use of com.google.template.soy.exprtree.VarRefNode 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.exprtree.VarRefNode 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);
}
Aggregations