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); }); }
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"); }
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); }
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)); }
public void ReturningValue_DoesNotAdvanceInput() { var p = Parse.Return(1); AssertParser.SucceedsWith(p, "abc", n => Assert.Equal(1, n)); }
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"); }
public void Parser_OfAtLeastOneChar_AcceptsManyChars() { AssertParser.SucceedsWithAll(Parse.Char('a').AtLeastOnce(), "aaa"); }
public void Parser_OfAtLeastOneChar_DoesNotAcceptEmptyInput() { AssertParser.Fails(Parse.Char('a').AtLeastOnce(), ""); }
public void Parser_OfManyChars_AcceptsManyChars() { AssertParser.SucceedsWithAll(Parse.Char('a').Many(), "aaa"); }
public void CanParseLabel() { AssertParser.SucceedsWith( AssemblerParser.Assembler, "label:", lines => Assert.Equal(new AssemblerLine("label", null, null, null), lines.Single())); }
public void IgnoreCaseParser() { var ab = Parse.IgnoreCase("ab").Text(); AssertParser.SucceedsWith(ab, "Ab", m => Assert.Equal("Ab", m)); }
public void NotParserConsumesNoInputOnFailure() { var notAb = Parse.String("ab").Text().Not(); AssertParser.FailsAt(notAb, "abc", 0); }
public void XAtLeastOnceParser_WhenFirstElementFails_FailureReportedAtFirstElement() { var ab = Parse.String("ab").Text(); var p = ab.XAtLeastOnce().End(); AssertParser.FailsAt(p, "d", 0); }
public void Parser_OfChar_DoesNotAcceptNonMatchingChar() { AssertParser.FailsAt(Parse.Char('a').Once(), "b", 0); }
public void XOptionalParserFailsOnPartialMatch() { var optAbc = Parse.String("abc").Text().XOptional(); AssertParser.FailsAt(optAbc, "abd", 2); AssertParser.FailsAt(optAbc, "aa", 1); }
public void Parser_OfChar_AcceptsOnlyOneChar() { AssertParser.SucceedsWithOne(Parse.Char('a').Once(), "aaa", 'a'); }
public void ExceptStopsConsumingInputWhenExclusionParsed() { var exceptAa = Parse.AnyChar.Except(Parse.String("aa")).Many().Text(); AssertParser.SucceedsWith(exceptAa, "abcaab", r => Assert.Equal("abc", r)); }
public void CanParseEmpty() { AssertParser.SucceedsWith(AssemblerParser.Assembler, string.Empty, Assert.Empty); }
public void CanParseCommentWithSpaces() { AssertParser.SucceedsWith(AssemblerParser.Assembler, " ; comment ", lines => Assert.Equal(new AssemblerLine(null, null, null, " comment "), lines.Single())); }
public void WhenFirstOptionSucceedsButConsumesNothing_SecondOptionTried() { var p = Parse.Char('a').Many().XOr(Parse.Char('b').Many()); AssertParser.SucceedsWithAll(p, "bbb"); }
public void Parser_OfManyChars_AcceptsEmptyInput() { AssertParser.SucceedsWithAll(Parse.Char('a').Many(), ""); }
public void ParsesString_AsSequenceOfChars() { var p = Parse.String("abc"); AssertParser.SucceedsWithAll(p, "abc"); }