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"); }
// 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"); }