use of com.google.template.soy.soytree.TemplateRegistry in project closure-templates by google.
the class FindTransitiveDepTemplatesVisitorTest 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";
ParseResult result = SoyFileSetParserBuilder.forFileContents(fileContent).errorReporter(FAIL).parse();
TemplateRegistry templateRegistry = result.registry();
SoyFileSetNode soyTree = result.fileSet();
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).
FindTransitiveDepTemplatesVisitor visitor = new FindTransitiveDepTemplatesVisitor(templateRegistry);
Map<TemplateNode, TransitiveDepTemplatesInfo> memoizedInfoMap = visitor.templateToFinishedInfoMap;
visitor.exec(aaa);
assertThat(memoizedInfoMap).hasSize(3);
assertThat(memoizedInfoMap.get(ccc).depTemplateSet).isEqualTo(ImmutableSet.of(ccc, bbb));
assertThat(memoizedInfoMap.get(bbb).depTemplateSet).isEqualTo(ImmutableSet.of(bbb, ccc));
assertThat(memoizedInfoMap.get(aaa).depTemplateSet).isEqualTo(ImmutableSet.of(aaa, bbb, ccc));
}
use of com.google.template.soy.soytree.TemplateRegistry in project closure-templates by google.
the class SimplifyVisitorTest method testCombineConsecutiveRawTextNodes.
@Test
public void testCombineConsecutiveRawTextNodes() throws Exception {
String soyCode = "{@param boo : ?}\n" + "blah{$boo}blah" + "{for $i in range(5)}" + " blah{$boo}blah" + "{/for}";
SoyFileSetNode soyTree = SoyFileSetParserBuilder.forTemplateContents(soyCode).parse().fileSet();
TemplateNode template = soyTree.getChild(0).getChild(0);
ForNonemptyNode forNode = (ForNonemptyNode) ((ForNode) template.getChild(3)).getChild(0);
forNode.addChild(new RawTextNode(0, "bleh", SourceLocation.UNKNOWN));
forNode.addChild(new RawTextNode(0, "bluh", SourceLocation.UNKNOWN));
template.addChild(0, new RawTextNode(0, "bleh", SourceLocation.UNKNOWN));
template.addChild(0, new RawTextNode(0, "bluh", SourceLocation.UNKNOWN));
assertThat(template.numChildren()).isEqualTo(6);
assertThat(forNode.numChildren()).isEqualTo(5);
SimplifyVisitor simplifyVisitor = SimplifyVisitor.create();
simplifyVisitor.simplify(soyTree, new TemplateRegistry(soyTree, ErrorReporter.exploding()));
assertThat(template.numChildren()).isEqualTo(4);
assertThat(forNode.numChildren()).isEqualTo(3);
assertThat(((RawTextNode) template.getChild(0)).getRawText()).isEqualTo("bluhblehblah");
assertThat(((RawTextNode) forNode.getChild(2)).getRawText()).isEqualTo("blahblehbluh");
}
use of com.google.template.soy.soytree.TemplateRegistry in project closure-templates by google.
the class RenderVisitorTest method renderTemplateInFile.
private String renderTemplateInFile(ParseResult parseResult, String templateName, SoyRecord data, SoyRecord ijData, Predicate<String> activeDelPackageNames, StringBuilder outputSb) {
TemplateRegistry templateRegistry = parseResult.registry();
RenderVisitor rv = new RenderVisitor(new EvalVisitorFactoryImpl(), outputSb, templateRegistry, data, ijData, activeDelPackageNames, null, xidRenamingMap, cssRenamingMap, false);
TemplateNode templateNode = templateRegistry.getBasicTemplate(templateName);
rv.exec(templateNode);
return outputSb.toString();
}
use of com.google.template.soy.soytree.TemplateRegistry 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);
}
use of com.google.template.soy.soytree.TemplateRegistry 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);
}
Aggregations