Пример #1
0
        public void Or_FirstSuccess_ReturnsFirstResult()
        {
            var parser = Combine.Or(Parse.Succeed('x'), Parse.Succeed('y'));
            var result = parser.Parse("");

            ParseAssert.ValueEquals('x', result);
        }
Пример #2
0
        public void Or_FirstError_ReturnsSecondResult()
        {
            var parser = Combine.Or(Parse.Fail <int>("test"), Parse.Succeed(42));
            var result = parser.Parse("");

            ParseAssert.ValueEquals(42, result);
        }
Пример #3
0
        public void Or_FirstErrorConsumesInput_ReturnsFirstError()
        {
            var parserA = from x in Chars.Any()
                          from y in Parse.Fail <char>("test")
                          select y;
            var parserB = Chars.Any();
            var parser  = Combine.Or(parserA, parserB);

            var result = parser.Parse("abc");

            ParseAssert.ErrorEquals("test", result);
        }