Search in sources :

Example 1 with GreaterThanOpNode

use of com.google.template.soy.exprtree.OperatorNodes.GreaterThanOpNode in project closure-templates by google.

the class TemplateParserTest method testParseIfStmt.

@Test
public void testParseIfStmt() throws Exception {
    String templateBody = "{@param zoo : ?}{@param boo: ?}{@param foo : ?}{@param moo : ?}\n" + "  {if $zoo}{$zoo}{/if}\n" + "  {if $boo}\n" + "    Blah\n" + "  {elseif $foo.goo > 2}\n" + "    {$moo}\n" + "  {else}\n" + "    Blah {$moo}\n" + "  {/if}\n";
    List<StandaloneNode> nodes = parseTemplateContent(templateBody, FAIL).getChildren();
    assertEquals(2, nodes.size());
    IfNode in0 = (IfNode) nodes.get(0);
    assertEquals(1, in0.numChildren());
    IfCondNode in0icn0 = (IfCondNode) in0.getChild(0);
    assertEquals("$zoo", in0icn0.getExpr().toSourceString());
    assertEquals(1, in0icn0.numChildren());
    assertEquals("$zoo", ((PrintNode) in0icn0.getChild(0)).getExpr().toSourceString());
    assertTrue(in0icn0.getExpr().getRoot() instanceof VarRefNode);
    IfNode in1 = (IfNode) nodes.get(1);
    assertEquals(3, in1.numChildren());
    IfCondNode in1icn0 = (IfCondNode) in1.getChild(0);
    assertEquals("$boo", in1icn0.getExpr().toSourceString());
    assertTrue(in1icn0.getExpr().getRoot() instanceof VarRefNode);
    IfCondNode in1icn1 = (IfCondNode) in1.getChild(1);
    assertEquals("$foo.goo > 2", in1icn1.getExpr().toSourceString());
    assertTrue(in1icn1.getExpr().getRoot() instanceof GreaterThanOpNode);
    assertEquals("{if $boo}Blah{elseif $foo.goo > 2}{$moo}{else}Blah {$moo}{/if}", in1.toSourceString());
}
Also used : StandaloneNode(com.google.template.soy.soytree.SoyNode.StandaloneNode) IfCondNode(com.google.template.soy.soytree.IfCondNode) GreaterThanOpNode(com.google.template.soy.exprtree.OperatorNodes.GreaterThanOpNode) VarRefNode(com.google.template.soy.exprtree.VarRefNode) IfNode(com.google.template.soy.soytree.IfNode) PrintNode(com.google.template.soy.soytree.PrintNode) Test(org.junit.Test)

Aggregations

GreaterThanOpNode (com.google.template.soy.exprtree.OperatorNodes.GreaterThanOpNode)1 VarRefNode (com.google.template.soy.exprtree.VarRefNode)1 IfCondNode (com.google.template.soy.soytree.IfCondNode)1 IfNode (com.google.template.soy.soytree.IfNode)1 PrintNode (com.google.template.soy.soytree.PrintNode)1 StandaloneNode (com.google.template.soy.soytree.SoyNode.StandaloneNode)1 Test (org.junit.Test)1