Search in sources :

Example 76 with TemplateNode

use of com.google.template.soy.soytree.TemplateNode in project closure-templates by google.

the class ResolveNamesVisitorTest method testLetNameLookupSuccess.

@Test
public void testLetNameLookupSuccess() {
    SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(constructTemplateSource("{let $pa: 1 /}", "{$pa}")).parse().fileSet();
    new ResolveNamesVisitor(ErrorReporter.exploding()).exec(soyTree);
    TemplateNode n = soyTree.getChild(0).getChild(0);
    assertThat(n.getMaxLocalVariableTableSize()).isEqualTo(1);
    assertThat(((LetValueNode) n.getChild(0)).getVar().localVariableIndex()).isEqualTo(0);
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode) SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) Test(org.junit.Test)

Example 77 with TemplateNode

use of com.google.template.soy.soytree.TemplateNode 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 78 with TemplateNode

use of com.google.template.soy.soytree.TemplateNode 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 79 with TemplateNode

use of com.google.template.soy.soytree.TemplateNode 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)

Example 80 with TemplateNode

use of com.google.template.soy.soytree.TemplateNode in project closure-templates by google.

the class ContextualAutoescaperTest method testStrictModeEscapesCallSites.

@Test
public void testStrictModeEscapesCallSites() {
    String source = "{namespace ns}\n\n" + "{template .main}\n" + "{call .htmltemplate /}" + "<script>var x={call .htmltemplate /};</script>\n" + "<script>var x={call .jstemplate /};</script>\n" + "{call .externtemplate /}" + "\n{/template}\n\n" + "{template .htmltemplate}\n" + "Hello World" + "\n{/template}\n\n" + "{template .jstemplate kind=\"js\"}\n" + "foo()" + "\n{/template}";
    TemplateNode mainTemplate = rewrite(source).getChild(0);
    assertWithMessage("Sanity check").that(mainTemplate.getTemplateName()).isEqualTo("ns.main");
    final List<CallNode> callNodes = SoyTreeUtils.getAllNodesOfType(mainTemplate, CallNode.class);
    assertThat(callNodes).hasSize(4);
    assertWithMessage("HTML->HTML escaping should be pruned").that(callNodes.get(0).getEscapingDirectives()).isEmpty();
    assertWithMessage("JS -> HTML call should be escaped").that(getDirectiveNames(callNodes.get(1).getEscapingDirectives())).containsExactly("|escapeJsValue");
    assertWithMessage("JS -> JS pruned").that(callNodes.get(2).getEscapingDirectives()).isEmpty();
    assertWithMessage("HTML -> extern call should be escaped").that(getDirectiveNames(callNodes.get(3).getEscapingDirectives())).containsExactly("|escapeHtml");
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode) CallNode(com.google.template.soy.soytree.CallNode) Test(org.junit.Test)

Aggregations

TemplateNode (com.google.template.soy.soytree.TemplateNode)89 Test (org.junit.Test)59 SoyFileSetNode (com.google.template.soy.soytree.SoyFileSetNode)35 TemplateRegistry (com.google.template.soy.soytree.TemplateRegistry)19 ErrorReporter (com.google.template.soy.error.ErrorReporter)11 ParseResult (com.google.template.soy.SoyFileSetParser.ParseResult)10 TransitiveDepTemplatesInfo (com.google.template.soy.passes.FindTransitiveDepTemplatesVisitor.TransitiveDepTemplatesInfo)9 RawTextNode (com.google.template.soy.soytree.RawTextNode)9 SoyFileNode (com.google.template.soy.soytree.SoyFileNode)8 TemplateParam (com.google.template.soy.soytree.defn.TemplateParam)7 FunctionNode (com.google.template.soy.exprtree.FunctionNode)6 PrintNode (com.google.template.soy.soytree.PrintNode)5 TemplateDelegateNode (com.google.template.soy.soytree.TemplateDelegateNode)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 SourceLocation (com.google.template.soy.base.SourceLocation)4 StringNode (com.google.template.soy.exprtree.StringNode)4 MsgFallbackGroupNode (com.google.template.soy.soytree.MsgFallbackGroupNode)4 ImmutableList (com.google.common.collect.ImmutableList)3 VarRefNode (com.google.template.soy.exprtree.VarRefNode)3 SoyMsgBundle (com.google.template.soy.msgs.SoyMsgBundle)3