using CanonSharp.Combinator; using CanonSharp.Combinator.Abstractions; using CanonSharp.Pascal.Scanner; namespace CanonSharp.Tests.Utils; public abstract class ParserTestsBase { protected static void ValidateSuccessfulResult(IParser parser, T value, string source) { StringReadState state = new(source); IParseResult result = parser.Parse(state); Assert.Equal(value, result.Value); } protected static void ValidateSuccessfulResult( IParser> parser, IEnumerable values, string source) { StringReadState state = new(source); IParseResult> result = parser.Parse(state); foreach ((T actual, T except) in result.Value.Zip(values)) { Assert.Equal(except, actual); } } protected static IFailedResult ValidateFailedResult(IParser parser, string source) { StringReadState state = new(source); IParseResult result = parser.Parse(state); Assert.ThrowsAny(() => { _ = result.Value; }); return (IFailedResult)result; } }