예제 #1
0
        public void CanSpecifyParsersUsingQueryComprehensions()
        {
            var p = from a in Parse.Char('a').Once()
                    from bs in Parse.Char('b').Many()
                    from cs in Parse.Char('c').AtLeastOnce()
                    select a.Concat(bs).Concat(cs);

            AssertParser.SucceedsWithAll(p, "abbbc");
        }
예제 #2
0
        public void WithXMany_WhenLastElementFails_FailureReportedAtLastElement()
        {
            var ab = from a in Parse.Char('a')
                     from b in Parse.Char('b')
                     select "ab";

            var p = ab.XMany().End();

            AssertParser.FailsAt(p, "ababaf", 5);
        }
예제 #3
0
        public void FailGracefullyOnSequence()
        {
            var sequence = Parse.Char('a').XDelimitedBy(Parse.Char(','));

            AssertParser.FailsWith(sequence, "a,a,b", result =>
            {
                StringAssert.Contains("unexpected 'b'", result.Message);
                CollectionAssert.Contains(result.Expectations, "a");
            });
        }
예제 #4
0
 public void Parser_OfChar_DoesNotAcceptNonMatchingChar()
 {
     AssertParser.FailsAt(Parse.Char('a').Once(), "b", 0);
 }
예제 #5
0
        public void ExceptStopsConsumingInputWhenExclusionParsed()
        {
            var exceptAa = Parse.AnyChar.Except(Parse.String("aa")).Many().Text();

            AssertParser.SucceedsWith(exceptAa, "abcaab", r => Assert.AreEqual("abc", r));
        }
예제 #6
0
 public void TestSelectManyNone() => AssertParser.SucceedsWith(ParserOptionalSelectMany, "b", o => Assert.True(o.IsEmpty));
예제 #7
0
 public void Parser_OfAtLeastOneChar_AcceptsManyChars()
 {
     AssertParser.SucceedsWithAll(Parse.Char('a').AtLeastOnce(), "aaa");
 }
예제 #8
0
 public void Parser_OfManyChars_AcceptsManyChars()
 {
     AssertParser.SucceedsWithAll(Parse.Char('a').Many(), "aaa");
 }
예제 #9
0
 public void RecursiveParserWithoutLeftRecursion() => AssertParser.SucceedsWith(Parser2UnderTest, "ababba0", o => Assert.Equal("ababba0", o));
예제 #10
0
 public void MultipleRefs() => AssertParser.SucceedsWith(Parser1UnderTest, "id=1", o => Assert.Equal("id", o));
예제 #11
0
 public void CanParseMutuallyLeftRecursiveGrammar()
 {
     AssertParser.SucceedsWithAll(ABSeq.End(), "baba");
 }
예제 #12
0
 public void CanParseLeftRecursiveGrammar()
 {
     AssertParser.SucceedsWith(ASeq.End(), "a,a,a", r => new string(r.ToArray()).Equals("aaa"));
 }
예제 #13
0
 public void TestSelectManyLinq() => AssertParser.SucceedsWith(ParserOptionalLinq, "ab", o => AssertSome(o, "ba"));
예제 #14
0
        public void NotParserConsumesNoInputOnFailure()
        {
            var notAb = Parse.String("ab").Text().Not();

            AssertParser.FailsAt(notAb, "abc", 0);
        }
예제 #15
0
 public void EmptyAlternative1() => AssertParser.SucceedsWith(Parser5UnderTest, "_+_+a", o => Assert.Equal("_+_+", o));
예제 #16
0
        public void IgnoreCaseParser()
        {
            var ab = Parse.IgnoreCase("ab").Text();

            AssertParser.SucceedsWith(ab, "Ab", m => Assert.AreEqual("Ab", m));
        }
예제 #17
0
        public void WhenFirstOptionSucceedsButConsumesNothing_SecondOptionTried()
        {
            var p = Parse.Char('a').Many().XOr(Parse.Char('b').Many());

            AssertParser.SucceedsWithAll(p, "bbb");
        }
예제 #18
0
 public void Parser_OfManyChars_AcceptsEmptyInput()
 {
     AssertParser.SucceedsWithAll(Parse.Char('a').Many(), "");
 }
예제 #19
0
        public void ParsesString_AsSequenceOfChars()
        {
            var p = Parse.String("abc");

            AssertParser.SucceedsWithAll(p, "abc");
        }
예제 #20
0
 public void Parser_OfAtLeastOneChar_DoesNotAcceptEmptyInput()
 {
     AssertParser.Fails(Parse.Char('a').AtLeastOnce(), "");
 }
예제 #21
0
 public void Parser_OfChar_AcceptsOnlyOneChar()
 {
     AssertParser.SucceedsWithOne(Parse.Char('a').Once(), "aaa", 'a');
 }
예제 #22
0
        public void ReturningValue_DoesNotAdvanceInput()
        {
            var p = Parse.Return(1);

            AssertParser.SucceedsWith(p, "abc", n => Assert.AreEqual(1, n));
        }
예제 #23
0
 public void TestSelect() => AssertParser.SucceedsWith(ParserOptionalSelect, "a", o => AssertSome(o, 'A'));