예제 #1
0
        public void It_Should_Parse_And_And_Or()
        {
            // Act
            var ast = _generator.Generate("Result : {% if true and false or true %} OK {% endif %}");


            // Assert
            var ifThenSymbolNode =
                LiquidASTGeneratorTests.FindNodesWithType(ast.LiquidAST, typeof(IfThenElseBlockTag)).FirstOrDefault();

            Assert.NotNull(ifThenSymbolNode);
            // ReSharper disable once PossibleNullReferenceException
            var predicateTree =
                ((IfThenElseBlockTag)ifThenSymbolNode.Data).IfElseClauses[0].LiquidExpressionTree;

            foreach (var expr in ((IfThenElseBlockTag)ifThenSymbolNode.Data).IfElseClauses)
            {
                DebugIfExpressions(expr.LiquidExpressionTree);
            }
            Assert.IsType <OrExpression>(predicateTree.Data.Expression);
            Assert.IsType <AndExpression>(predicateTree[0].Data.Expression);
            Assert.IsType <LiquidBoolean>(predicateTree[1].Data.Expression);
            Assert.IsType <LiquidBoolean>(predicateTree[0][0].Data.Expression);
            Assert.IsType <LiquidBoolean>(predicateTree[0][1].Data.Expression);
        }
예제 #2
0
        public void It_Should_Add_A_String_Reference()
        {
            // Act
            var ast            = _generator.Generate("Result : {% if \"hello\" %} OK {% endif %}");
            var ifThenElseNode = LiquidASTGeneratorTests.FindNodesWithType(ast.LiquidAST, typeof(IfThenElseBlockTag)).FirstOrDefault();

            Assert.NotNull(ifThenElseNode);
            // ReSharper disable once PossibleNullReferenceException
            var ifThenElseSymbol = ((IfThenElseBlockTag)ifThenElseNode.Data);

            // Assert
            Assert.IsType <LiquidString>(ifThenElseSymbol.IfElseClauses[0].LiquidExpressionTree.Data.Expression);
        }
        public void It_Should_Add_A_Boolean_Reference()
        {
            // Act
            var ast            = _generator.Generate("Result : {% if true %} OK {% endif %}");
            var ifThenElseNode = LiquidASTGeneratorTests.FindNodesWithType(ast.LiquidAST, typeof(IfThenElseBlockTag)).FirstOrDefault();

            Assert.That(ifThenElseNode, Is.Not.Null);
            // ReSharper disable once PossibleNullReferenceException
            var ifThenElseSymbol = ((IfThenElseBlockTag)ifThenElseNode.Data);

            // Assert
            Assert.That(ifThenElseSymbol.IfElseClauses[0].LiquidExpressionTree.Data.Expression, Is.TypeOf <LiquidBoolean>());
        }
예제 #4
0
        public void It_Should_Parse_Nested_If()
        {
            // Act
            var ast = _generator.Generate("Result : {% if true %} {% if false %} True and false {% endif %} {% endif %}");

            // Assert
            var parentIfThenElseSymbol = LiquidASTGeneratorTests.FindNodesWithType(ast.LiquidAST, typeof(IfThenElseBlockTag)).FirstOrDefault();

            // ReSharper disable once PossibleNullReferenceException
            var childIfThenElse = ((IfThenElseBlockTag)parentIfThenElseSymbol.Data).IfElseClauses[0].LiquidBlock;

            //Logger.Log(childIfThenElse);
            Assert.NotNull(childIfThenElse);
        }
예제 #5
0
        public void It_Should_Parse_Else()
        {
            // Act
            var ast = _generator.Generate("Result : {% if true %} OK {% elsif false %} NO {% elsif true %} YES {% else %} ELSE {% endif %}");

            // Assert
            var ifThenSymbolNode =
                LiquidASTGeneratorTests.FindNodesWithType(ast.LiquidAST, typeof(IfThenElseBlockTag)).FirstOrDefault();

            Assert.NotNull(ifThenSymbolNode);
            // ReSharper disable once PossibleNullReferenceException
            var elseSymbols = ((IfThenElseBlockTag)ifThenSymbolNode.Data).IfElseClauses;

            Logger.Log("-- AST --");
            Logger.Log(new ASTWalker().Walk(ast.LiquidAST));

            Assert.Equal(4, elseSymbols.Count); // the else symbol is an elsif set to "true".
        }
예제 #6
0
        public void It_Should_Parse_If_Var_Equals_String()
        {
            // Act
            var ast = _generator.Generate("Result : {% if myvar == \"hello\" %} OK {% endif %}");

            // Assert
            var ifThenSymbolNode =
                LiquidASTGeneratorTests.FindNodesWithType(ast.LiquidAST, typeof(IfThenElseBlockTag)).FirstOrDefault();

            Assert.NotNull(ifThenSymbolNode);
            // ReSharper disable once PossibleNullReferenceException
            var predicateTree = ((IfThenElseBlockTag)ifThenSymbolNode.Data).IfElseClauses[0].LiquidExpressionTree;

            Assert.IsType <EqualsExpression>(predicateTree.Data.Expression);
            Assert.IsType <VariableReferenceTree>(predicateTree[0].Data.Expression);
            Assert.IsType <LiquidString>(predicateTree[1].Data.Expression);
            //Assert.That(predicateTree[0].Data, Is.TypeOf<VariableReference>());
            //Assert.That(predicateTree[1].Data, Is.TypeOf<String>());
        }
예제 #7
0
        public void It_Should_Parse_ElsIf()
        {
            // Act
            var ast = _generator.Generate("Result : {% if true %} OK {% elsif false %} NO {% elsif true %} YES {% endif %}");

            // Assert
            var ifThenSymbolNode =
                LiquidASTGeneratorTests.FindNodesWithType(ast.LiquidAST, typeof(IfThenElseBlockTag)).FirstOrDefault();

            Assert.NotNull(ifThenSymbolNode);
            // ReSharper disable once PossibleNullReferenceException
            var elsIfPredicateTrees = ((IfThenElseBlockTag)ifThenSymbolNode.Data).IfElseClauses.Select(x => x.LiquidExpressionTree).ToList();

            foreach (var expr in ((IfThenElseBlockTag)ifThenSymbolNode.Data).IfElseClauses)
            {
                DebugIfExpressions(expr.LiquidExpressionTree);
            }
            Assert.Equal(3, elsIfPredicateTrees.Count);

            Assert.IsType <LiquidBoolean>(elsIfPredicateTrees[0].Data.Expression);
            Assert.IsType <LiquidBoolean>(elsIfPredicateTrees[1].Data.Expression);
        }
예제 #8
0
        public void It_Should_Add_A_String_Indexed_Array_Reference_In_An_Object()
        {
            // Act
            var ast = _generator.Generate("Result : {{ myvar[\"test\"] }}");

            // Assert
            var liquidExpressionNode = LiquidASTGeneratorTests.FindNodesWithType(ast.LiquidAST, typeof(LiquidExpressionTree)).FirstOrDefault();

            Assert.NotNull(liquidExpressionNode);
            // ReSharper disable once PossibleNullReferenceException
            Assert.NotNull(liquidExpressionNode.Data);
            var liquidExpression = ((LiquidExpressionTree)liquidExpressionNode.Data);

            // Assert
            Assert.NotNull(liquidExpression.ExpressionTree.Data.Expression);
            Assert.IsType <VariableReferenceTree>(liquidExpression.ExpressionTree.Data.Expression);
            VariableReferenceTree varRefTree = (VariableReferenceTree)liquidExpression.ExpressionTree.Data.Expression;

            Assert.IsType <VariableReferenceTree>(varRefTree.IndexExpression);
            VariableReferenceTree indexVarRefTree = (VariableReferenceTree)varRefTree.IndexExpression;

            Assert.IsType <LiquidString>(indexVarRefTree.Value);
        }
        public void It_Should_Add_An_Int_Indexed_Array_Reference_In_An_Object()
        {
            // Act
            var ast = _generator.Generate("Result : {{ myvar[3] }}");

            // Assert
            var liquidExpressionNode = LiquidASTGeneratorTests.FindNodesWithType(ast.LiquidAST, typeof(LiquidExpressionTree)).FirstOrDefault();

            Assert.That(liquidExpressionNode, Is.Not.Null);
            // ReSharper disable once PossibleNullReferenceException
            Assert.That(liquidExpressionNode.Data, Is.Not.Null);
            var liquidExpression = ((LiquidExpressionTree)liquidExpressionNode.Data);

            // Assert
            Assert.That(liquidExpression.ExpressionTree.Data.Expression, Is.Not.Null);
            Assert.That(liquidExpression.ExpressionTree.Data.Expression, Is.TypeOf <VariableReferenceTree>());
            VariableReferenceTree varRefTree = (VariableReferenceTree)liquidExpression.ExpressionTree.Data.Expression;

            Assert.That(varRefTree.IndexExpression, Is.TypeOf <VariableReferenceTree>());
            VariableReferenceTree indexVarRefTree = (VariableReferenceTree)varRefTree.IndexExpression;

            Assert.That(indexVarRefTree.Value, Is.AssignableTo <LiquidNumeric>());
            Assert.That(((LiquidNumeric)indexVarRefTree.Value).IntValue, Is.EqualTo(3));
        }