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");
}
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());
}
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");
}
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");
}
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");
}
Aggregations