示例#1
0
        public void Int_NoDigit_ReturnsError()
        {
            var parser = Numeric.Int();
            var result = parser.Parse("xyz");

            ParseAssert.IsError(result);
        }
示例#2
0
        public void Between_NonMatchingValue_ReturnsError()
        {
            var parser = Chars.Char('x').Between(Chars.Char('['), Chars.Char(']'));
            var result = parser.Parse("[_]");

            ParseAssert.IsError(result);
        }
示例#3
0
        public void Between_RepeatingValue_ReturnsValue()
        {
            var parser = Chars.NoneOf("]").Many().Between(Chars.Char('['), Chars.Char(']'));
            var result = parser.Parse("[xyz]");

            ParseAssert.ValueEquals("xyz", result);
        }
示例#4
0
        public void Repeat_CountZero_ReturnsEmptyResult()
        {
            var parser = Chars.Char('x').Repeat(0);
            var result = parser.Parse("xxxxx");

            ParseAssert.ValueEquals(new char[0], result);
        }
示例#5
0
        public void Repeat_CountThree_ReturnsThreeMatches()
        {
            var parser = Chars.Char('x').Repeat(3);
            var result = parser.Parse("xxxxx");

            ParseAssert.ValueEquals(new char[] { 'x', 'x', 'x' }, result);
        }
示例#6
0
        public void SeparatedBy_ValueOnly_ReturnsValue()
        {
            var parser = Chars.Any().SeparatedBy(Chars.Char(';'));
            var result = parser.Parse("x");

            ParseAssert.ValueEquals(new char[] { 'x' }, result);
        }
示例#7
0
        public void SeparatedBy_ValueAndSeparator_ReturnsError()
        {
            var parser = Chars.Any().SeparatedBy(Chars.Char(';'));
            var result = parser.Parse("x;");

            ParseAssert.IsError(result);
        }
示例#8
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);
        }
示例#9
0
        public void Many_NoMatch_ReturnsEmptySet()
        {
            var parser = Chars.Char('x').Many();
            var result = parser.Parse("y");

            ParseAssert.ValueEquals("", result);
        }
示例#10
0
        public void Double_Int_ReturnsDoubleValue()
        {
            var parser = Numeric.Double();
            var result = parser.Parse("42");

            ParseAssert.ValueEquals(42, result);
        }
示例#11
0
        public void Double_IntThenFraction_ReturnsDoubleValue()
        {
            var parser = Numeric.Double();
            var result = parser.Parse("42.37");

            ParseAssert.ValueEquals(42.37, result);
        }
示例#12
0
        public void Double_NonNumeric_ReturnsError()
        {
            var parser = Numeric.Double();
            var result = parser.Parse("test");

            ParseAssert.IsError(result);
        }
示例#13
0
        public void Int_Plus_ReturnIntValue()
        {
            var parser = Numeric.Int();
            var result = parser.Parse("+42xyz");

            ParseAssert.ValueEquals(42, result);
        }
示例#14
0
        public void Int_Negative_ReturnsIntValue()
        {
            var parser = Numeric.Int();
            var result = parser.Parse("-42xyz");

            ParseAssert.ValueEquals(-42, result);
        }
示例#15
0
        public void NotFollowedBy_ParserBSuccess_ReturnsError()
        {
            var parser = Chars.Char('x').NotFollowedBy(Chars.Char('y'));
            var result = parser.Parse("xy");

            ParseAssert.IsError(result);
        }
示例#16
0
        public void Many1_NoMatch_ReturnsError()
        {
            var parser = Chars.Char('x').Many1();
            var result = parser.Parse("y");

            ParseAssert.IsError(result);
        }
示例#17
0
        public void SeparatedBy_Nothing_ReturnsEmptyValue()
        {
            var parser = Chars.Any().SeparatedBy(Chars.Char(';'));
            var result = parser.Parse("");

            ParseAssert.ValueEquals(new char[] { }, result);
        }
示例#18
0
        public void Many1_OneMatch_ReturnsSetWithOneMatch()
        {
            var parser = Chars.Char('x').Many1();
            var result = parser.Parse("xy");

            ParseAssert.ValueEquals("x", result);
        }
示例#19
0
        public void Before_ParserABSuccess_ReturnsParserBResult()
        {
            var parser = Chars.Char('x').Before(Chars.Char('y'));
            var result = parser.Parse("xy");

            ParseAssert.ValueEquals('y', result);
        }
示例#20
0
        public void Many1_ManyMatches_ReturnsSet()
        {
            var parser = Chars.OneOf("xyz").Many1();
            var result = parser.Parse("xxyz");

            ParseAssert.ValueEquals("xxyz", result);
        }
示例#21
0
        public void SeparatedBy_MultipleValues_ReturnsValues()
        {
            var parser = Chars.Any().SeparatedBy(Chars.Char(';'));
            var result = parser.Parse("x;y;z");

            ParseAssert.ValueEquals(new char[] { 'x', 'y', 'z' }, result);
        }
示例#22
0
        public void Before_ParserBError_ReturnsError()
        {
            var parser = Chars.Char('x').Before(Chars.Char('y'));
            var result = parser.Parse("xx");

            ParseAssert.IsError(result);
        }
示例#23
0
        public void Repeat_CountOne_ReturnsSingleMatch()
        {
            var parser = Chars.Char('x').Repeat(1);
            var result = parser.Parse("xxxxx");

            ParseAssert.ValueEquals(new char[] { 'x' }, result);
        }
示例#24
0
        public void FollowedBy_ParserBError_ReturnsError()
        {
            var parser = Chars.Char('x').FollowedBy(Chars.Char('y'));
            var result = parser.Parse("xx");

            ParseAssert.IsError(result);
        }
示例#25
0
        public void Repeat_CountLargerThanMatching_ReturnsError()
        {
            var parser = Chars.Char('x').Repeat(42);
            var result = parser.Parse("xxxxx");

            ParseAssert.IsError(result);
        }
示例#26
0
        public void FollowedBy_ParserABSuccess_ReturnsParserAResult()
        {
            var parser = Chars.Char('x').FollowedBy(Chars.Char('y'));
            var result = parser.Parse("xy");

            ParseAssert.ValueEquals('x', result);
        }
示例#27
0
        public void Between_AllMatching_ReturnsValue()
        {
            var parser = Chars.Any().Between(Chars.Char('['), Chars.Char(']'));
            var result = parser.Parse("[x]");

            ParseAssert.ValueEquals('x', result);
        }
示例#28
0
        public void NotFollowedBy_ParserBError_ReturnsParserAValue()
        {
            var parser = Chars.Char('x').NotFollowedBy(Chars.Char('y'));
            var result = parser.Parse("xz");

            ParseAssert.ValueEquals('x', result);
        }
示例#29
0
        public void Or_FirstSuccess_ReturnsFirstResult()
        {
            var parser = Combine.Or(Parse.Succeed('x'), Parse.Succeed('y'));
            var result = parser.Parse("");

            ParseAssert.ValueEquals('x', result);
        }
示例#30
0
        public void OneOf_NonMatchingChar_ReturnsError()
        {
            var parser = Chars.OneOf("xyz");
            var result = parser.Parse("a");

            ParseAssert.IsError(result);
        }