use of com.google.template.soy.soytree.TemplateNode in project closure-templates by google.
the class HtmlRewritePassTest method testConditionalUnquotedAttributeValue.
@Test
public void testConditionalUnquotedAttributeValue() {
TemplateNode node = runPass("{@param p : ?}<div class={if $p}x{else}y{/if}>");
assertThatSourceString(node).isEqualTo("<div class={if $p}x{else}y{/if}>");
}
use of com.google.template.soy.soytree.TemplateNode in project closure-templates by google.
the class HtmlRewritePassTest method testConditionalAttribute.
@Test
public void testConditionalAttribute() {
TemplateNode node = runPass("{let $t : 'x' /}<div {if $t}foo{else}bar{/if}>content</div>");
assertThatSourceString(node).isEqualTo("{let $t : 'x' /}<div{if $t} foo{else} bar{/if}>content</div>");
assertThatASTString(node).isEqualTo("" + "LET_VALUE_NODE\n" + "HTML_OPEN_TAG_NODE\n" + " RAW_TEXT_NODE\n" + " IF_NODE\n" + " IF_COND_NODE\n" + " HTML_ATTRIBUTE_NODE\n" + " RAW_TEXT_NODE\n" + " IF_ELSE_NODE\n" + " HTML_ATTRIBUTE_NODE\n" + " RAW_TEXT_NODE\n" + "RAW_TEXT_NODE\n" + "HTML_CLOSE_TAG_NODE\n" + " RAW_TEXT_NODE\n" + "");
}
use of com.google.template.soy.soytree.TemplateNode in project closure-templates by google.
the class ResolveNamesVisitorTest method testMultipleLocals.
@Test
public void testMultipleLocals() {
SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(constructTemplateSource("{let $la: 1 /}", "{let $lb: $la /}", "{let $lc: $lb /}")).parse().fileSet();
new ResolveNamesVisitor(ErrorReporter.exploding()).exec(soyTree);
TemplateNode n = soyTree.getChild(0).getChild(0);
// 3 because each new $la binding is a 'new variable'
assertThat(n.getMaxLocalVariableTableSize()).isEqualTo(3);
LetValueNode firstLet = (LetValueNode) n.getChild(0);
LetValueNode secondLet = (LetValueNode) n.getChild(1);
LetValueNode thirdLet = (LetValueNode) n.getChild(2);
assertThat(firstLet.getVar().localVariableIndex()).isEqualTo(0);
assertThat(secondLet.getVar().localVariableIndex()).isEqualTo(1);
assertThat(thirdLet.getVar().localVariableIndex()).isEqualTo(2);
assertThat(((VarRefNode) secondLet.getExpr().getRoot()).getDefnDecl()).isEqualTo(firstLet.getVar());
assertThat(((VarRefNode) thirdLet.getExpr().getRoot()).getDefnDecl()).isEqualTo(secondLet.getVar());
}
use of com.google.template.soy.soytree.TemplateNode in project closure-templates by google.
the class ResolveNamesVisitorTest method testLetReferencedInsideAttributeValue.
@Test
public void testLetReferencedInsideAttributeValue() {
SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(constructTemplateSource("{let $t: 1 /}<{$t}>")).parse().fileSet();
TemplateNode n = soyTree.getChild(0).getChild(0);
VarRefNode node = Iterables.getOnlyElement(SoyTreeUtils.getAllNodesOfType(n, VarRefNode.class));
assertThat(node.getDefnDecl().kind()).isEqualTo(VarDefn.Kind.LOCAL_VAR);
}
use of com.google.template.soy.soytree.TemplateNode in project closure-templates by google.
the class ResolveNamesVisitorTest method testLetContentSlotLifetime.
@Test
public void testLetContentSlotLifetime() {
SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(constructTemplateSource("{let $a kind=\"text\"}", // introduce an extra scope
" {if true}", " {let $b: 2 /}", " {$b}", " {/if}", "{/let}", "{$a}")).parse().fileSet();
new ResolveNamesVisitor(ErrorReporter.exploding()).exec(soyTree);
TemplateNode n = soyTree.getChild(0).getChild(0);
// 1 because each new $la binding overwrites the prior one
assertThat(n.getMaxLocalVariableTableSize()).isEqualTo(2);
LetContentNode aLetNode = (LetContentNode) n.getChild(0);
assertThat(aLetNode.getVar().localVariableIndex()).isEqualTo(1);
LetValueNode bLetNode = (LetValueNode) ((IfCondNode) ((IfNode) aLetNode.getChild(0)).getChild(0)).getChild(0);
assertThat(bLetNode.getVar().localVariableIndex()).isEqualTo(0);
}
Aggregations