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