Search in sources :

Example 21 with TemplateNode

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

the class HtmlRewritePassTest method testTags.

@Test
public void testTags() {
    TemplateNode node = runPass("<div></div>");
    assertThat(node.getChild(0)).isInstanceOf(HtmlOpenTagNode.class);
    assertThat(node.getChild(1)).isInstanceOf(HtmlCloseTagNode.class);
    assertThatSourceString(node).isEqualTo("<div></div>");
    assertThatASTString(node).isEqualTo("HTML_OPEN_TAG_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 22 with TemplateNode

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

the class HtmlRewritePassTest method testLetAttributes.

@Test
public void testLetAttributes() {
    TemplateNode node = runPass("{let $foo kind=\"attributes\"}class='foo'{/let}");
    assertThatSourceString(node).isEqualTo("{let $foo kind=\"attributes\"}class='foo'{/let}");
    String structure = "" + "LET_CONTENT_NODE\n" + "  HTML_ATTRIBUTE_NODE\n" + "    RAW_TEXT_NODE\n" + "    HTML_ATTRIBUTE_VALUE_NODE\n" + "      RAW_TEXT_NODE\n";
    assertThatASTString(node).isEqualTo(structure);
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode) Test(org.junit.Test)

Example 23 with TemplateNode

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

the class HtmlRewritePassTest method testTextNodes.

@Test
public void testTextNodes() {
    TemplateNode node = runPass("x x<div>content</div> <div>{sp}</div>");
    assertThatSourceString(node).isEqualTo("x x<div>content</div> <div> </div>");
    assertThatASTString(node).isEqualTo("" + "RAW_TEXT_NODE\n" + "HTML_OPEN_TAG_NODE\n" + "  RAW_TEXT_NODE\n" + "RAW_TEXT_NODE\n" + "HTML_CLOSE_TAG_NODE\n" + "  RAW_TEXT_NODE\n" + "RAW_TEXT_NODE\n" + "HTML_OPEN_TAG_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 24 with TemplateNode

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

the class HtmlRewritePassTest method testConditionalContextMerging.

// TODO(lukes): ideally these would all be implemented in the CompilerIntegrationTests but the
// ContextualAutoescaper rejects these forms.  once we stop 'desuraging' prior to the autoescaper
// we can move these tests over.
@Test
public void testConditionalContextMerging() {
    TemplateNode node = runPass("{@param p : ?}<div {if $p}foo=bar{else}baz{/if}>");
    assertThatSourceString(node).isEqualTo("<div{if $p} foo=bar{else} baz{/if}>");
    assertThatASTString(node).isEqualTo("" + "HTML_OPEN_TAG_NODE\n" + "  RAW_TEXT_NODE\n" + "  IF_NODE\n" + "    IF_COND_NODE\n" + "      HTML_ATTRIBUTE_NODE\n" + "        RAW_TEXT_NODE\n" + "        HTML_ATTRIBUTE_VALUE_NODE\n" + "          RAW_TEXT_NODE\n" + "    IF_ELSE_NODE\n" + "      HTML_ATTRIBUTE_NODE\n" + "        RAW_TEXT_NODE\n" + "");
    node = runPass("{@param p : ?}<div {if $p}class=x{else}style=\"baz\"{/if}>");
    assertThatSourceString(node).isEqualTo("<div{if $p} class=x{else} style=\"baz\"{/if}>");
    node = runPass("{@param p : ?}<div {if $p}class='x'{else}style=\"baz\"{/if}>");
    assertThatSourceString(node).isEqualTo("<div{if $p} class='x'{else} style=\"baz\"{/if}>");
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode) Test(org.junit.Test)

Example 25 with TemplateNode

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

the class HtmlRewritePassTest method testConditionalQuotedAttributeValues.

// Ideally, we wouldn't support this pattern since it adds a fair bit of complexity
@Test
public void testConditionalQuotedAttributeValues() {
    TemplateNode node = runPass("{@param p : ?}<div x={if $p}'foo'{else}'bar'{/if} {$p}>");
    assertThatSourceString(node).isEqualTo("<div x={if $p}'foo'{else}'bar'{/if} {$p}>");
    assertThatASTString(node).isEqualTo("" + "HTML_OPEN_TAG_NODE\n" + "  RAW_TEXT_NODE\n" + "  HTML_ATTRIBUTE_NODE\n" + "    RAW_TEXT_NODE\n" + "    IF_NODE\n" + "      IF_COND_NODE\n" + "        HTML_ATTRIBUTE_VALUE_NODE\n" + "          RAW_TEXT_NODE\n" + "      IF_ELSE_NODE\n" + "        HTML_ATTRIBUTE_VALUE_NODE\n" + "          RAW_TEXT_NODE\n" + "  HTML_ATTRIBUTE_NODE\n" + "    PRINT_NODE\n" + "");
    node = runPass("{@param p : ?}{@param p2 : ?}<div x={if $p}{if $p2}'foo'{else}'bar'{/if}" + "{else}{if $p2}'foo'{else}'bar'{/if}{/if} {$p}>");
    assertThatSourceString(node).isEqualTo("<div x={if $p}{if $p2}'foo'{else}'bar'{/if}{else}{if $p2}'foo'{else}'bar'{/if}{/if}" + " {$p}>");
    assertThatASTString(node).isEqualTo("" + "HTML_OPEN_TAG_NODE\n" + "  RAW_TEXT_NODE\n" + "  HTML_ATTRIBUTE_NODE\n" + "    RAW_TEXT_NODE\n" + "    IF_NODE\n" + "      IF_COND_NODE\n" + "        IF_NODE\n" + "          IF_COND_NODE\n" + "            HTML_ATTRIBUTE_VALUE_NODE\n" + "              RAW_TEXT_NODE\n" + "          IF_ELSE_NODE\n" + "            HTML_ATTRIBUTE_VALUE_NODE\n" + "              RAW_TEXT_NODE\n" + "      IF_ELSE_NODE\n" + "        IF_NODE\n" + "          IF_COND_NODE\n" + "            HTML_ATTRIBUTE_VALUE_NODE\n" + "              RAW_TEXT_NODE\n" + "          IF_ELSE_NODE\n" + "            HTML_ATTRIBUTE_VALUE_NODE\n" + "              RAW_TEXT_NODE\n" + "  HTML_ATTRIBUTE_NODE\n" + "    PRINT_NODE\n" + "");
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode) 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