use of com.google.template.soy.jbcsrc.shared.CompiledTemplates 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.CompiledTemplates in project closure-templates by google.
the class ProtoSupportTest method testPassingManipulatedFields.
// tests for a bug in handling of ternaries
@Test
public void testPassingManipulatedFields() {
String file = JOINER.join("{namespace ns}", "", "{template .caller}", " {@param pair : example.KvPair}", " {let $closeUrl : $pair.value /}", " {call .callee}{param str : $closeUrl ? $closeUrl : '' /}{/call}", "{/template}", "", "{template .callee}", " {@param? str : string}", " {if $str}", " {$str}", " {/if}", "{/template}");
CompiledTemplates templates = BytecodeCompiler.compile(SoyFileSetParserBuilder.forFileContents(file).typeRegistry(types).parse().registry(), false, ErrorReporter.exploding()).get();
render(templates, "ns.caller", (SoyRecord) SoyValueConverter.INSTANCE.convert(ImmutableMap.of("pair", KvPair.newBuilder().setAnotherValue(2))));
}
use of com.google.template.soy.jbcsrc.shared.CompiledTemplates 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());
}
use of com.google.template.soy.jbcsrc.shared.CompiledTemplates in project closure-templates by google.
the class LazyClosureCompilerTest method testDetachOnFutureLazily.
@Test
public void testDetachOnFutureLazily() throws IOException {
SettableFuture<String> bar = SettableFuture.create();
CompiledTemplates templates = compileTemplateBody("{@param bar : string }", "{let $foo : $bar + $bar /}", "before use", "{$foo}");
CompiledTemplate.Factory factory = templates.getTemplateFactory("ns.foo");
RenderContext context = getDefaultContext(templates);
CompiledTemplate template = factory.create(asRecord(ImmutableMap.of("bar", bar)), EMPTY_DICT);
BufferingAppendable output = LoggingAdvisingAppendable.buffering();
RenderResult result = template.render(output, context);
assertThat(result.type()).isEqualTo(RenderResult.Type.DETACH);
// we found bar!
assertThat(result.future()).isSameAs(bar);
assertThat(output.toString()).isEqualTo("before use");
// make sure no progress is made
result = template.render(output, context);
assertThat(result.type()).isEqualTo(RenderResult.Type.DETACH);
assertThat(result.future()).isSameAs(bar);
assertThat(output.toString()).isEqualTo("before use");
bar.set(" bar");
assertThat(template.render(output, context)).isEqualTo(RenderResult.done());
assertThat(output.toString()).isEqualTo("before use bar bar");
}
use of com.google.template.soy.jbcsrc.shared.CompiledTemplates in project closure-templates by google.
the class LazyClosureCompilerTest method testLetContentNode_detaching.
@Test
public void testLetContentNode_detaching() throws IOException {
SettableFuture<String> bar = SettableFuture.create();
CompiledTemplates templates = compileTemplateBody("{@param bar : string }", "{let $foo kind=\"text\"}", " hello {$bar}", "{/let}", "{$foo}");
CompiledTemplate.Factory factory = templates.getTemplateFactory("ns.foo");
RenderContext context = getDefaultContext(templates);
CompiledTemplate template = factory.create(asRecord(ImmutableMap.of("bar", bar)), EMPTY_DICT);
BufferingAppendable output = LoggingAdvisingAppendable.buffering();
RenderResult result = template.render(output, context);
assertThat(result.type()).isEqualTo(RenderResult.Type.DETACH);
// we found bar!
assertThat(result.future()).isSameAs(bar);
assertThat(output.toString()).isEqualTo("hello ");
// make sure no progress is made
result = template.render(output, context);
assertThat(result.type()).isEqualTo(RenderResult.Type.DETACH);
assertThat(result.future()).isSameAs(bar);
assertThat(output.toString()).isEqualTo("hello ");
bar.set("bar");
assertThat(template.render(output, context)).isEqualTo(RenderResult.done());
assertThat(output.toString()).isEqualTo("hello bar");
}
Aggregations