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