// Regression test covering rollback of cl/101592053. public void testJavaFunctions() { String soyFileContent = "{namespace ns autoescape=\"strict\"}\n" + "/***/\n" + "{template .foo kind=\"html\"}\n" + " {reverse('hello')}\n" + "{/template}\n"; ParseResult result = SoyFileSetParserBuilder.forFileContents(soyFileContent) .addSoyFunction(Reverse.INSTANCE) .parse(); TemplateRegistry registry = result.registry(); StringBuilder out = new StringBuilder(); RenderVisitor rv = INJECTOR .getInstance(RenderVisitorFactory.class) .create( out, registry, SoyValueHelper.EMPTY_DICT, null /* ijData */, null /* activeDelPackageNames */, null /* msgBundle */, null /* xidRenamingMap */, null /* cssRenamingMap */); rv.exec(registry.getBasicTemplate("ns.foo")); assertThat(out.toString()).isEqualTo("olleh"); }
public void testTofuPrintDirectives() { String soyFileContent = "{namespace ns autoescape=\"strict\"}\n" + "/***/\n" + "{template .foo kind=\"html\"}\n" + " {'hello' |caps}\n" + "{/template}\n"; ImmutableMap<String, ? extends SoyJavaPrintDirective> printDirectives = FunctionAdapters.buildSpecificSoyDirectivesMap( ImmutableSet.of(Caps.INSTANCE), SoyJavaPrintDirective.class); ParseResult result = SoyFileSetParserBuilder.forFileContents(soyFileContent).parse(); TemplateRegistry registry = result.registry(); StringBuilder out = new StringBuilder(); RenderVisitor rv = INJECTOR .getInstance(TofuRenderVisitorFactory.class) .create( out, registry, printDirectives, SoyValueHelper.EMPTY_DICT, SoyValueHelper.EMPTY_DICT /* ijData */, null /* activeDelPackageNames */, null /* msgBundle */, null /* xidRenamingMap */, null /* cssRenamingMap */); rv.exec(registry.getBasicTemplate("ns.foo")); assertThat(out.toString()).isEqualTo("HELLO"); }
// TODO: Does this belong in RenderVisitorTest instead? public void testLetWithinParam() throws Exception { String soyFileContent = "" + "{namespace ns autoescape=\"deprecated-noncontextual\"}\n" + "\n" + "/***/\n" + "{template .callerTemplate}\n" + " {call .calleeTemplate}\n" + " {param boo}\n" + " {let $foo: 'blah' /}\n" + " {$foo}\n" + " {/param}\n" + " {/call}\n" + "{/template}\n" + "\n" + "/** @param boo */\n" + "{template .calleeTemplate}\n" + " {$boo}\n" + "{/template}\n"; TemplateRegistry templateRegistry = SoyFileSetParserBuilder.forFileContents(soyFileContent).parse().registry(); // Important: This test will be doing its intended job only if we run // MarkParentNodesNeedingEnvFramesVisitor, because otherwise the 'let' within the 'param' block // will add its var to the enclosing template's env frame. StringBuilder outputSb = new StringBuilder(); RenderVisitor rv = INJECTOR .getInstance(RenderVisitorFactory.class) .create( outputSb, templateRegistry, SoyValueHelper.EMPTY_DICT, null /* ijData */, Collections.<String>emptySet() /* activeDelPackageNames */, null /* msgBundle */, null /* xidRenamingMap */, null /* cssRenamingMap */); rv.exec(templateRegistry.getBasicTemplate("ns.callerTemplate")); assertThat(outputSb.toString()).isEqualTo("blah"); }