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