CanonSharp/CanonSharp.Tests/CombinatorsTests/LinqTests.cs
jackfiled cf19f8197e feat: Grammar Parser (#3)
Reviewed-on: https://git.bupt-hpc.cn/jackfiled/CanonSharp/pulls/3
Co-authored-by: jackfiled <xcrenchangjun@outlook.com>
Co-committed-by: jackfiled <xcrenchangjun@outlook.com>
2024-08-18 12:01:27 +08:00

30 lines
815 B
C#

using CanonSharp.Combinator.Abstractions;
using CanonSharp.Combinator.Extensions;
using static CanonSharp.Combinator.Text.TextParserBuilder;
using CanonSharp.Tests.Utils;
namespace CanonSharp.Tests.CombinatorsTests;
public class LinqTests : ParserTestsBase
{
[Fact]
public void SelectTest1()
{
IParser<char, string> parser = from token in Char('a')
select token.ToString();
ValidateSuccessfulResult(parser, "a", "a");
ValidateFailedResult(parser, "b");
}
[Fact]
public void SelectManyTest1()
{
IParser<char, int> parser = from _1 in Char('a')
from _2 in Char('b')
from _3 in Char('c')
select 123;
ValidateSuccessfulResult(parser, 123, "abc");
ValidateFailedResult(parser, "asd");
}
}