Search in sources :

Example 1 with PlusOpNode

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

the class ExprEquivalenceTest method testSubExpressions.

@Test
public void testSubExpressions() {
    PlusOpNode node = (PlusOpNode) parse("$foo.a.b + $foo.a.b");
    assertEquivalent(node.getChild(0), node.getChild(1));
    assertNotEquivalent(node, node.getChild(0));
    assertNotEquivalent(node, node.getChild(1));
}
Also used : PlusOpNode(com.google.template.soy.exprtree.OperatorNodes.PlusOpNode) Test(org.junit.Test)

Example 2 with PlusOpNode

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

the class TemplateParserTest method testParsePrintStmt.

@Test
public void testParsePrintStmt() throws Exception {
    String templateBody = "{@param boo : ?}{@param goo : ?}\n" + "  {$boo.foo}{$boo.foo}\n" + "  {$goo + 1 |noAutoescape}\n" + "  {print 'blah    blahblahblah' |escapeHtml|insertWordBreaks:8}\n";
    List<StandaloneNode> nodes = parseTemplateContent(templateBody, FAIL).getChildren();
    assertEquals(4, nodes.size());
    PrintNode pn0 = (PrintNode) nodes.get(0);
    assertEquals("$boo.foo", pn0.getExpr().toSourceString());
    assertEquals(0, pn0.getChildren().size());
    assertEquals("FOO", pn0.genBasePhName());
    assertEquals("{$boo.foo}", pn0.toSourceString());
    assertTrue(pn0.getExpr().getRoot() instanceof FieldAccessNode);
    PrintNode pn1 = (PrintNode) nodes.get(1);
    assertTrue(pn0.genSamenessKey().equals(pn1.genSamenessKey()));
    assertTrue(pn1.getExpr().getRoot() instanceof FieldAccessNode);
    PrintNode pn2 = (PrintNode) nodes.get(2);
    assertEquals("$goo + 1", pn2.getExpr().toSourceString());
    assertEquals(1, pn2.getChildren().size());
    PrintDirectiveNode pn2d0 = pn2.getChild(0);
    assertEquals("|noAutoescape", pn2d0.getName());
    assertEquals("XXX", pn2.genBasePhName());
    assertTrue(pn2.getExpr().getRoot() instanceof PlusOpNode);
    PrintNode pn3 = (PrintNode) nodes.get(3);
    assertEquals("'blah    blahblahblah'", pn3.getExpr().toSourceString());
    assertEquals(2, pn3.getChildren().size());
    PrintDirectiveNode pn3d0 = pn3.getChild(0);
    assertEquals("|escapeHtml", pn3d0.getName());
    PrintDirectiveNode pn3d1 = pn3.getChild(1);
    assertEquals("|insertWordBreaks", pn3d1.getName());
    assertEquals(8, ((IntegerNode) pn3d1.getArgs().get(0).getRoot()).getValue());
    assertEquals("XXX", pn3.genBasePhName());
    assertTrue(pn3.getExpr().getRoot() instanceof StringNode);
    assertFalse(pn0.genSamenessKey().equals(pn2.genSamenessKey()));
    assertFalse(pn3.genSamenessKey().equals(pn0.genSamenessKey()));
}
Also used : StandaloneNode(com.google.template.soy.soytree.SoyNode.StandaloneNode) PrintDirectiveNode(com.google.template.soy.soytree.PrintDirectiveNode) StringNode(com.google.template.soy.exprtree.StringNode) PlusOpNode(com.google.template.soy.exprtree.OperatorNodes.PlusOpNode) PrintNode(com.google.template.soy.soytree.PrintNode) FieldAccessNode(com.google.template.soy.exprtree.FieldAccessNode) Test(org.junit.Test)

Aggregations

PlusOpNode (com.google.template.soy.exprtree.OperatorNodes.PlusOpNode)2 Test (org.junit.Test)2 FieldAccessNode (com.google.template.soy.exprtree.FieldAccessNode)1 StringNode (com.google.template.soy.exprtree.StringNode)1 PrintDirectiveNode (com.google.template.soy.soytree.PrintDirectiveNode)1 PrintNode (com.google.template.soy.soytree.PrintNode)1 StandaloneNode (com.google.template.soy.soytree.SoyNode.StandaloneNode)1