use of com.google.template.soy.soytree.TemplateNode in project closure-templates by google.
the class HtmlRewritePassTest method testSelfClosingTag.
@Test
public void testSelfClosingTag() {
TemplateNode node = runPass("<input/>");
assertThatSourceString(node).isEqualTo("<input/>");
// NOTE: the whitespace difference
node = runPass("<input />");
assertThatSourceString(node).isEqualTo("<input/>");
}
use of com.google.template.soy.soytree.TemplateNode in project closure-templates by google.
the class HtmlRewritePassTest method testAttributes.
@Test
public void testAttributes() {
TemplateNode node = runPass("<div class=\"foo\"></div>");
assertThatSourceString(node).isEqualTo("<div class=\"foo\"></div>");
String structure = "" + "HTML_OPEN_TAG_NODE\n" + " RAW_TEXT_NODE\n" + " HTML_ATTRIBUTE_NODE\n" + " RAW_TEXT_NODE\n" + " HTML_ATTRIBUTE_VALUE_NODE\n" + " RAW_TEXT_NODE\n" + "HTML_CLOSE_TAG_NODE\n" + " RAW_TEXT_NODE\n" + "";
assertThatASTString(node).isEqualTo(structure);
// test alternate quotation marks
node = runPass("<div class='foo'></div>");
assertThatSourceString(node).isEqualTo("<div class='foo'></div>");
assertThatASTString(node).isEqualTo(structure);
node = runPass("<div class=foo></div>");
assertThatSourceString(node).isEqualTo("<div class=foo></div>");
assertThatASTString(node).isEqualTo(structure);
// This is a tricky case, according to the spec the '/' belongs to the attribute, not the tag
node = runPass("<input class=foo/>");
assertThatSourceString(node).isEqualTo("<input class=foo/>");
HtmlOpenTagNode openTag = (HtmlOpenTagNode) node.getChild(0);
assertThat(openTag.isSelfClosing()).isFalse();
HtmlAttributeValueNode attributeValue = (HtmlAttributeValueNode) ((HtmlAttributeNode) openTag.getChild(1)).getChild(1);
assertThat(attributeValue.getQuotes()).isEqualTo(HtmlAttributeValueNode.Quotes.NONE);
assertThat(((RawTextNode) attributeValue.getChild(0)).getRawText()).isEqualTo("foo/");
}
use of com.google.template.soy.soytree.TemplateNode in project closure-templates by google.
the class HtmlRewritePassTest method testHtmlCommentWithControlFlow.
@Test
public void testHtmlCommentWithControlFlow() {
ErrorReporter errorReporter = ErrorReporter.createForTest();
TemplateNode node;
// Control flow structure should be preserved.
node = runPass("<!-- {if $foo} foo {else} bar {/if} -->", errorReporter);
assertThatASTString(node).isEqualTo(Joiner.on('\n').join("HTML_COMMENT_NODE", " RAW_TEXT_NODE", " IF_NODE", " IF_COND_NODE", " RAW_TEXT_NODE", " IF_ELSE_NODE", " RAW_TEXT_NODE", " RAW_TEXT_NODE", ""));
assertThatSourceString(node).isEqualTo("<!-- {if $foo} foo {else} bar {/if} -->");
}
use of com.google.template.soy.soytree.TemplateNode in project closure-templates by google.
the class HtmlRewritePassTest method testUnquotedAttributeValue.
@Test
public void testUnquotedAttributeValue() {
TemplateNode node = runPass("<img class=foo />");
assertThat(((HtmlOpenTagNode) node.getChild(0)).isSelfClosing()).isTrue();
node = runPass("<img class=foo/>");
assertThat(((HtmlOpenTagNode) node.getChild(0)).isSelfClosing()).isFalse();
node = runPass("<img class/>");
assertThat(((HtmlOpenTagNode) node.getChild(0)).isSelfClosing()).isTrue();
}
use of com.google.template.soy.soytree.TemplateNode in project closure-templates by google.
the class HtmlRewritePassTest method testConditionalAttributeValue.
@Test
public void testConditionalAttributeValue() {
TemplateNode node = runPass("{let $t : 'x' /}<div class=\"{if $t}foo{else}bar{/if}\">content</div>");
assertThatSourceString(node).isEqualTo("{let $t : 'x' /}<div class=\"{if $t}foo{else}bar{/if}\">content</div>");
assertThatASTString(node).isEqualTo("" + "LET_VALUE_NODE\n" + "HTML_OPEN_TAG_NODE\n" + " RAW_TEXT_NODE\n" + " HTML_ATTRIBUTE_NODE\n" + " RAW_TEXT_NODE\n" + " HTML_ATTRIBUTE_VALUE_NODE\n" + " IF_NODE\n" + " IF_COND_NODE\n" + " RAW_TEXT_NODE\n" + " IF_ELSE_NODE\n" + " RAW_TEXT_NODE\n" + "RAW_TEXT_NODE\n" + "HTML_CLOSE_TAG_NODE\n" + " RAW_TEXT_NODE\n" + "");
}
Aggregations