Search in sources :

Example 71 with TemplateNode

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}>");
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode) Test(org.junit.Test)

Example 72 with TemplateNode

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" + "");
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode) Test(org.junit.Test)

Example 73 with TemplateNode

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());
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode) LetValueNode(com.google.template.soy.soytree.LetValueNode) VarRefNode(com.google.template.soy.exprtree.VarRefNode) SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) Test(org.junit.Test)

Example 74 with TemplateNode

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);
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode) VarRefNode(com.google.template.soy.exprtree.VarRefNode) SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) Test(org.junit.Test)

Example 75 with TemplateNode

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);
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode) LetValueNode(com.google.template.soy.soytree.LetValueNode) SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) IfNode(com.google.template.soy.soytree.IfNode) LetContentNode(com.google.template.soy.soytree.LetContentNode) 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