Skip to content

Commit

Permalink
fix UI test failure on NPP 8.3.3 (handle nul end)
Browse files Browse the repository at this point in the history
the oldest NPP version the UI tests were tried on previously
    was 8.3.3.
The tests previously passed on NPP 8.4.2 but failed on 8.3.3,
    but now they all pass on 8.3.3 (not tested on anything
    between those two, nor on anything earlier than 8.3.3).

The test failures were due to issues with requesting
    only n bytes of a document with n + 1 bytes after factoring
    in the NUL terminator.
  • Loading branch information
molsonkiko committed Dec 28, 2023
1 parent 97fc94a commit 4073d4d
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 50 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed

1. Eliminated plugin crash when attempting to open the [regex search form](/docs/README.md#regex-search-form) after it had been closed.
2. Some UI test failures (and probably related weirdness in public API) on older NPP versions

## [6.0.0] - 2023-12-13

Expand Down
2 changes: 1 addition & 1 deletion JsonToolsNppPlugin/Forms/TreeViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ public static bool LengthOfStringInRegexMode(JNode[] nodes, char delim, char quo
int nodepos = jnode.position;
if (documentText is null)
documentText = selectionEnd < 0
? Npp.editor.GetText(Npp.editor.GetLength() + 1)
? Npp.editor.GetText()
: Npp.GetSlice(selectionStart, selectionEnd);
int utf8Extra = 0;
for (; startIndex < documentText.Length && startIndex + utf8Extra < nodepos; startIndex++)
Expand Down
4 changes: 2 additions & 2 deletions JsonToolsNppPlugin/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ public static void DumpSelectedTextAsJsonString()
var selections = SelectionManager.GetSelectedRanges();
if (SelectionManager.NoTextSelected(selections))
{
string text = Npp.editor.GetText(Npp.editor.GetLength());
string text = Npp.editor.GetText();
JNode textNode = new JNode(text);
PrettyPrintJsonInNewFile(textNode);
}
Expand Down Expand Up @@ -1020,7 +1020,7 @@ public static void DumpSelectedJsonStringsAsText()
public static string TryGetSelectedJsonStringValue(int start = -1, int end = -1)
{
string text = start < 0 || end < 0
? Npp.editor.GetText(Npp.editor.GetLength())
? Npp.editor.GetText()
: Npp.GetSlice(start, end);
try
{
Expand Down
4 changes: 2 additions & 2 deletions JsonToolsNppPlugin/PluginInfrastructure/IScintillaGateway.cs
Original file line number Diff line number Diff line change
Expand Up @@ -909,12 +909,12 @@ public interface IScintillaGateway
unsafe void SetText(string text);

/// <summary>
/// Retrieve all the text in the document.
/// Retrieve all the text in the document (or the first length chars of the document).
/// Returns number of characters retrieved.
/// Result is NUL-terminated.
/// (Scintilla feature 2182)
/// </summary>
unsafe string GetText(int length);
unsafe string GetText(int length = -1);

/// <summary>Retrieve the number of characters in the document. (Scintilla feature 2183)</summary>
int GetTextLength();
Expand Down
4 changes: 3 additions & 1 deletion JsonToolsNppPlugin/PluginInfrastructure/ScintillaGateway.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1764,8 +1764,10 @@ public unsafe void SetText(string text)
/// Result is NUL-terminated.
/// (Scintilla feature 2182)
/// </summary>
public unsafe string GetText(int length)
public unsafe string GetText(int length = -1)
{
if (length == -1)
length = GetLength() + 1;
byte[] textBuffer = new byte[length];
fixed (byte* textPtr = textBuffer)
{
Expand Down
4 changes: 2 additions & 2 deletions JsonToolsNppPlugin/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("6.0.0.9")]
[assembly: AssemblyFileVersion("6.0.0.9")]
[assembly: AssemblyVersion("6.0.0.10")]
[assembly: AssemblyFileVersion("6.0.0.10")]
2 changes: 1 addition & 1 deletion JsonToolsNppPlugin/Tests/UserInterfaceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static bool ExecuteFileManipulation(string command, List<string> messages
break;
case "compare_text":
var correctText = (string)args[0];
string gotText = Npp.editor.GetText(Npp.editor.GetLength());
string gotText = Npp.editor.GetText();
if (correctText != gotText)
{
messages.Add($"FAIL: expected text\r\n{correctText}\r\nGOT\r\n{gotText}");
Expand Down
82 changes: 41 additions & 41 deletions most recent errors.txt

Large diffs are not rendered by default.

0 comments on commit 4073d4d

Please sign in to comment.