Пример #1
0
 public void FailGracefullyOnSequence()
 {
     var sequence = Parse.Char('a').XDelimitedBy(Parse.Char(','));
     AssertParser.FailsWith(sequence, "a,a,b", result =>
     {
         Assert.Contains(string.Format(TRS.UnexpectedToken, "b"), result.Message);
         Assert.Contains("a", result.Expectations);
     });
 }
Пример #2
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");
        }
Пример #3
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);
        }
Пример #4
0
 public void CanParseSeceralLines()
 {
     AssertParser.SucceedsWith(
         AssemblerParser.Assembler,
         @"      ;multiline sample
                 label:  
                 mov   a  ,  b;",
         lines => Assert.Equal(
             new[]
     {
         new AssemblerLine(null, null, null, "multiline sample"),
         new AssemblerLine("label", null, null, null),
         new AssemblerLine(null, "mov", new[] { "a", "b" }, "")
     },
             lines));
 }
Пример #5
0
 public void ReturningValue_DoesNotAdvanceInput()
 {
     var p = Parse.Return(1);
     AssertParser.SucceedsWith(p, "abc", n => Assert.Equal(1, n));
 }
Пример #6
0
 public void ConcatenatingParsers_ConcatenatesResults()
 {
     var p = Parse.Char('a').Once().Then(a =>
         Parse.Char('b').Once().Select(b => a.Concat(b)));
     AssertParser.SucceedsWithAll(p, "ab");
 }
Пример #7
0
 public void Parser_OfAtLeastOneChar_AcceptsManyChars()
 {
     AssertParser.SucceedsWithAll(Parse.Char('a').AtLeastOnce(), "aaa");
 }
Пример #8
0
 public void Parser_OfAtLeastOneChar_DoesNotAcceptEmptyInput()
 {
     AssertParser.Fails(Parse.Char('a').AtLeastOnce(), "");
 }
Пример #9
0
 public void Parser_OfManyChars_AcceptsManyChars()
 {
     AssertParser.SucceedsWithAll(Parse.Char('a').Many(), "aaa");
 }
Пример #10
0
 public void CanParseLabel()
 {
     AssertParser.SucceedsWith(
         AssemblerParser.Assembler, "label:",
         lines => Assert.Equal(new AssemblerLine("label", null, null, null), lines.Single()));
 }
Пример #11
0
 public void IgnoreCaseParser()
 {
     var ab = Parse.IgnoreCase("ab").Text();
     AssertParser.SucceedsWith(ab, "Ab", m => Assert.Equal("Ab", m));
 }
Пример #12
0
 public void NotParserConsumesNoInputOnFailure()
 {
     var notAb = Parse.String("ab").Text().Not();
     AssertParser.FailsAt(notAb, "abc", 0);
 }
Пример #13
0
 public void XAtLeastOnceParser_WhenFirstElementFails_FailureReportedAtFirstElement()
 {
     var ab = Parse.String("ab").Text();
     var p = ab.XAtLeastOnce().End();
     AssertParser.FailsAt(p, "d", 0);
 }
Пример #14
0
 public void Parser_OfChar_DoesNotAcceptNonMatchingChar()
 {
     AssertParser.FailsAt(Parse.Char('a').Once(), "b", 0);
 }
Пример #15
0
 public void XOptionalParserFailsOnPartialMatch()
 {
     var optAbc = Parse.String("abc").Text().XOptional();
     AssertParser.FailsAt(optAbc, "abd", 2);
     AssertParser.FailsAt(optAbc, "aa", 1);
 }
Пример #16
0
 public void Parser_OfChar_AcceptsOnlyOneChar()
 {
     AssertParser.SucceedsWithOne(Parse.Char('a').Once(), "aaa", 'a');
 }
Пример #17
0
 public void ExceptStopsConsumingInputWhenExclusionParsed()
 {
     var exceptAa = Parse.AnyChar.Except(Parse.String("aa")).Many().Text();
     AssertParser.SucceedsWith(exceptAa, "abcaab", r => Assert.Equal("abc", r));
 }
Пример #18
0
 public void CanParseEmpty()
 {
     AssertParser.SucceedsWith(AssemblerParser.Assembler, string.Empty, Assert.Empty);
 }
Пример #19
0
 public void CanParseCommentWithSpaces()
 {
     AssertParser.SucceedsWith(AssemblerParser.Assembler,
                               "  ; comment ",
                               lines => Assert.Equal(new AssemblerLine(null, null, null, " comment "), lines.Single()));
 }
Пример #20
0
 public void WhenFirstOptionSucceedsButConsumesNothing_SecondOptionTried()
 {
     var p = Parse.Char('a').Many().XOr(Parse.Char('b').Many());
     AssertParser.SucceedsWithAll(p, "bbb");
 }
Пример #21
0
 public void Parser_OfManyChars_AcceptsEmptyInput()
 {
     AssertParser.SucceedsWithAll(Parse.Char('a').Many(), "");
 }
Пример #22
0
 public void ParsesString_AsSequenceOfChars()
 {
     var p = Parse.String("abc");
     AssertParser.SucceedsWithAll(p, "abc");
 }