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

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

            ParseAssert.IsError(result);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #7
0
        public void SeparatedBy_ValueAndSeparator_ReturnsError()
        {
            var parser = Chars.Any().SeparatedBy(Chars.Char(';'));
            var result = parser.Parse("x;");

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

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

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

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

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

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

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

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

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

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

            ParseAssert.ValueEquals("x", result);
        }
Exemple #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);
        }
Exemple #20
0
        public void Many1_ManyMatches_ReturnsSet()
        {
            var parser = Chars.OneOf("xyz").Many1();
            var result = parser.Parse("xxyz");

            ParseAssert.ValueEquals("xxyz", result);
        }
Exemple #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);
        }
Exemple #22
0
        public void Before_ParserBError_ReturnsError()
        {
            var parser = Chars.Char('x').Before(Chars.Char('y'));
            var result = parser.Parse("xx");

            ParseAssert.IsError(result);
        }
Exemple #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);
        }
Exemple #24
0
        public void FollowedBy_ParserBError_ReturnsError()
        {
            var parser = Chars.Char('x').FollowedBy(Chars.Char('y'));
            var result = parser.Parse("xx");

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

            ParseAssert.IsError(result);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #30
0
        public void OneOf_NonMatchingChar_ReturnsError()
        {
            var parser = Chars.OneOf("xyz");
            var result = parser.Parse("a");

            ParseAssert.IsError(result);
        }