Skip to content

Commit 69c5f15

Browse files
authored
Used UTF-8 string literals in Utf8HelperTests class (#8951)
1 parent 962fff9 commit 69c5f15

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

src/HotChocolate/Language/test/Language.Tests/Parser/Utf8HelperTests.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public void Unescape_LongStringNoEscapes_BulkCopy()
158158
public void Unescape_LongStringWithEscapeAtStart()
159159
{
160160
// arrange - escape at position 0, then 60+ bytes
161-
var inputData = Encoding.UTF8.GetBytes("\\nABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
161+
var inputData = "\\nABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"u8.ToArray();
162162
var outputBuffer = new byte[inputData.Length];
163163

164164
var input = new ReadOnlySpan<byte>(inputData);
@@ -176,7 +176,7 @@ public void Unescape_LongStringWithEscapeAtStart()
176176
public void Unescape_LongStringWithEscapeInMiddle()
177177
{
178178
// arrange - 32 bytes, then escape, then more bytes (exercises SIMD + escape + SIMD)
179-
var inputData = Encoding.UTF8.GetBytes("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef\\nghijklmnopqrstuvwxyz0123456789_-");
179+
var inputData = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef\\nghijklmnopqrstuvwxyz0123456789_-"u8.ToArray();
180180
var outputBuffer = new byte[inputData.Length];
181181

182182
var input = new ReadOnlySpan<byte>(inputData);
@@ -194,7 +194,7 @@ public void Unescape_LongStringWithEscapeInMiddle()
194194
public void Unescape_LongStringWithEscapeAtEnd()
195195
{
196196
// arrange - 60+ bytes then escape at end (exercises SIMD + scalar tail)
197-
var inputData = Encoding.UTF8.GetBytes("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\\n");
197+
var inputData = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\\n"u8.ToArray();
198198
var outputBuffer = new byte[inputData.Length];
199199

200200
var input = new ReadOnlySpan<byte>(inputData);
@@ -212,7 +212,7 @@ public void Unescape_LongStringWithEscapeAtEnd()
212212
public void Unescape_MultipleEscapesInLongString()
213213
{
214214
// arrange - multiple escapes spread across SIMD boundaries
215-
var inputData = Encoding.UTF8.GetBytes("ABCDEFGHIJ\\nKLMNOPQRSTUVWXYZ\\tabcdefghij\\rklmnopqrstuvwxyz");
215+
var inputData = "ABCDEFGHIJ\\nKLMNOPQRSTUVWXYZ\\tabcdefghij\\rklmnopqrstuvwxyz"u8.ToArray();
216216
var outputBuffer = new byte[inputData.Length];
217217

218218
var input = new ReadOnlySpan<byte>(inputData);
@@ -230,7 +230,7 @@ public void Unescape_MultipleEscapesInLongString()
230230
public void Unescape_SurrogatePair_Emoji()
231231
{
232232
// arrange - surrogate pair for 😀 (U+1F600) = \uD83D\uDE00
233-
var inputData = Encoding.UTF8.GetBytes("hello\\uD83D\\uDE00world");
233+
var inputData = "hello\\uD83D\\uDE00world"u8.ToArray();
234234
var outputBuffer = new byte[inputData.Length];
235235

236236
var input = new ReadOnlySpan<byte>(inputData);
@@ -247,7 +247,7 @@ public void Unescape_SurrogatePair_Emoji()
247247
public void Unescape_ConsecutiveEscapes()
248248
{
249249
// arrange - multiple escapes in a row
250-
var inputData = Encoding.UTF8.GetBytes("\\n\\r\\t\\b");
250+
var inputData = "\\n\\r\\t\\b"u8.ToArray();
251251
var outputBuffer = new byte[inputData.Length];
252252

253253
var input = new ReadOnlySpan<byte>(inputData);
@@ -300,7 +300,7 @@ public void Unescape_Exactly16Bytes_NoEscape()
300300
public void Unescape_ForwardSlash()
301301
{
302302
// arrange - forward slash escape
303-
var inputData = Encoding.UTF8.GetBytes("path\\/to\\/file");
303+
var inputData = "path\\/to\\/file"u8.ToArray();
304304
var outputBuffer = new byte[inputData.Length];
305305

306306
var input = new ReadOnlySpan<byte>(inputData);
@@ -317,7 +317,7 @@ public void Unescape_ForwardSlash()
317317
public void Unescape_BackslashEscape()
318318
{
319319
// arrange - escaped backslash
320-
var inputData = Encoding.UTF8.GetBytes("path\\\\to\\\\file");
320+
var inputData = "path\\\\to\\\\file"u8.ToArray();
321321
var outputBuffer = new byte[inputData.Length];
322322

323323
var input = new ReadOnlySpan<byte>(inputData);
@@ -334,7 +334,7 @@ public void Unescape_BackslashEscape()
334334
public void Unescape_SmallStringWithEscape_ScalarPath()
335335
{
336336
// arrange - 10 bytes total, too small for SIMD, goes to scalar
337-
var inputData = Encoding.UTF8.GetBytes("abc\\ndef");
337+
var inputData = "abc\\ndef"u8.ToArray();
338338
var outputBuffer = new byte[inputData.Length];
339339

340340
var input = new ReadOnlySpan<byte>(inputData);
@@ -405,7 +405,7 @@ public void Unescape_15Bytes_JustUnderVector128()
405405
public void Unescape_EscapeAtPosition31()
406406
{
407407
// arrange - escape right at Vector256 boundary
408-
var inputData = Encoding.UTF8.GetBytes("0123456789012345678901234567890\\n");
408+
var inputData = "0123456789012345678901234567890\\n"u8.ToArray();
409409
Assert.Equal(33, inputData.Length); // 31 chars + \n (2 bytes)
410410
var outputBuffer = new byte[inputData.Length];
411411

@@ -424,7 +424,7 @@ public void Unescape_EscapeAtPosition31()
424424
public void Unescape_InvalidEscapeChar_ThrowsException()
425425
{
426426
// arrange - invalid escape sequence \q
427-
var inputData = Encoding.UTF8.GetBytes("hello\\qworld");
427+
var inputData = "hello\\qworld"u8.ToArray();
428428
var outputBuffer = new byte[inputData.Length];
429429

430430
var input = new ReadOnlySpan<byte>(inputData);
@@ -442,7 +442,7 @@ public void Unescape_InvalidEscapeChar_ThrowsException()
442442
public void Unescape_TruncatedUnicodeEscape_ThrowsException()
443443
{
444444
// arrange - truncated unicode \u00
445-
var inputData = Encoding.UTF8.GetBytes("hello\\u00");
445+
var inputData = "hello\\u00"u8.ToArray();
446446
var outputBuffer = new byte[inputData.Length];
447447

448448
// act & assert
@@ -457,7 +457,7 @@ public void Unescape_TruncatedUnicodeEscape_ThrowsException()
457457
public void Unescape_UnexpectedHighSurrogate_ThrowsException()
458458
{
459459
// arrange - two high surrogates in a row
460-
var inputData = Encoding.UTF8.GetBytes("\\uD83D\\uD83D");
460+
var inputData = "\\uD83D\\uD83D"u8.ToArray();
461461
var outputBuffer = new byte[inputData.Length];
462462

463463
// act & assert
@@ -472,7 +472,7 @@ public void Unescape_UnexpectedHighSurrogate_ThrowsException()
472472
public void Unescape_UnexpectedLowSurrogate_ThrowsException()
473473
{
474474
// arrange - low surrogate without high surrogate
475-
var inputData = Encoding.UTF8.GetBytes("\\uDE00");
475+
var inputData = "\\uDE00"u8.ToArray();
476476
var outputBuffer = new byte[inputData.Length];
477477

478478
// act & assert
@@ -487,7 +487,7 @@ public void Unescape_UnexpectedLowSurrogate_ThrowsException()
487487
public void Unescape_HighSurrogateNotFollowedByLowSurrogate_ThrowsException()
488488
{
489489
// arrange - high surrogate followed by regular char
490-
var inputData = Encoding.UTF8.GetBytes("\\uD83D\\u0041");
490+
var inputData = "\\uD83D\\u0041"u8.ToArray();
491491
var outputBuffer = new byte[inputData.Length];
492492

493493
// act & assert
@@ -502,7 +502,7 @@ public void Unescape_HighSurrogateNotFollowedByLowSurrogate_ThrowsException()
502502
public void Unescape_TrailingBackslash_ThrowsException()
503503
{
504504
// arrange - string ending with backslash
505-
var inputData = Encoding.UTF8.GetBytes("hello\\");
505+
var inputData = "hello\\"u8.ToArray();
506506
var outputBuffer = new byte[inputData.Length];
507507

508508
// act & assert
@@ -517,7 +517,7 @@ public void Unescape_TrailingBackslash_ThrowsException()
517517
public void Unescape_OnlyBackslashN()
518518
{
519519
// arrange - just an escape, nothing else
520-
var inputData = Encoding.UTF8.GetBytes("\\n");
520+
var inputData = "\\n"u8.ToArray();
521521
var outputBuffer = new byte[inputData.Length];
522522

523523
var input = new ReadOnlySpan<byte>(inputData);
@@ -534,7 +534,7 @@ public void Unescape_OnlyBackslashN()
534534
public void Unescape_64BytesWithEscapeAtByte32()
535535
{
536536
// arrange - escape exactly at byte 32 (SIMD boundary)
537-
var inputData = Encoding.UTF8.GetBytes("ABCDEFGHIJKLMNOPQRSTUVWXYZ012345\\n67890abcdefghijklmnopqrstuvwxyz");
537+
var inputData = "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345\\n67890abcdefghijklmnopqrstuvwxyz"u8.ToArray();
538538
var outputBuffer = new byte[inputData.Length];
539539

540540
var input = new ReadOnlySpan<byte>(inputData);
@@ -552,7 +552,7 @@ public void Unescape_64BytesWithEscapeAtByte32()
552552
public void Unescape_UnicodeInLongString()
553553
{
554554
// arrange - unicode escape in a long string (exercises SIMD + unicode handling)
555-
var inputData = Encoding.UTF8.GetBytes("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghij\\u20ACklmnopqrstuvwxyz0123456789");
555+
var inputData = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghij\\u20ACklmnopqrstuvwxyz0123456789"u8.ToArray();
556556
var outputBuffer = new byte[inputData.Length];
557557

558558
var input = new ReadOnlySpan<byte>(inputData);

0 commit comments

Comments
 (0)