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