Skip to content

Commit c8c5b1c

Browse files
committed
add unit tests for parsing ANSI with non-ASCII
also update CI build to address latest dependabot PR
1 parent 6b97933 commit c8c5b1c

7 files changed

Lines changed: 130 additions & 57 deletions

File tree

.github/workflows/CI_build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ jobs:
3232

3333
- name: Archive artifacts for x64
3434
if: matrix.build_platform == 'x64' && matrix.build_configuration == 'Release'
35-
uses: actions/upload-artifact@v5
35+
uses: actions/upload-artifact@v7
3636
with:
3737
name: plugin_dll_x64
3838
path: JsonToolsNppPlugin\bin\${{ matrix.build_configuration }}-x64\JsonTools.dll
3939

4040
- name: Archive artifacts for x86
4141
if: matrix.build_platform == 'x86' && matrix.build_configuration == 'Release'
42-
uses: actions/upload-artifact@v5
42+
uses: actions/upload-artifact@v7
4343
with:
4444
name: plugin_dll_x86
4545
path: JsonToolsNppPlugin\bin\${{ matrix.build_configuration }}\JsonTools.dll

JsonToolsNppPlugin/PluginInfrastructure/Msgs_h.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,4 +873,33 @@ public enum StatusBarSection
873873
UnicodeType,
874874
TypingMode,
875875
}
876+
877+
/// <summary>
878+
/// based on the UniMode enum in NppConstants.h
879+
/// </summary>
880+
public enum BufferEncoding
881+
{
882+
/// <summary>
883+
/// returned when something was wrong in Notepad++
884+
/// </summary>
885+
invalid = -1,
886+
/// <summary>ANSI</summary>
887+
uni8Bit = 0,
888+
/// <summary>UTF-8 with BOM</summary>
889+
uniUTF8 = 1,
890+
/// <summary>UTF-16 Big Endian with BOM</summary>
891+
uni16BE = 2,
892+
/// <summary>UTF-16 Little Endian with BOM</summary>
893+
uni16LE = 3,
894+
/// <summary>UTF-8 without BOM</summary>
895+
uniUTF8_NoBOM = 4,
896+
/// <summary>0 - 127 ASCII</summary>
897+
uni7Bit = 5,
898+
/// <summary>UTF-16 Big Endian without BOM</summary>
899+
uni16BE_NoBOM = 6,
900+
/// <summary>UTF-16 Little Endian without BOM</summary>
901+
uni16LE_NoBOM = 7,
902+
/// <summary>indicates the maximum BufferEncoding value, has no real meaning</summary>
903+
uniEnd = 8
904+
};
876905
}

JsonToolsNppPlugin/PluginInfrastructure/NotepadPPGateway.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ public interface INotepadPPGateway
5757
/// <returns></returns>
5858
bool AllocateIndicators(int numberOfIndicators, out int[] indicators);
5959

60+
BufferEncoding GetBufferEncoding(IntPtr bufferID);
61+
62+
void SetBufferEncoding(IntPtr bufferID, BufferEncoding bufferEncoding);
63+
64+
IntPtr GetCurrentBufferID();
65+
6066
}
6167

6268
/// <summary>
@@ -305,6 +311,26 @@ public unsafe bool AllocateIndicators(int numberOfIndicators, out int[] indicato
305311
return success != IntPtr.Zero;
306312
}
307313
}
314+
315+
public BufferEncoding GetBufferEncoding(IntPtr bufferID)
316+
{
317+
long result = (long)Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_GETBUFFERENCODING, bufferID, 0);
318+
if (result >= (long)BufferEncoding.uniEnd || result < 0)
319+
return BufferEncoding.invalid;
320+
return (BufferEncoding)result;
321+
}
322+
323+
public void SetBufferEncoding(IntPtr bufferID, BufferEncoding encoding)
324+
{
325+
if (encoding <= BufferEncoding.invalid || encoding >= BufferEncoding.uniEnd)
326+
return;
327+
Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_SETBUFFERENCODING, bufferID, (int)encoding);
328+
}
329+
330+
public IntPtr GetCurrentBufferID()
331+
{
332+
return Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_GETCURRENTBUFFERID, 0, 0);
333+
}
308334
}
309335

310336
/// <summary>

JsonToolsNppPlugin/PluginInfrastructure/ScintillaGateway.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ public int GetNextTabStop(int line, int x)
467467
/// The SC_CP_UTF8 value can be used to enter Unicode mode.
468468
/// (Scintilla feature 2037)
469469
/// </summary>
470+
/// <remarks>WARNING: this method should probably <em>not</em> be used to set a document's encoding. Use <see cref="NotepadPPGateway.SetBufferEncoding(IntPtr, BufferEncoding)"/> instead.</remarks>
470471
public void SetCodePage(int codePage)
471472
{
472473
Win32.SendMessage(scintilla, SciMsg.SCI_SETCODEPAGE, (IntPtr) codePage, (IntPtr) Unused);

JsonToolsNppPlugin/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@
2828
// Build Number
2929
// Revision
3030
//
31-
[assembly: AssemblyVersion("8.4.0.7")]
32-
[assembly: AssemblyFileVersion("8.4.0.7")]
31+
[assembly: AssemblyVersion("8.4.0.8")]
32+
[assembly: AssemblyFileVersion("8.4.0.8")]

JsonToolsNppPlugin/Tests/UserInterfaceTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using JSON_Tools.JSON_Tools;
88
using JSON_Tools.Utils;
99
using Kbg.NppPluginNET;
10+
using Kbg.NppPluginNET.PluginInfrastructure;
1011

1112
namespace JSON_Tools.Tests
1213
{
@@ -366,6 +367,13 @@ public static bool ExecuteFileManipulation(string command, List<string> messages
366367
}
367368
messages.Add($"Set document type to {newDocumentTypeName} with the treeview's combo box");
368369
break;
370+
case "set_buffer_encoding":
371+
BufferEncoding newEncoding = (BufferEncoding)args[0];
372+
if (newEncoding >= BufferEncoding.uniEnd || newEncoding < 0)
373+
newEncoding = BufferEncoding.invalid;
374+
IntPtr curBuffID = Npp.notepad.GetCurrentBufferID();
375+
Npp.notepad.SetBufferEncoding(curBuffID, newEncoding);
376+
break;
369377
default:
370378
throw new ArgumentException($"Unrecognized command {command}");
371379
}
@@ -880,6 +888,14 @@ public static bool Test()
880888
("compare_text", new object[]{"[2,\"bar\",false]\n[1,\"foo\",true]"}),
881889
("sort_form_run", new object[]{"[0]", false, true, 3, "s_len(str(@))"}),
882890
("compare_text", new object[]{"[false,\"bar\",2]\n[1,\"foo\",true]"}),
891+
// TEST PARSE ANSI DOCUMENTS WITH NON-ASCII CHARACTERS
892+
("file_open", new object[]{3, "json"}),
893+
("set_buffer_encoding", new object[]{BufferEncoding.uni8Bit}),
894+
("overwrite", new object[]{"[\r\n [\"µ ØÅ\", 1, \"a\"], // foo\r\n [\"ü\", 2, \"b\"], // bÆr\r\n [\"ß\", 3, \"c\"], // baz\r\n]//a"}),
895+
("pretty_print", new object[]{true, true, PrettyPrintStyle.Google}),
896+
("compare_text", new object[]{"[\r\n\t[\r\n\t\t\"µ ØÅ\",\r\n\t\t1,\r\n\t\t\"a\"\r\n\t],\r\n\t// foo\r\n\t[\r\n\t\t\"ü\",\r\n\t\t2,\r\n\t\t\"b\"\r\n\t],\r\n\t// bÆr\r\n\t[\r\n\t\t\"ß\",\r\n\t\t3,\r\n\t\t\"c\"\r\n\t]\r\n]\r\n// baz\r\n//a\r\n"}),
897+
("pretty_print", new object[]{true}),
898+
("compare_text", new object[]{"[\r\n\t[\"µ ØÅ\", 1, \"a\"],\r\n\t[\"ü\", 2, \"b\"],\r\n\t[\"ß\", 3, \"c\"]\r\n]"}),
883899
};
884900

885901
var messages = new List<string>();
@@ -927,6 +943,7 @@ public static bool Test()
927943
string[] oneArray2000xPPrintSelections = ((JArray)remesParser.Search("(range(2000) * 13)[:]{@, @ + 11}{s_join(`,`, str(@))}[0]", new JNode())).children
928944
.Select(x => (string)x.value)
929945
.ToArray();
946+
testcases.Add(("file_open", new object[] { 2 }));
930947
testcases.Add(("overwrite", new object[] { oneArray2000xStr }));
931948
testcases.Add(("select_every_valid", new object[] { }));
932949
testcases.Add(("compare_selections", new object[] { oneArray2000xSelections }));

0 commit comments

Comments
 (0)