Search in sources :

Example 41 with TemplateNode

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

the class ClearSoyDocStringsVisitorTest method testClearSoyDocStrings.

@Test
public void testClearSoyDocStrings() {
    String testFileContent = "{namespace boo}\n" + "\n" + "/**\n" + " * blah blah blah\n" + " *\n" + " * @param goo blah blah\n" + " */\n" + "{template .foo}\n" + "  {$goo}\n" + "{/template}\n";
    ErrorReporter boom = ErrorReporter.exploding();
    SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(testFileContent).errorReporter(boom).parse().fileSet();
    TemplateNode template = (TemplateNode) SharedTestUtils.getNode(soyTree);
    assertThat(template.getSoyDoc()).contains("blah");
    assertThat(template.getSoyDocDesc()).contains("blah");
    assertThat(template.getParams().get(0).desc()).contains("blah");
    new ClearSoyDocStringsVisitor().exec(soyTree);
    assertThat(template.getSoyDoc()).isNull();
    assertThat(template.getSoyDocDesc()).isNull();
    assertThat(template.getParams().get(0).desc()).isNull();
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode) ErrorReporter(com.google.template.soy.error.ErrorReporter) SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) Test(org.junit.Test)

Example 42 with TemplateNode

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

the class FindIjParamsVisitorTest method testTwoPathsToSameTemplate.

@Test
public void testTwoPathsToSameTemplate() {
    // aaa -> {bbb, ccc}, ccc -> bbb.
    String fileContent = "" + "{namespace ns}\n" + "\n" + "/***/\n" + "{template .aaa}\n" + "  {call .bbb /} {$ij.boo} {call .ccc /} {$ij.foo}\n" + "{/template}\n" + "\n" + "/***/\n" + "{template .bbb}\n" + "  {$ij.boo} {$ij.goo}\n" + "{/template}\n" + "\n" + "/***/\n" + "{template .ccc}\n" + "  {$ij.boo} {$ij.moo + $ij.woo} {call .bbb /}\n" + "{/template}\n";
    SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(fileContent).parse().fileSet();
    TemplateRegistry templateRegistry = new TemplateRegistry(soyTree, FAIL);
    TemplateNode aaa = soyTree.getChild(0).getChild(0);
    TemplateNode bbb = soyTree.getChild(0).getChild(1);
    TemplateNode ccc = soyTree.getChild(0).getChild(2);
    // Test with exec(aaa).
    // Exercises: processCalleeHelper case 4 with incorporateCalleeVisitInfo case 1 (ccc -> bbb).
    FindIjParamsVisitor visitor = new FindIjParamsVisitor(templateRegistry);
    visitor.exec(aaa);
    assertThat(visitor.exec(bbb).ijParamToCalleesMultimap).hasSize(2);
    assertThat(visitor.exec(ccc).ijParamToCalleesMultimap).hasSize(5);
    assertThat(visitor.exec(ccc).ijParamToCalleesMultimap.keySet()).hasSize(4);
    assertThat(visitor.exec(aaa).ijParamToCalleesMultimap).hasSize(7);
    assertThat(visitor.exec(aaa).ijParamToCalleesMultimap.keySet()).hasSize(5);
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode) TemplateRegistry(com.google.template.soy.soytree.TemplateRegistry) SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) Test(org.junit.Test)

Example 43 with TemplateNode

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

the class FindIjParamsVisitorTest method testTwoPathsToSameRecursiveCycle.

@Test
public void testTwoPathsToSameRecursiveCycle() {
    // aaa -> {bbb, ccc}, bbb -> ddd, ccc -> ddd, ddd -> bbb.
    String fileContent = "" + "{namespace ns}\n" + "\n" + "/***/\n" + "{template .aaa}\n" + "  {$ij.boo} {$ij.foo} {call .bbb /} {call .ccc /}\n" + "{/template}\n" + "\n" + "/***/\n" + "{template .bbb}\n" + "  {$ij.boo} {$ij.goo} {call .ddd /}\n" + "{/template}\n" + "\n" + "/***/\n" + "{template .ccc}\n" + "  {$ij.boo} {$ij.moo} {call .ddd /}\n" + "{/template}\n" + "\n" + "/***/\n" + "{template .ddd}\n" + "  {$ij.boo} {$ij.too} {call .bbb /}\n" + "{/template}\n";
    SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(fileContent).parse().fileSet();
    TemplateRegistry templateRegistry = new TemplateRegistry(soyTree, FAIL);
    TemplateNode aaa = soyTree.getChild(0).getChild(0);
    TemplateNode bbb = soyTree.getChild(0).getChild(1);
    TemplateNode ccc = soyTree.getChild(0).getChild(2);
    TemplateNode ddd = soyTree.getChild(0).getChild(3);
    // Test with exec(aaa).
    // Exercises: processCalleeHelper case 4 with incorporateCalleeVisitInfo case 4 (ccc -> ddd).
    FindIjParamsVisitor visitor = new FindIjParamsVisitor(templateRegistry);
    visitor.exec(aaa);
    assertThat(visitor.exec(bbb).ijParamToCalleesMultimap).hasSize(4);
    assertThat(visitor.exec(bbb).ijParamToCalleesMultimap.keySet()).hasSize(3);
    assertThat(visitor.exec(ddd).ijParamToCalleesMultimap).hasSize(4);
    assertThat(visitor.exec(ddd).ijParamToCalleesMultimap.keySet()).hasSize(3);
    assertThat(visitor.exec(ccc).ijParamToCalleesMultimap).hasSize(6);
    assertThat(visitor.exec(ccc).ijParamToCalleesMultimap.keySet()).hasSize(4);
    assertThat(visitor.exec(aaa).ijParamToCalleesMultimap).hasSize(8);
    assertThat(visitor.exec(aaa).ijParamToCalleesMultimap.keySet()).hasSize(5);
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode) TemplateRegistry(com.google.template.soy.soytree.TemplateRegistry) SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) Test(org.junit.Test)

Example 44 with TemplateNode

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

the class FindIjParamsVisitorTest method testSimpleRecursion.

@Test
public void testSimpleRecursion() {
    // Tests direct recursion (cycle of 1) and indirect recursion with a cycle of 2.
    // aaa -> bbb, bbb -> {bbb, ccc}, ccc -> bbb.
    String fileContent = "" + "{namespace ns}\n" + "\n" + "/***/\n" + "{template .aaa}\n" + "  {call .bbb /} {$ij.boo} {$ij.foo}\n" + "{/template}\n" + "\n" + "/***/\n" + "{template .bbb}\n" + "  {$ij.boo} {$ij.goo} {call .bbb /} {call .ccc /}\n" + "{/template}\n" + "\n" + "/***/\n" + "{template .ccc}\n" + "  {$ij.boo} {call .bbb /} {$ij.moo}\n" + "{/template}\n";
    SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(fileContent).parse().fileSet();
    TemplateRegistry templateRegistry = new TemplateRegistry(soyTree, FAIL);
    TemplateNode aaa = soyTree.getChild(0).getChild(0);
    TemplateNode bbb = soyTree.getChild(0).getChild(1);
    TemplateNode ccc = soyTree.getChild(0).getChild(2);
    // Test with exec(aaa).
    // Exercises: processCalleeHelper case 2 (bbb -> bbb).
    // Exercises: processCalleeHelper case 3 (ccc -> bbb).
    // Exercises: processCalleeHelper case 5 with incorporateCalleeVisitInfo case 2 (bbb -> ccc).
    FindIjParamsVisitor visitor = new FindIjParamsVisitor(templateRegistry);
    visitor.exec(aaa);
    assertThat(visitor.exec(ccc).ijParamToCalleesMultimap).hasSize(4);
    assertThat(visitor.exec(ccc).ijParamToCalleesMultimap.keySet()).hasSize(3);
    assertThat(visitor.exec(bbb).ijParamToCalleesMultimap).hasSize(4);
    assertThat(visitor.exec(bbb).ijParamToCalleesMultimap.keySet()).hasSize(3);
    assertThat(visitor.exec(aaa).ijParamToCalleesMultimap).hasSize(6);
    assertThat(visitor.exec(aaa).ijParamToCalleesMultimap.keySet()).hasSize(4);
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode) TemplateRegistry(com.google.template.soy.soytree.TemplateRegistry) SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) Test(org.junit.Test)

Example 45 with TemplateNode

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

the class FindIjParamsVisitorTest method testSmallerRecursiveCycleInLargerRecursiveCycle.

@Test
public void testSmallerRecursiveCycleInLargerRecursiveCycle() {
    // aaa -> {bbb, ccc}, bbb -> aaa, ccc -> bbb.
    String fileContent = "" + "{namespace ns}\n" + "\n" + "/***/\n" + "{template .aaa}\n" + "  {$ij.foo} {$ij.boo} {call .bbb /} {call .ccc /}\n" + "{/template}\n" + "\n" + "/***/\n" + "{template .bbb}\n" + "  {$ij.goo} {$ij.boo} {call .aaa /}\n" + "{/template}\n" + "\n" + "/***/\n" + "{template .ccc}\n" + "  {$ij.moo} {$ij.boo} {call .bbb /}\n" + "{/template}\n";
    SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(fileContent).parse().fileSet();
    TemplateRegistry templateRegistry = new TemplateRegistry(soyTree, FAIL);
    TemplateNode aaa = soyTree.getChild(0).getChild(0);
    TemplateNode bbb = soyTree.getChild(0).getChild(1);
    TemplateNode ccc = soyTree.getChild(0).getChild(2);
    // Test with exec(aaa).
    // Exercises: processCalleeHelper case 4 with incorporateCalleeVisitInfo case 3 (ccc -> bbb).
    FindIjParamsVisitor visitor = new FindIjParamsVisitor(templateRegistry);
    visitor.exec(aaa);
    assertThat(visitor.exec(ccc).ijParamToCalleesMultimap).hasSize(6);
    assertThat(visitor.exec(ccc).ijParamToCalleesMultimap.keySet()).hasSize(4);
    assertThat(visitor.exec(bbb).ijParamToCalleesMultimap).hasSize(6);
    assertThat(visitor.exec(bbb).ijParamToCalleesMultimap.keySet()).hasSize(4);
    assertThat(visitor.exec(aaa).ijParamToCalleesMultimap).hasSize(6);
    assertThat(visitor.exec(aaa).ijParamToCalleesMultimap.keySet()).hasSize(4);
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode) TemplateRegistry(com.google.template.soy.soytree.TemplateRegistry) SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) 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