Files
basic-computer-games/00_Common/dotnet/Games.Common.Test/IO/TokenizerTests.cs
2022-02-11 20:45:01 +11:00

34 lines
1.1 KiB
C#

using System.Linq;
using FluentAssertions;
using Xunit;
namespace Games.Common.IO
{
public class TokenizerTests
{
[Theory]
[MemberData(nameof(TokenizerTestCases))]
public void ParseTokens_SplitsStringIntoExpectedTokens(string input, string[] expected)
{
var result = Tokenizer.ParseTokens(input);
result.Select(t => t.ToString()).Should().BeEquivalentTo(expected);
}
public static TheoryData<string, string[]> TokenizerTestCases() => new()
{
{ "", new[] { "" } },
{ "aBc", new[] { "aBc" } },
{ " Foo ", new[] { "Foo" } },
{ " \" Foo \" ", new[] { " Foo " } },
{ " \" Foo ", new[] { " Foo " } },
{ "\"\"abc", new[] { "" } },
{ "a\"\"bc", new[] { "a\"\"bc" } },
{ "\"\"", new[] { "" } },
{ ",", new[] { "", "" } },
{ " foo ,bar", new[] { "foo", "bar" } },
{ "\"a\"bc,de", new[] { "a" } },
{ "a\"b,\" c,d\", f ,,g", new[] { "a\"b", " c,d", "f", "", "g" } }
};
}
}