using CanonSharp.Combinator; using CanonSharp.Combinator.Abstractions; using CanonSharp.Common.Scanner; namespace CanonSharp.Tests.Utils; public abstract class LexicalTestBase { protected static void ValidateSuccessfulParser(Parser parser, LexicalTokenType exceptedType, string literalValue, string input) { StringReadState state = new(input); ParseResult result = parser.Parse(state); Assert.Equal(exceptedType, result.Value.TokenType); Assert.Equal(literalValue, result.Value.LiteralValue); } protected static void ValidateFailedParser(Parser parser, string input) { StringReadState state = new(input); ParseResult result = parser.Parse(state); Assert.ThrowsAny(() => result.Value); } protected static void ValidateLexicalTokens(Parser> parser, string input, IEnumerable<(LexicalTokenType, string)> exceptedResult) { StringReadState state = new(input); ParseResult> result = parser.Parse(state); foreach (((LexicalTokenType exceptedType, string exceptedValue), LexicalToken token) in exceptedResult.Zip( result.Value)) { Assert.Equal(exceptedType, token.TokenType); Assert.Equal(exceptedValue, token.LiteralValue); } } }