using CanonSharp.Combinator; using CanonSharp.Combinator.Abstractions; using CanonSharp.Combinator.Extensions; using CanonSharp.Tests.Utils; using static CanonSharp.Combinator.ParserBuilder; using static CanonSharp.Combinator.Text.TextParserBuilder; namespace CanonSharp.Tests.CombinatorsTests; public class ModifierParserTests : ParserTestsBase { [Fact] public void DoTest() { Parser parser = Token('a').Do(x => Assert.Equal('a', x)).Do(x => Assert.Equal('a', x), failedResult => Assert.ThrowsAny(() => failedResult.Value)); ValidateSuccessfulResult(parser, 'a', "abc"); ValidateFailedResult(parser, "bcd"); } [Fact] public void LookAheadTest() { Parser parser = Token('a').LookAhead().Next(_ => Token('a'), _ => Token('b')); ValidateSuccessfulResult(parser, 'a', "abc"); ValidateSuccessfulResult(parser, 'b', "bcd"); } [Fact] public void NotTest() { Parser parser = Token('a').Not('b'); ValidateSuccessfulResult(parser, 'b', "bcd"); parser = Token('a').Not().Bind(_ => Token('b')); ValidateSuccessfulResult(parser, 'b', "bcd"); } [Fact] public void TryTest() { Parser parser = String("abc").Try("cde"); ValidateSuccessfulResult(parser, "abc", "abc"); ValidateSuccessfulResult(parser, "cde", "cde"); parser = String("abc").Try(_ => "cde"); ValidateSuccessfulResult(parser, "abc", "abc"); ValidateSuccessfulResult(parser, "cde", "cde"); } }