From d13e2baaf9f108259106974622027e1eb1199226 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 13 Jun 2024 10:32:30 +1000 Subject: [PATCH] use utf8 strings --- .../ChunkStreamReadTests.cs | 4 +- .../CommonOperationsTests.cs | 40 +++++++++--------- .../LookaroundTests.cs | 2 +- .../TokenTrieTests.cs | 42 +++++++++---------- 4 files changed, 44 insertions(+), 44 deletions(-) diff --git a/test/Microsoft.TemplateEngine.Core.UnitTests/ChunkStreamReadTests.cs b/test/Microsoft.TemplateEngine.Core.UnitTests/ChunkStreamReadTests.cs index a6822a665ce..3466b972137 100644 --- a/test/Microsoft.TemplateEngine.Core.UnitTests/ChunkStreamReadTests.cs +++ b/test/Microsoft.TemplateEngine.Core.UnitTests/ChunkStreamReadTests.cs @@ -130,11 +130,11 @@ public void VerifyConsumeWholeLine() return 0; }, true, - Encoding.UTF8.GetBytes("There")); + "There"u8.ToArray()); EngineConfig cfg = new EngineConfig(_engineEnvironmentSettings.Host.Logger, new VariableCollection()); IProcessor processor = Processor.Create(cfg, o.Provider); - byte[] data = Encoding.UTF8.GetBytes("Hello \r\n There \r\n You"); + byte[] data = "Hello \r\n There \r\n You"u8.ToArray(); Stream input = new ChunkMemoryStream(data, 1); Stream output = new ChunkMemoryStream(1); bool changed = processor.Run(input, output, 5); diff --git a/test/Microsoft.TemplateEngine.Core.UnitTests/CommonOperationsTests.cs b/test/Microsoft.TemplateEngine.Core.UnitTests/CommonOperationsTests.cs index 128cb0e8266..db442812437 100644 --- a/test/Microsoft.TemplateEngine.Core.UnitTests/CommonOperationsTests.cs +++ b/test/Microsoft.TemplateEngine.Core.UnitTests/CommonOperationsTests.cs @@ -31,11 +31,11 @@ public void VerifyTrimWhitespaceForward() return 0; }, true, - Encoding.UTF8.GetBytes("Hello")); + "Hello"u8.ToArray()); EngineConfig cfg = new EngineConfig(_logger, new VariableCollection()); IProcessor processor = Processor.Create(cfg, o.Provider); - byte[] data = Encoding.UTF8.GetBytes("Hello \r\n There"); + byte[] data = "Hello \r\n There"u8.ToArray(); Stream d = new MemoryStream(data); MemoryStream result = new MemoryStream(); bool modified = processor.Run(d, result); @@ -56,11 +56,11 @@ public void VerifyTrimWhitespaceBackward() return 0; }, true, - Encoding.UTF8.GetBytes("There")); + "There"u8.ToArray()); EngineConfig cfg = new EngineConfig(_logger, new VariableCollection()); IProcessor processor = Processor.Create(cfg, o.Provider); - byte[] data = Encoding.UTF8.GetBytes("Hello \r\n There"); + byte[] data = "Hello \r\n There"u8.ToArray(); Stream d = new MemoryStream(data); MemoryStream result = new MemoryStream(); bool modified = processor.Run(d, result); @@ -81,11 +81,11 @@ public void VerifyTrimWhitespaceBothDirections() return 0; }, true, - Encoding.UTF8.GetBytes("There")); + "There"u8.ToArray()); EngineConfig cfg = new EngineConfig(_logger, new VariableCollection()); IProcessor processor = Processor.Create(cfg, o.Provider); - byte[] data = Encoding.UTF8.GetBytes("Hello \r\n There \r\n You"); + byte[] data = "Hello \r\n There \r\n You"u8.ToArray(); Stream d = new MemoryStream(data); MemoryStream result = new MemoryStream(); bool modified = processor.Run(d, result); @@ -106,11 +106,11 @@ public void VerifyTrimWhitespaceNeitherDirection() return 0; }, true, - Encoding.UTF8.GetBytes("There")); + "There"u8.ToArray()); EngineConfig cfg = new EngineConfig(_logger, new VariableCollection()); IProcessor processor = Processor.Create(cfg, o.Provider); - byte[] data = Encoding.UTF8.GetBytes("Hello \r\n There \r\n You"); + byte[] data = "Hello \r\n There \r\n You"u8.ToArray(); Stream d = new MemoryStream(data); MemoryStream result = new MemoryStream(); bool modified = processor.Run(d, result); @@ -131,11 +131,11 @@ public void VerifyConsumeWholeLine() return 0; }, true, - Encoding.UTF8.GetBytes("There")); + "There"u8.ToArray()); EngineConfig cfg = new EngineConfig(_logger, new VariableCollection()); IProcessor processor = Processor.Create(cfg, o.Provider); - byte[] data = Encoding.UTF8.GetBytes("Hello \r\n There \r\n You"); + byte[] data = "Hello \r\n There \r\n You"u8.ToArray(); Stream d = new MemoryStream(data); MemoryStream result = new MemoryStream(); bool modified = processor.Run(d, result); @@ -164,11 +164,11 @@ public void VerifyWhitespaceHandlerConsumeWholeLine(bool trim, bool trimForward, return 0; }, true, - Encoding.UTF8.GetBytes("There")); + "There"u8.ToArray()); EngineConfig cfg = new EngineConfig(_logger, new VariableCollection()); IProcessor processor = Processor.Create(cfg, o.Provider); - byte[] data = Encoding.UTF8.GetBytes("Hello \r\n There \r\n You"); + byte[] data = "Hello \r\n There \r\n You"u8.ToArray(); Stream d = new MemoryStream(data); MemoryStream result = new MemoryStream(); bool modified = processor.Run(d, result); @@ -193,11 +193,11 @@ public void VerifyWhitespaceHandlerTrim(bool trimForward, bool trimBackward) return 0; }, true, - Encoding.UTF8.GetBytes("There")); + "There"u8.ToArray()); EngineConfig cfg = new EngineConfig(_logger, new VariableCollection()); IProcessor processor = Processor.Create(cfg, o.Provider); - byte[] data = Encoding.UTF8.GetBytes("Hello \r\n There \r\n You"); + byte[] data = "Hello \r\n There \r\n You"u8.ToArray(); Stream d = new MemoryStream(data); MemoryStream result = new MemoryStream(); bool modified = processor.Run(d, result); @@ -219,11 +219,11 @@ public void VerifyWhitespaceHandlerTrimForwardButNotBack() return 0; }, true, - Encoding.UTF8.GetBytes("There")); + "There"u8.ToArray()); EngineConfig cfg = new EngineConfig(_logger, new VariableCollection()); IProcessor processor = Processor.Create(cfg, o.Provider); - byte[] data = Encoding.UTF8.GetBytes("Hello \r\n There \r\n You"); + byte[] data = "Hello \r\n There \r\n You"u8.ToArray(); Stream d = new MemoryStream(data); MemoryStream result = new MemoryStream(); bool modified = processor.Run(d, result); @@ -244,11 +244,11 @@ public void VerifyWhitespaceHandlerTrimBackButNotForward() return 0; }, true, - Encoding.UTF8.GetBytes("There")); + "There"u8.ToArray()); EngineConfig cfg = new EngineConfig(_logger, new VariableCollection()); IProcessor processor = Processor.Create(cfg, o.Provider); - byte[] data = Encoding.UTF8.GetBytes("Hello \r\n There \r\n You"); + byte[] data = "Hello \r\n There \r\n You"u8.ToArray(); Stream d = new MemoryStream(data); MemoryStream result = new MemoryStream(); bool modified = processor.Run(d, result); @@ -269,11 +269,11 @@ public void VerifyWhitespaceHandlerTrimBackAndForward() return 0; }, true, - Encoding.UTF8.GetBytes("There")); + "There"u8.ToArray()); EngineConfig cfg = new EngineConfig(_logger, new VariableCollection()); IProcessor processor = Processor.Create(cfg, o.Provider); - byte[] data = Encoding.UTF8.GetBytes("Hello \r\n There \r\n You"); + byte[] data = "Hello \r\n There \r\n You"u8.ToArray(); Stream d = new MemoryStream(data); MemoryStream result = new MemoryStream(); bool modified = processor.Run(d, result); diff --git a/test/Microsoft.TemplateEngine.Core.UnitTests/LookaroundTests.cs b/test/Microsoft.TemplateEngine.Core.UnitTests/LookaroundTests.cs index 4abbe2eca94..cd7c9a9962f 100644 --- a/test/Microsoft.TemplateEngine.Core.UnitTests/LookaroundTests.cs +++ b/test/Microsoft.TemplateEngine.Core.UnitTests/LookaroundTests.cs @@ -187,7 +187,7 @@ public void TestReadAheadBreaksLookBehinds() IOperationProvider[] operations = { - new MockOperationProvider(new MockOperation(null, ReadaheadOneByte, true, Encoding.UTF8.GetBytes("foo"))), + new MockOperationProvider(new MockOperation(null, ReadaheadOneByte, true, "foo"u8.ToArray())), new Replacement("bar".TokenConfigBuilder().OnlyIfAfter("foot"), "b", null, true) }; EngineConfig cfg = new EngineConfig(_engineEnvironmentSettings.Host.Logger, VariableCollection.Root()); diff --git a/test/Microsoft.TemplateEngine.Core.UnitTests/TokenTrieTests.cs b/test/Microsoft.TemplateEngine.Core.UnitTests/TokenTrieTests.cs index 4eabb416f40..ec2f09ac7ce 100644 --- a/test/Microsoft.TemplateEngine.Core.UnitTests/TokenTrieTests.cs +++ b/test/Microsoft.TemplateEngine.Core.UnitTests/TokenTrieTests.cs @@ -42,21 +42,21 @@ public void VerifyTokenTrieLookArounds(string original, int checkPosition, int e [Fact(DisplayName = nameof(VerifyTokenTrieAtBegin))] public void VerifyTokenTrieAtBegin() { - byte[] hello = Encoding.UTF8.GetBytes("hello"); - byte[] helloBang = Encoding.UTF8.GetBytes("hello!"); - byte[] hi = Encoding.UTF8.GetBytes("hi"); + byte[] hello = "hello"u8.ToArray(); + byte[] helloBang = "hello!"u8.ToArray(); + byte[] hi = "hi"u8.ToArray(); TokenTrie t = new TokenTrie(); t.AddToken(hello); t.AddToken(helloBang); t.AddToken(hi); - byte[] source1 = Encoding.UTF8.GetBytes("hello there"); - byte[] source2 = Encoding.UTF8.GetBytes("hello1 there"); - byte[] source3 = Encoding.UTF8.GetBytes("hello! there"); - byte[] source4 = Encoding.UTF8.GetBytes("hi there"); - byte[] source5 = Encoding.UTF8.GetBytes("hi"); - byte[] source6 = Encoding.UTF8.GetBytes("he"); + byte[] source1 = "hello there"u8.ToArray(); + byte[] source2 = "hello1 there"u8.ToArray(); + byte[] source3 = "hello! there"u8.ToArray(); + byte[] source4 = "hi there"u8.ToArray(); + byte[] source5 = "hi"u8.ToArray(); + byte[] source6 = "he"u8.ToArray(); int pos = 0; Assert.True(t.GetOperation(source1, source1.Length, ref pos, out int token)); @@ -86,15 +86,15 @@ public void VerifyTokenTrieAtBegin() [Fact(DisplayName = nameof(VerifyTokenTrieNotEnoughBufferLeft))] public void VerifyTokenTrieNotEnoughBufferLeft() { - byte[] hello = Encoding.UTF8.GetBytes("hello"); - byte[] helloBang = Encoding.UTF8.GetBytes("hello!"); + byte[] hello = "hello"u8.ToArray(); + byte[] helloBang = "hello!"u8.ToArray(); TokenTrie t = new TokenTrie(); t.AddToken(hello); t.AddToken(helloBang); - byte[] source1 = Encoding.UTF8.GetBytes("hi"); - byte[] source2 = Encoding.UTF8.GetBytes(" hello"); + byte[] source1 = "hi"u8.ToArray(); + byte[] source2 = " hello"u8.ToArray(); int pos = 0; Assert.False(t.GetOperation(source1, source1.Length, ref pos, out int token)); @@ -112,10 +112,10 @@ public void VerifyTokenTrieNotEnoughBufferLeft() [Fact(DisplayName = nameof(VerifyTokenTrieCombine))] public void VerifyTokenTrieCombine() { - byte[] hello = Encoding.UTF8.GetBytes("hello"); - byte[] helloBang = Encoding.UTF8.GetBytes("hello!"); - byte[] hi = Encoding.UTF8.GetBytes("hi"); - byte[] there = Encoding.UTF8.GetBytes("there!"); + byte[] hello = "hello"u8.ToArray(); + byte[] helloBang = "hello!"u8.ToArray(); + byte[] hi = "hi"u8.ToArray(); + byte[] there = "there!"u8.ToArray(); TokenTrie t = new TokenTrie(); t.AddToken(hello); @@ -129,10 +129,10 @@ public void VerifyTokenTrieCombine() combined.Append(t); combined.Append(t2); - byte[] source1 = Encoding.UTF8.GetBytes("hello there"); - byte[] source2 = Encoding.UTF8.GetBytes("hello! there"); - byte[] source3 = Encoding.UTF8.GetBytes("hi there"); - byte[] source4 = Encoding.UTF8.GetBytes("there!"); + byte[] source1 = "hello there"u8.ToArray(); + byte[] source2 = "hello! there"u8.ToArray(); + byte[] source3 = "hi there"u8.ToArray(); + byte[] source4 = "there!"u8.ToArray(); int pos = 0; Assert.True(t.GetOperation(source1, source1.Length, ref pos, out int token));