Example #1
0
 public void Parse_Success(string input, ExpressionKind expectedRootExpressionKind)
 {
     AssertParser.SucceedsWith(Parsers.GroupedExpression, input, actualExpression =>
     {
         Assert.Equal(expectedRootExpressionKind, actualExpression.Kind);
     });
 }
 public void Parse_Success(string input, string expectedContent)
 {
     AssertParser.SucceedsWith(Parsers.QuotedStringLiteral, input, actualQuotedStringLiteral =>
     {
         Assert.Equal(expectedContent, actualQuotedStringLiteral.Content);
     });
 }
        public void OneOf2TokenSucceeds()
        {
            var p = Parse.OneOf(Token.EqualTo('1'), Token.EqualTo('w'));

            AssertParser.SucceedsWith(p, "1", '1');
            AssertParser.SucceedsWith(p, "w", 'w');
        }
Example #4
0
        public void Parse_Binary_Comparison_QuotedString_Success(string input, LogicalOperatorKind expectedLogicalOperatorKind, ComparisonKind expectedLeftComparisonKind, ComparisonKind expectedRightComparisonKind, string expectedLeftLeftString, string expectedLeftRightString, string expectedRightLeftString, string expectedRightRightString)
        {
            AssertParser.SucceedsWith(Parsers.Logical, input, actualLogical =>
            {
                Assert.Equal(expectedLogicalOperatorKind, actualLogical.OperatorKind);

                // Left-hand comparison.
                Compare leftComparison = Assert.IsType <Compare>(actualLogical.Left);
                Assert.Equal(expectedLeftComparisonKind, leftComparison.ComparisonKind);

                QuotedString leftLeftString = Assert.IsType <QuotedString>(leftComparison.Left);
                Assert.Equal(expectedLeftLeftString, leftLeftString.StringContent);

                QuotedString leftRightString = Assert.IsType <QuotedString>(leftComparison.Right);
                Assert.Equal(expectedLeftRightString, leftRightString.StringContent);

                // Right-hand comparison.
                Compare rightComparison = Assert.IsType <Compare>(actualLogical.Right);
                Assert.Equal(expectedRightComparisonKind, rightComparison.ComparisonKind);

                QuotedString rightLeftString = Assert.IsType <QuotedString>(rightComparison.Left);
                Assert.Equal(expectedRightLeftString, rightLeftString.StringContent);

                QuotedString rightRightString = Assert.IsType <QuotedString>(rightComparison.Right);
                Assert.Equal(expectedRightRightString, rightRightString.StringContent);
            });
        }
Example #5
0
 public void Parse_Success(string input, string expectedItemGroupName)
 {
     AssertParser.SucceedsWith(Parsers.ItemGroup, input, actualItemGroup =>
     {
         Assert.Equal(expectedItemGroupName, actualItemGroup.Name);
     });
 }
 public void Parse_Success(string input, string expectedIdentifierName)
 {
     AssertParser.SucceedsWith(Tokens.Identifier, input, actualToken =>
     {
         Assert.Equal(expectedIdentifierName, actualToken);
     });
 }
        public void Parse_Success(string input, string expectedItemType, bool expectBody, bool expectSeparator)
        {
            AssertParser.SucceedsWith(Parsers.ItemGroupTransform, input, actualItemGroupTransform =>
            {
                Assert.Equal(expectedItemType, actualItemGroupTransform.Name);

                if (expectBody)
                {
                    Assert.True(actualItemGroupTransform.HasBody, "HasBody");
                }
                else
                {
                    Assert.False(actualItemGroupTransform.HasBody, "HasBody");
                }

                if (expectSeparator)
                {
                    Assert.True(actualItemGroupTransform.HasSeparator, "HasSeparator");
                }
                else
                {
                    Assert.False(actualItemGroupTransform.HasSeparator, "HasSeparator");
                }
            });
        }
 public void ArgumentList_Success(string input, int expectedArgumentCount)
 {
     AssertParser.SucceedsWith(Parsers.FunctionCalls.ArgumentList, input, actualArgumentList =>
     {
         Assert.Equal(expectedArgumentCount, actualArgumentList.Count());
     });
 }
        public void ManyReportsCorrectRemainderForBacktrackingPartialItemMatch()
        {
            var ab   = Character.EqualTo('a').Then(_ => Character.EqualTo('b'));
            var list = Span.MatchedBy(ab.Try().Many()).Select(s => s.ToStringValue());

            AssertParser.SucceedsWith(list, "ababac", "abab");
        }
Example #10
0
 public void ParseSimpleListItem_Success(string input)
 {
     AssertParser.SucceedsWith(Parsers.SimpleLists.Item, input, actualItem =>
     {
         Assert.Equal(input, actualItem.Value);
     });
 }
 public void Parse_Qualified_Success(string input, string expectedItemType, string expectedMetadataName)
 {
     AssertParser.SucceedsWith(Parsers.ItemMetadata, input, actualItemMetadata =>
     {
         Assert.Equal(expectedItemType, actualItemMetadata.ItemType);
         Assert.Equal(expectedMetadataName, actualItemMetadata.Name);
     });
 }
Example #12
0
 public void Parse_Success(string input, string expectedTypeName, string expectedTypeNamespace)
 {
     AssertParser.SucceedsWith(Parsers.TypeRef, input, actualTypeRef =>
     {
         Assert.Equal(expectedTypeName, actualTypeRef.Name);
         Assert.Equal(expectedTypeNamespace, actualTypeRef.Namespace);
     });
 }
 public void AnEndDelimiterCanBeSpecified()
 {
     AssertParser.SucceedsWith(
         Token.EqualTo('a').Value('a')
         .ManyDelimitedBy(Token.EqualTo('b'), end: Token.EqualTo('c')),
         "ababac",
         new[] { 'a', 'a', 'a' });
 }
        public void OneOfReportsCorrectError()
        {
            var names = new[] { "one", "two" };
            TextParser <TextSpan> p = Parse.OneOf(names.Select(Span.EqualTo).ToArray());

            AssertParser.SucceedsWith(p.Select(t => t.ToStringValue()), "one", "one");
            AssertParser.SucceedsWith(p.Select(t => t.ToStringValue()), "two", "two");
            AssertParser.FailsWithMessage(p.Select(t => t.ToStringValue()), "four", "Syntax error (line 1, column 1): unexpected `f`, expected `one` or `two`.");
        }
        public void Parse_Logical_Success(string input, ExpressionKind expectedRootExpressionKind)
        {
            AssertParser.SucceedsWith(Parsers.Root, input, actualRoot =>
            {
                Assert.Equal(1, actualRoot.Children.Count);
                ExpressionNode actualExpression = actualRoot.Children[0];

                Assert.Equal(expectedRootExpressionKind, actualExpression.Kind);
            });
        }
Example #16
0
        public void Parse_Symbol_Success(string input, string expectedSymbolName)
        {
            AssertParser.SucceedsWith(Parsers.Evaluation, input, actualEvaluation =>
            {
                Assert.Equal(1, actualEvaluation.Children.Count);

                Symbol actualSymbol = Assert.IsType <Symbol>(actualEvaluation.Children[0]);
                Assert.Equal(expectedSymbolName, actualSymbol.Name);
            });
        }
Example #17
0
        public void Parse_FunctionCall_Success(string input, string expectedFunctionName)
        {
            AssertParser.SucceedsWith(Parsers.Evaluation, input, actualEvaluation =>
            {
                Assert.Equal(1, actualEvaluation.Children.Count);

                FunctionCall actualFunctionCall = Assert.IsType <FunctionCall>(actualEvaluation.Children[0]);
                Assert.Equal(expectedFunctionName, actualFunctionCall.Name);
            });
        }
Example #18
0
        public void Parse_Unary_Not_Symbol_Success(string input, string expectedSymbol)
        {
            AssertParser.SucceedsWith(Parsers.LogicalUnary, input, actualLogical =>
            {
                Assert.Equal(LogicalOperatorKind.Not, actualLogical.OperatorKind);

                Symbol rightSymbol = Assert.IsType <Symbol>(actualLogical.Right);
                Assert.Equal(expectedSymbol, rightSymbol.Name);
            });
        }
        public void Parse_Unqualified_Success(string input, string expectedMetadataName)
        {
            AssertParser.SucceedsWith(Parsers.ItemMetadata, input, actualItemMetadata =>
            {
                actualItemMetadata.PostParse(
                    new TextPositions(input)
                    );

                Assert.Equal(expectedMetadataName, actualItemMetadata.Name);
            });
        }
Example #20
0
        public void SuccessLeftAssociativeChain()
        {
            const string input       = "A.1.2.3";
            var          seed        = Character.EqualTo('A').Select(i => System.Collections.Immutable.ImmutableList.Create <int>());
            var          chainParser = seed.Chain(
                Character.EqualTo('.'),
                Numerics.IntegerInt32,
                (o, r, i) => r.Add(i));

            AssertParser.SucceedsWith(chainParser, input, System.Collections.Immutable.ImmutableList.Create(1, 2, 3));
        }
Example #21
0
        public void SuccessWithLongChains()
        {
            const int chainLength = 5000;
            string    input       = string.Join("+", Enumerable.Repeat("1", chainLength));
            var       chainParser = Parse.Chain(
                Character.EqualTo('+'),
                Numerics.IntegerInt32,
                (opr, val1, val2) => val1 + val2);

            AssertParser.SucceedsWith(chainParser, input, chainLength);
        }
 public void Parse_StaticMethod_SingleArgument_String_Success(string input, ExpressionKind expectedArgumentKind)
 {
     AssertParser.SucceedsWith(Parsers.FunctionCalls.StaticMethod, input, actualFunctionCall =>
     {
         Assert.Equal(FunctionKind.StaticMethod, actualFunctionCall.FunctionKind);
         Assert.Collection(actualFunctionCall.Arguments, actualArgument =>
         {
             Assert.Equal(expectedArgumentKind, actualArgument.Kind);
         });
     });
 }
Example #23
0
        public void TokenSuccessWithLongChains()
        {
            const int chainLength = 5000;
            string    input       = string.Join("+", Enumerable.Repeat("1", chainLength));

            var chainParser = Parse.Chain(
                Token.EqualTo('+'),
                Token.EqualTo('1').Value(1),
                (opr, val1, val2) => val1 + val2);

            AssertParser.SucceedsWith(chainParser, input, chainLength);
        }
        public void Parse_Eval_Symbol_Success(string input, string expectedSymbolName)
        {
            AssertParser.SucceedsWith(Parsers.QuotedString, input, actualQuotedString =>
            {
                Evaluate evaluation = actualQuotedString.Evaluations.FirstOrDefault();
                Assert.NotNull(evaluation);

                Symbol symbol = evaluation.Children.OfType <Symbol>().FirstOrDefault();
                Assert.NotNull(symbol);

                Assert.Equal(expectedSymbolName, symbol.Name);
            });
        }
        public void FindDeepestNode_Success(string input, int absolutePosition, ExpressionKind expectedExpressionKind, ExpressionKind?parentExpressionKind)
        {
            AssertParser.SucceedsWith(Parsers.Root, input, actualExpression =>
            {
                actualExpression.PostParse(
                    new TextPositions(input)
                    );

                ExpressionNode actualNodeAtPosition = actualExpression.FindDeepestNodeAt(absolutePosition);
                Assert.NotNull(actualNodeAtPosition);
                Assert.Equal(expectedExpressionKind, actualNodeAtPosition.Kind);
                Assert.Equal(parentExpressionKind, actualNodeAtPosition.Parent?.Kind);
            });
        }
        public void Parse_Symbols_Success(string input, ComparisonKind expectedComparisonKind, string expectedLeftSymbol, string expectedRightSymbol)
        {
            AssertParser.SucceedsWith(Parsers.Comparison, input, actualComparison =>
            {
                Assert.Equal(expectedComparisonKind, actualComparison.ComparisonKind);

                Assert.NotNull(actualComparison.Left);
                Symbol left = Assert.IsType <Symbol>(actualComparison.Left);
                Assert.Equal(left.Name, expectedLeftSymbol);

                Assert.NotNull(actualComparison.Right);
                Symbol right = Assert.IsType <Symbol>(actualComparison.Right);
                Assert.Equal(right.Name, expectedRightSymbol);
            });
        }
        public void ParseCompare_QuotedStrings_Success(string input, ComparisonKind expectedComparisonKind, string expectedLeftContent, string expectedRightContent)
        {
            AssertParser.SucceedsWith(Parsers.Comparison, input, actualComparison =>
            {
                Assert.Equal(expectedComparisonKind, actualComparison.ComparisonKind);

                Assert.NotNull(actualComparison.Left);
                QuotedString left = Assert.IsType <QuotedString>(actualComparison.Left);
                Assert.Equal(expectedLeftContent, left.StringContent);

                Assert.NotNull(actualComparison.Right);
                QuotedString right = Assert.IsType <QuotedString>(actualComparison.Right);
                Assert.Equal(expectedRightContent, right.StringContent);
            });
        }
Example #28
0
 public void CanParseSeceralLines()
 {
     AssertParser.SucceedsWith(AssemblerParser.Assembler,
                               @"      ;multiline sample
                 label:  
                 mov   a  ,  b;",
                               lines => CollectionAssert.AreEqual(
                                   new[]
     {
         new AssemblerLine(null, null, null, "multiline sample"),
         new AssemblerLine("label", null, null, null),
         new AssemblerLine(null, "mov", new[] { "a", "b" }, "")
     },
                                   lines));
 }
Example #29
0
        public void Parse_Unary_Not_Comparison_QuotedString_Success(string input, ComparisonKind expectedComparisonKind, string expectedLeftString, string expectedRightString)
        {
            AssertParser.SucceedsWith(Parsers.Logical, input, actualLogical =>
            {
                Assert.Equal(LogicalOperatorKind.Not, actualLogical.OperatorKind);

                Compare comparison = Assert.IsType <Compare>(actualLogical.Right);
                Assert.Equal(expectedComparisonKind, comparison.ComparisonKind);

                QuotedString leftString = Assert.IsType <QuotedString>(comparison.Left);
                Assert.Equal(expectedLeftString, leftString.StringContent);

                QuotedString rightString = Assert.IsType <QuotedString>(comparison.Right);
                Assert.Equal(expectedRightString, rightString.StringContent);
            });
        }
        public void SimpleListEquivalentToStringSplit(string input)
        {
            AssertParser.SucceedsWith(Parsers.SimpleLists.List, input, actualList =>
            {
                DumpList(actualList, input);

                string[] expectedValues = input.Split(';');
                Assert.Collection(actualList.Items, HasListItems(expectedValues, (expectedValue, actualItem) =>
                {
                    Assert.Equal(ExpressionKind.SimpleListItem, actualItem.Kind);

                    SimpleListItem actuaListItem = Assert.IsType <SimpleListItem>(actualItem);
                    Assert.Equal(expectedValue, actuaListItem.Value);
                }));
            });
        }