Exemple #1
0
        public void TestObjectDecorationValueEvaluator(string value, string expected)
        {
            var    tree   = ObjectDecorationParserFacade.ParseObjectDecorationValue(value);
            string actual = (string)_evaluator.Visit(tree, null);

            Assert.Equal(expected, actual);
        }
        public void TestSimpleObjectDecoration()
        {
            var parseTree = ObjectDecorationParserFacade.ParseObjectDecoration(TWO_KEYVALUE_PARIS_WITH_ONE_VARIBLE);

            Assert.Equal(2, parseTree.List.Count);
            Assert.Equal(" key1 ", parseTree.List[0].Key);
            Assert.Equal(3, ((NodeList <Node>)parseTree.List[0].Value).List.Count);
            Assert.Equal("key2", parseTree.List[1].Key);
        }
Exemple #3
0
        public void TestSimpleExpression()
        {
            var parseTree = ObjectDecorationParserFacade.ParseObjectDecorationValue(SIMPLE_EXPRESSION);

            Assert.Equal(3, parseTree.List.Count);
            Assert.IsType <LiteralNode>(parseTree.List[0]);
            Assert.IsType <LiteralNode>(parseTree.List[2]);

            var invocationExpression = (InvocationNode)parseTree.List[1];

            Assert.Equal("regex_extract", invocationExpression.FunctionName.Identifier);
            Assert.Equal(2, invocationExpression.Arguments.Count);
            Assert.IsType <IdentifierNode>(invocationExpression.Arguments[0]);
            Assert.IsType <LiteralNode>(invocationExpression.Arguments[1]);
        }
Exemple #4
0
        public void TestNestedExpression()
        {
            var parseTree = ObjectDecorationParserFacade.ParseObjectDecorationValue(NESTED_EXPRESSION);

            Assert.Single(parseTree.List);

            var invocationExpression = (InvocationNode)parseTree.List[0];

            Assert.Equal("substr", invocationExpression.FunctionName.Identifier);
            Assert.Equal(2, invocationExpression.Arguments.Count);
            var arg0 = (InvocationNode)invocationExpression.Arguments[0];

            Assert.Equal("regex_extract", arg0.FunctionName.Identifier);
            Assert.Equal(2, arg0.Arguments.Count);
            Assert.IsType <IdentifierNode>(arg0.Arguments[0]);
            Assert.IsType <LiteralNode>(arg0.Arguments[1]);

            Assert.IsType <LiteralNode>(invocationExpression.Arguments[1]);
        }
        public ObjectDecorationExEvaluator(string objectDecoration,
                                           Func <string, string> evaluateVariable,
                                           Func <string, IEnvelope, object> evaluateRecordVariable,
                                           ILogger logger
                                           )
        {
            _tree = ObjectDecorationParserFacade.ParseObjectDecoration(objectDecoration);
            FunctionBinder binder = new FunctionBinder(new Type[] { typeof(BuiltInFunctions) });
            ExpressionEvaluationContext <IEnvelope> evalContext = new ExpressionEvaluationContext <IEnvelope>(
                evaluateVariable,
                evaluateRecordVariable,
                binder,
                logger
                );
            var validator = new ObjectDecorationValidator <IEnvelope>(evalContext);

            validator.Visit(_tree, null); //Should throw if cannot resolve function
            _interpreter = new ObjectDecorationInterpreter <IEnvelope>(evalContext);
        }
 public void TestIncompleteObjectDecoration()
 {
     Assert.Throws <Exception>(() => ObjectDecorationParserFacade.ParseObjectDecoration(INCOMPLETE_OBJECTDECORATION));
 }
        public void TestObjectDecorationWithExpressions()
        {
            var parseTree = ObjectDecorationParserFacade.ParseObjectDecoration(OBJECTDECORATION_WITH_EXPRESSIONS);

            Assert.Equal(6, parseTree.List.Count);
        }