use of com.google.template.soy.jbcsrc.shared.CompiledTemplate in project closure-templates by google.
the class DetachStateTest method testDetachOnUnResolvedProvider.
@Test
public void testDetachOnUnResolvedProvider() throws IOException {
SettableFuture<String> future = SettableFuture.create();
CompiledTemplates templates = TemplateTester.compileTemplateBody("{@param foo : string}", "prefix{sp}{$foo}{sp}suffix");
CompiledTemplate.Factory factory = templates.getTemplateFactory("ns.foo");
RenderContext context = getDefaultContext(templates);
CompiledTemplate template = factory.create(asRecord(ImmutableMap.of("foo", future)), EMPTY_DICT);
BufferingAppendable output = LoggingAdvisingAppendable.buffering();
RenderResult result = template.render(output, context);
assertThat(result.type()).isEqualTo(RenderResult.Type.DETACH);
assertThat(result.future()).isEqualTo(future);
assertThat(output.toString()).isEqualTo("prefix ");
// No progress is made, our caller is an idiot and didn't wait for the future
result = template.render(output, context);
assertThat(result.type()).isEqualTo(RenderResult.Type.DETACH);
assertThat(result.future()).isEqualTo(future);
assertThat(output.toString()).isEqualTo("prefix ");
future.set("future");
result = template.render(output, context);
assertThat(result).isEqualTo(RenderResult.done());
assertThat(output.toString()).isEqualTo("prefix future suffix");
}
use of com.google.template.soy.jbcsrc.shared.CompiledTemplate in project closure-templates by google.
the class DetachStateTest method testDetachOnParamTransclusion.
@Test
public void testDetachOnParamTransclusion() throws IOException {
CompiledTemplates templates = TemplateTester.compileFile("{namespace ns}", "", "/** */", "{template .caller}", " {@param callerParam : string}", " {call .callee}", " {param calleeParam kind=\"text\"}", " prefix {$callerParam} suffix", " {/param}", " {/call}", "{/template}", "", "/** */", "{template .callee}", " {@param calleeParam : string}", " {$calleeParam}", "{/template}", "");
CompiledTemplate.Factory factory = templates.getTemplateFactory("ns.caller");
RenderContext context = getDefaultContext(templates);
SettableFuture<String> param = SettableFuture.create();
SoyRecord params = asRecord(ImmutableMap.of("callerParam", param));
CompiledTemplate template = factory.create(params, EMPTY_DICT);
BufferingAppendable output = LoggingAdvisingAppendable.buffering();
assertThat(template.render(output, context)).isEqualTo(RenderResult.continueAfter(param));
assertThat(output.toString()).isEqualTo("prefix ");
param.set("foo");
assertThat(template.render(output, context)).isEqualTo(RenderResult.done());
assertThat(output.toString()).isEqualTo("prefix foo suffix");
}
use of com.google.template.soy.jbcsrc.shared.CompiledTemplate in project closure-templates by google.
the class DetachStateTest method testDetach_xid.
@Test
public void testDetach_xid() throws IOException {
CompiledTemplates templates = TemplateTester.compileTemplateBody("{xid('foo')}");
CompiledTemplate.Factory factory = templates.getTemplateFactory("ns.foo");
RenderContext context = getDefaultContext(templates);
CompiledTemplate template = factory.create(EMPTY_DICT, EMPTY_DICT);
// Basic stuff works
TestAppendable output = new TestAppendable();
assertThat(template.render(output, context)).isEqualTo(RenderResult.done());
assertThat(output.toString()).isEqualTo("foo_");
output = new TestAppendable();
output.softLimitReached = true;
// xid() does not detach
assertThat(template.render(output, context)).isEqualTo(RenderResult.done());
assertThat(output.toString()).isEqualTo("foo_");
}
use of com.google.template.soy.jbcsrc.shared.CompiledTemplate in project closure-templates by google.
the class ProtoSupportTest method render.
private String render(CompiledTemplates templates, String name, SoyRecord params) {
CompiledTemplate caller = templates.getTemplateFactory(name).create(params, EMPTY_DICT);
BufferingAppendable sb = LoggingAdvisingAppendable.buffering();
try {
assertThat(caller.render(sb, getDefaultContext(templates))).isEqualTo(RenderResult.done());
} catch (IOException e) {
throw new RuntimeException(e);
}
return sb.toString();
}
use of com.google.template.soy.jbcsrc.shared.CompiledTemplate in project closure-templates by google.
the class LazyClosureCompilerTest method testLetValueNodeStructure.
@Test
public void testLetValueNodeStructure() {
// make sure we don't break normal reflection apis
CompiledTemplates templates = compileTemplateBody("{let $bar : 'a' /}", "{let $foo : $bar + 1 /}");
CompiledTemplate.Factory factory = templates.getTemplateFactory("ns.foo");
CompiledTemplate template = factory.create(EMPTY_DICT, EMPTY_DICT);
assertThat(template.getClass().getDeclaredClasses()).hasLength(2);
List<Class<?>> innerClasses = Lists.newArrayList(template.getClass().getDeclaredClasses());
innerClasses.remove(factory.getClass());
Class<?> let = Iterables.getOnlyElement(innerClasses);
assertThat(let.getSimpleName()).isEqualTo("let_foo");
assertThat(let.getDeclaringClass()).isEqualTo(template.getClass());
}
Aggregations