Search in sources :

Example 56 with SoyFileSetNode

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());
}
Also used : TemplateRegistry(com.google.template.soy.soytree.TemplateRegistry) RenderContext(com.google.template.soy.jbcsrc.shared.RenderContext) SoyFileSetParserBuilder(com.google.template.soy.SoyFileSetParserBuilder) SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) RenderResult(com.google.template.soy.jbcsrc.api.RenderResult) CompiledTemplates(com.google.template.soy.jbcsrc.shared.CompiledTemplates)

Example 57 with SoyFileSetNode

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

Example 58 with SoyFileSetNode

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

Example 59 with SoyFileSetNode

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

Example 60 with SoyFileSetNode

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();
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter) SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode)

Aggregations

SoyFileSetNode (com.google.template.soy.soytree.SoyFileSetNode)106 Test (org.junit.Test)81 TemplateNode (com.google.template.soy.soytree.TemplateNode)35 TemplateRegistry (com.google.template.soy.soytree.TemplateRegistry)29 ErrorReporter (com.google.template.soy.error.ErrorReporter)19 ParseResult (com.google.template.soy.SoyFileSetParser.ParseResult)13 TransitiveDepTemplatesInfo (com.google.template.soy.passes.FindTransitiveDepTemplatesVisitor.TransitiveDepTemplatesInfo)8 RawTextNode (com.google.template.soy.soytree.RawTextNode)8 MsgNode (com.google.template.soy.soytree.MsgNode)7 SoyNode (com.google.template.soy.soytree.SoyNode)6 CompiledTemplates (com.google.template.soy.jbcsrc.shared.CompiledTemplates)5 SoyMsgBundle (com.google.template.soy.msgs.SoyMsgBundle)5 PrintNode (com.google.template.soy.soytree.PrintNode)5 MsgFallbackGroupNode (com.google.template.soy.soytree.MsgFallbackGroupNode)4 SoyFileNode (com.google.template.soy.soytree.SoyFileNode)4 CompiledTemplate (com.google.template.soy.jbcsrc.shared.CompiledTemplate)3 SoyMsg (com.google.template.soy.msgs.restricted.SoyMsg)3 SoyMsgBundleImpl (com.google.template.soy.msgs.restricted.SoyMsgBundleImpl)3 PluginResolver (com.google.template.soy.soyparse.PluginResolver)3 ImmutableList (com.google.common.collect.ImmutableList)2