Search in sources :

Example 16 with StringNode

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

the class ParseExpressionTest method testParseProtoInitCall.

@Test
public void testParseProtoInitCall() throws Exception {
    ExprNode expr = assertThatExpression("my.Proto(a: 1, b: glo.bal, c: fn('str'))").isValidExpression();
    ProtoInitNode protoFn = (ProtoInitNode) expr;
    assertThat(protoFn.getProtoName()).isEqualTo("my.Proto");
    assertThat(protoFn.getParamNames()).containsExactly("a", "b", "c").inOrder();
    assertThat(protoFn.numChildren()).isEqualTo(3);
    assertThat(((IntegerNode) protoFn.getChild(0)).getValue()).isEqualTo(1);
    assertThat(((GlobalNode) protoFn.getChild(1)).getName()).isEqualTo("glo.bal");
    assertThat(((StringNode) ((FunctionNode) protoFn.getChild(2)).getChild(0)).getValue()).isEqualTo("str");
}
Also used : ExprNode(com.google.template.soy.exprtree.ExprNode) IntegerNode(com.google.template.soy.exprtree.IntegerNode) ProtoInitNode(com.google.template.soy.exprtree.ProtoInitNode) StringNode(com.google.template.soy.exprtree.StringNode) GlobalNode(com.google.template.soy.exprtree.GlobalNode) Test(org.junit.Test)

Example 17 with StringNode

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

the class TemplateNodeTest method testValidVariant.

@Test
public void testValidVariant() {
    // Variant is a string literal: There's no expression and the value is already resolved.
    TemplateDelegateNode node = (TemplateDelegateNode) parse(join("{namespace ns}", "{deltemplate namespace.boo variant=\"'abc'\"}", "{/deltemplate}"));
    assertEquals("namespace.boo", node.getDelTemplateName());
    assertEquals("abc", node.getDelTemplateVariant());
    assertEquals("abc", node.getDelTemplateKey().variant());
    // Variant is a global, that was not yet resolved.
    node = (TemplateDelegateNode) parse(join("{namespace ns}", "{deltemplate namespace.boo variant=\"test.GLOBAL_CONSTANT\"}", "{/deltemplate}"));
    assertEquals("namespace.boo", node.getDelTemplateName());
    assertEquals("test.GLOBAL_CONSTANT", node.getDelTemplateVariant());
    assertEquals("test.GLOBAL_CONSTANT", node.getDelTemplateKey().variant());
    // Verify the global expression.
    List<ExprRootNode> exprs = node.getExprList();
    assertEquals(1, exprs.size());
    ExprRootNode expr = exprs.get(0);
    assertEquals("test.GLOBAL_CONSTANT", expr.toSourceString());
    assertEquals(1, expr.numChildren());
    assertTrue(expr.getRoot() instanceof GlobalNode);
    // Substitute the global expression.
    expr.replaceChild(0, new IntegerNode(123, expr.getRoot().getSourceLocation()));
    // Check the new values.
    assertEquals("123", node.getDelTemplateVariant());
    assertEquals("123", node.getDelTemplateKey().variant());
    // Resolve a global to a string.
    node = (TemplateDelegateNode) parse(join("{namespace ns}", "{deltemplate namespace.boo variant=\"test.GLOBAL_CONSTANT\"}", "{/deltemplate}"));
    node.getExprList().get(0).replaceChild(0, new StringNode("variant", QuoteStyle.SINGLE, node.getSourceLocation()));
    assertEquals("variant", node.getDelTemplateVariant());
    assertEquals("variant", node.getDelTemplateKey().variant());
}
Also used : IntegerNode(com.google.template.soy.exprtree.IntegerNode) StringNode(com.google.template.soy.exprtree.StringNode) GlobalNode(com.google.template.soy.exprtree.GlobalNode) ExprRootNode(com.google.template.soy.exprtree.ExprRootNode) Test(org.junit.Test)

Example 18 with StringNode

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

the class ResolvePackageRelativeCssNamesVisitorTest method testBaseCssOnNamespace.

@Test
public void testBaseCssOnNamespace() {
    TemplateNode template = compileTemplate("{namespace boo cssbase=\"some.test.package\"}\n\n" + "/** Test template.*/\n" + "{template .foo}\n" + "  <p class=\"{css('%AAA')}\">\n" + "{/template}\n");
    PrintNode printNode = Iterables.getOnlyElement(SoyTreeUtils.getAllNodesOfType(template, PrintNode.class));
    FunctionNode cssFn = (FunctionNode) printNode.getExpr().getRoot();
    assertThat(((StringNode) cssFn.getChild(0)).getValue()).isEqualTo("someTestPackageAAA");
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode) FunctionNode(com.google.template.soy.exprtree.FunctionNode) StringNode(com.google.template.soy.exprtree.StringNode) PrintNode(com.google.template.soy.soytree.PrintNode) Test(org.junit.Test)

Example 19 with StringNode

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

the class ResolvePackageRelativeCssNamesVisitorTest method testBaseCssOnTemplate.

@Test
public void testBaseCssOnTemplate() {
    TemplateNode template = compileTemplate("{namespace boo}\n\n" + "/** Test template.  */\n" + "{template .foo cssbase=\"some.test.package\"}\n" + "  <p class=\"{css('%AAA')}\">\n" + "{/template}\n");
    PrintNode printNode = Iterables.getOnlyElement(SoyTreeUtils.getAllNodesOfType(template, PrintNode.class));
    FunctionNode cssFn = (FunctionNode) printNode.getExpr().getRoot();
    assertThat(((StringNode) cssFn.getChild(0)).getValue()).isEqualTo("someTestPackageAAA");
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode) FunctionNode(com.google.template.soy.exprtree.FunctionNode) StringNode(com.google.template.soy.exprtree.StringNode) PrintNode(com.google.template.soy.soytree.PrintNode) Test(org.junit.Test)

Example 20 with StringNode

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

the class ResolvePackageRelativeCssNamesVisitorTest method testUnprefixedNode.

@Test
public void testUnprefixedNode() {
    TemplateNode template = compileTemplate("{namespace boo cssbase=\"some.test.package\"}\n\n" + "/** Test template. */\n" + "{template .foo}\n" + "  <p class=\"{css('AAA')}\">\n" + "{/template}\n");
    PrintNode printNode = Iterables.getOnlyElement(SoyTreeUtils.getAllNodesOfType(template, PrintNode.class));
    FunctionNode cssFn = (FunctionNode) printNode.getExpr().getRoot();
    assertThat(((StringNode) cssFn.getChild(0)).getValue()).isEqualTo("AAA");
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode) FunctionNode(com.google.template.soy.exprtree.FunctionNode) StringNode(com.google.template.soy.exprtree.StringNode) PrintNode(com.google.template.soy.soytree.PrintNode) Test(org.junit.Test)

Aggregations

StringNode (com.google.template.soy.exprtree.StringNode)20 Test (org.junit.Test)9 ExprNode (com.google.template.soy.exprtree.ExprNode)7 FunctionNode (com.google.template.soy.exprtree.FunctionNode)7 IntegerNode (com.google.template.soy.exprtree.IntegerNode)6 PrintNode (com.google.template.soy.soytree.PrintNode)6 GlobalNode (com.google.template.soy.exprtree.GlobalNode)4 TemplateNode (com.google.template.soy.soytree.TemplateNode)4 BooleanNode (com.google.template.soy.exprtree.BooleanNode)2 ExprRootNode (com.google.template.soy.exprtree.ExprRootNode)2 FloatNode (com.google.template.soy.exprtree.FloatNode)2 VarRefNode (com.google.template.soy.exprtree.VarRefNode)2 CodeChunk (com.google.template.soy.jssrc.dsl.CodeChunk)2 StandaloneNode (com.google.template.soy.soytree.SoyNode.StandaloneNode)2 ImmutableList (com.google.common.collect.ImmutableList)1 SourceLocation (com.google.template.soy.base.SourceLocation)1 NullData (com.google.template.soy.data.restricted.NullData)1 PrimitiveNode (com.google.template.soy.exprtree.ExprNode.PrimitiveNode)1 FieldAccessNode (com.google.template.soy.exprtree.FieldAccessNode)1 ListLiteralNode (com.google.template.soy.exprtree.ListLiteralNode)1