Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public static bool IsValidGraphQLName(this in ReadOnlySpan<byte> name)

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool IsLetterOrDigitOrUnderscore(this char c)
=> IsLetterOrDigitOrUnderscore((byte)c);
=> c is >= 'a' and <= 'z' or >= 'A' and <= 'Z' or >= '0' and <= '9' or '_';

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool IsLetterOrDigitOrUnderscore(this byte c)
Expand Down Expand Up @@ -188,5 +188,5 @@ private static bool IsLetterOrUnderscore(this byte c)

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool IsLetterOrUnderscore(this char c)
=> IsLetterOrUnderscore((byte)c);
=> c is >= 'a' and <= 'z' or >= 'A' and <= 'Z' or '_';
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ public class NameUtilsTests
[InlineData("1_Bar")]
[InlineData("B/ar")]
[InlineData("B+ar")]
[InlineData("Łar")]
[InlineData("Bŗar")]
[InlineData("Bİar")]
public void InvalidName(string name)
{
var message = Assert.Throws<ArgumentException>(() => name.EnsureGraphQLName()).Message;
Expand All @@ -33,4 +36,19 @@ public void ValidName(string name)
{
name.EnsureGraphQLName();
}

[Theory]
[InlineData("Łar", "_ar")]
[InlineData("Bŗar", "B_ar")]
[InlineData("Bİar", "B_ar")]
public void MakeValidGraphQLName_Should_ReplaceTheCharacter_When_ItIsNotAnAsciiNameCharacter(
string name,
string expected)
{
// act
var result = NameUtils.MakeValidGraphQLName(name);

// assert
Assert.Equal(expected, result);
}
}
Loading