Search in sources :

Example 26 with TemplateNode

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

Example 27 with TemplateNode

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

Example 28 with TemplateNode

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

Example 29 with TemplateNode

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

Example 30 with TemplateNode

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