use of com.google.template.soy.soytree.SoyFileSetNode in project closure-templates by google.
the class VeLoggingTest method renderTemplate.
private void renderTemplate(Map<String, ?> params, OutputAppendable output, String... templateBodyLines) throws IOException {
SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents("{namespace ns}\n" + "{template .foo}\n" + Joiner.on("\n").join(templateBodyLines) + "\n{/template}").typeRegistry(new SoyTypeRegistry.Builder().addDescriptors(ImmutableList.of(com.google.template.soy.testing.Foo.getDescriptor())).build()).setLoggingConfig(config).addSoyFunction(new DepthFunction()).runAutoescaper(true).parse().fileSet();
TemplateRegistry templateRegistry = new TemplateRegistry(soyTree, ErrorReporter.exploding());
CompiledTemplates templates = BytecodeCompiler.compile(templateRegistry, false, ErrorReporter.exploding()).get();
RenderContext ctx = TemplateTester.getDefaultContext(templates).toBuilder().hasLogger(true).build();
RenderResult result = templates.getTemplateFactory("ns.foo").create(TemplateTester.asRecord(params), EMPTY_DICT).render(output, ctx);
assertThat(result).isEqualTo(RenderResult.done());
}
use of com.google.template.soy.soytree.SoyFileSetNode in project closure-templates by google.
the class AliasUtilsTest method testMultipleCallAliasing.
/*
* Tests that a template that is called multiple times does not create a new alias.
*/
@Test
public void testMultipleCallAliasing() {
String fileBody = "{namespace foo.bar.baz}\n" + "{template .bam}\n" + " {call other.name.space.bam /}\n" + " {call other.name.space.bam /}\n" + "{/template}\n";
SoyFileSetNode n = SoyFileSetParserBuilder.forFileContents(fileBody).parse().fileSet();
TemplateAliases templateAliases = AliasUtils.createTemplateAliases(n.getChild(0));
String alias = templateAliases.get("other.name.space.bam");
assertThat(alias).isEqualTo("$templateAlias1");
assertThat(AliasUtils.isExternalFunction(alias)).isTrue();
}
use of com.google.template.soy.soytree.SoyFileSetNode in project closure-templates by google.
the class PerformDeprecatedNonContextualAutoescapeVisitorTest method testAutoescapeOnSimple.
@Test
public void testAutoescapeOnSimple() throws Exception {
String testPrintTags = "{'<br>'}";
SoyFileSetNode soyTree = parseTestPrintTagsHelper(testPrintTags);
List<PrintNode> printNodes = SoyTreeUtils.getAllNodesOfType(soyTree, PrintNode.class);
// Before.
assertThat(printNodes.get(0).getChildren()).isEmpty();
performAutoescape(soyTree);
// After.
assertThat(printNodes.get(0).getChildren()).hasSize(1);
assertThat(printNodes.get(0).getChild(0).getName()).isEqualTo(EscapeHtmlDirective.NAME);
}
use of com.google.template.soy.soytree.SoyFileSetNode in project closure-templates by google.
the class PerformDeprecatedNonContextualAutoescapeVisitorTest method testAutoescapeOnWithOtherDirectives.
@Test
public void testAutoescapeOnWithOtherDirectives() throws Exception {
String testPrintTags = "{'<br>' |truncate:5}";
SoyFileSetNode soyTree = parseTestPrintTagsHelper(testPrintTags);
List<PrintNode> printNodes = SoyTreeUtils.getAllNodesOfType(soyTree, PrintNode.class);
// Before.
assertThat(printNodes.get(0).getChildren()).hasSize(1);
assertThat(printNodes.get(0).getChild(0).getName()).isEqualTo("|truncate");
performAutoescape(soyTree);
// After.
assertThat(printNodes.get(0).getChildren()).hasSize(2);
assertThat(printNodes.get(0).getChild(0).getName()).isEqualTo(EscapeHtmlDirective.NAME);
assertThat(printNodes.get(0).getChild(1).getName()).isEqualTo("|truncate");
}
use of com.google.template.soy.soytree.SoyFileSetNode in project closure-templates by google.
the class AssertStrictAutoescapingVisitorTest method parseAndGetErrors.
private ImmutableList<SoyError> parseAndGetErrors(String soyCode) {
ErrorReporter errorReporter = ErrorReporter.createForTest();
SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(soyCode).errorReporter(errorReporter).parse().fileSet();
new AssertStrictAutoescapingVisitor(errorReporter).exec(soyTree);
return errorReporter.getErrors();
}
Aggregations