Skip to content

Commit

Permalink
refactor tests with 4-digit UnicodeChars (RocketChar)
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp-Binder committed Oct 20, 2024
1 parent 9a2e5b6 commit b6dd9da
Showing 1 changed file with 18 additions and 28 deletions.
46 changes: 18 additions & 28 deletions test/DotNetEnv.Tests/ParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,6 @@ namespace DotNetEnv.Tests
{
public class ParserTests : IDisposable
{
// C# wow that you can't handle 32 bit unicode as chars. wow. strings for 4 byte chars.
private struct Utf32Integers
{
// https://stackoverflow.com/questions/602912/how-do-you-echo-a-4-digit-unicode-character-in-bash
// printf '\xE2\x98\xA0'
// printf ☠ | hexdump # hexdump has bytes flipped per word (2 bytes, 4 hex)

internal static string AsUnicodeString(int value) => char.ConvertFromUtf32(value);

internal const int RocketChar = 0x1F680; // 🚀
}

private const string EXCEPT_CHARS = "'\"$";

private const string EV_TEST = "ENVVAR_TEST";
Expand Down Expand Up @@ -100,25 +88,21 @@ public void HexByteShouldParseUntilEnd(byte expected, string input) =>
[InlineData("☠", @"\xE2\x98\xA0")]
[InlineData("日", @"\xe6\x97\xa5")]
[InlineData("本", @"\xe6\x9c\xac")]
[InlineData(UnicodeChars.RocketChar, @"\xF0\x9F\x9A\x80")]
public void Utf8CharShouldParseUntilEnd(string expected, string input) =>
Assert.Equal(expected, Parsers.Utf8Char.AtEnd().Parse(input));

[Theory]
[InlineData(Utf32Integers.RocketChar, @"\xF0\x9F\x9A\x80")]
public void Utf8CharShouldParse4DigitCharsUntilEnd(int expected, string input) =>
Assert.Equal(Utf32Integers.AsUnicodeString(expected), Parsers.Utf8Char.AtEnd().Parse(input));

[Theory]
[InlineData("®", @"\u00ae")]
[InlineData("®", @"\uae")]
public void Utf16CharShouldParseUntilEnd(string expected, string input) =>
Assert.Equal(expected, Parsers.Utf16Char.AtEnd().Parse(input));

[Theory]
[InlineData(Utf32Integers.RocketChar, @"\U0001F680")]
[InlineData(Utf32Integers.RocketChar, @"\U1F680")]
public void Utf32CharShouldParse4DigitUntilEnd(int expected, string input) =>
Assert.Equal(Utf32Integers.AsUnicodeString(expected), Parsers.Utf32Char.AtEnd().Parse(input));
[InlineData(UnicodeChars.RocketChar, @"\U0001F680")]
[InlineData(UnicodeChars.RocketChar, @"\U1F680")]
public void Utf32CharShouldParse4DigitUntilEnd(string expected, string input) =>
Assert.Equal(expected, Parsers.Utf32Char.AtEnd().Parse(input));

[Theory]
[InlineData("\b", "\\b")]
Expand Down Expand Up @@ -182,16 +166,12 @@ public void NotControlNorWhitespaceShouldThrowOnParseUntilEnd(string invalidInpu
[InlineData("\\m", "\\m")]
[InlineData("'", "\\'")]
[InlineData("\"", "\\\"")]
[InlineData(UnicodeChars.RocketChar, @"\xF0\x9F\x9A\x80")]
[InlineData(UnicodeChars.RocketChar, @"\U0001F680")]
[InlineData(UnicodeChars.RocketChar, @"\U1F680")]
public void SpecialCharShouldParseUntilEnd(string expected, string input) =>
Assert.Equal(expected, Parsers.SpecialChar.AtEnd().Parse(input));

[Theory]
[InlineData(Utf32Integers.RocketChar, @"\xF0\x9F\x9A\x80")]
[InlineData(Utf32Integers.RocketChar, @"\U0001F680")]
[InlineData(Utf32Integers.RocketChar, @"\U1F680")]
public void SpecialCharShouldParse4DigitUntilEnd(int expected, string input) =>
Assert.Equal(Utf32Integers.AsUnicodeString(expected), Parsers.SpecialChar.AtEnd().Parse(input));

[Theory]
[InlineData("a")]
[InlineData("%")]
Expand Down Expand Up @@ -532,5 +512,15 @@ public void ParseDotenvFile ()
};
testParse(expecteds, contents);
}

// C# wow that you can't handle 32 bit unicode as chars. wow. strings for 4 byte chars.
private struct UnicodeChars
{
// https://stackoverflow.com/questions/602912/how-do-you-echo-a-4-digit-unicode-character-in-bash
// printf '\xE2\x98\xA0'
// printf ☠ | hexdump # hexdump has bytes flipped per word (2 bytes, 4 hex)

public const string RocketChar = "\ud83d\ude80"; // 🚀
}
}
}

0 comments on commit b6dd9da

Please sign in to comment.