use of com.google.template.soy.data.LoggingAdvisingAppendable.BufferingAppendable in project closure-templates by google.
the class StreamingPrintDirectivesTest method testStreamingPrintOrdering.
// There was a bug that caused us to apply print directives in the wrong order when there were
// multiple streaming print directives.
@Test
public void testStreamingPrintOrdering() throws IOException {
CompiledTemplates templates = compileFile("{namespace ns}", "", "{template .foo}", " {@param s : ?}", " {$s |streaming:'first' |streaming:'second'}", "{/template}", "");
RenderContext context = getDefaultContext(templates);
BufferingAppendable output = BufferingAppendable.buffering();
CompiledTemplate template = templates.getTemplateFactory("ns.foo").create(SoyValueConverterUtility.newDict("s", "hello"), EMPTY_DICT);
template.render(output, context);
assertThat(output.getAndClearBuffer()).isEqualTo("(second: (first: hello))");
}
use of com.google.template.soy.data.LoggingAdvisingAppendable.BufferingAppendable in project closure-templates by google.
the class StreamingPrintDirectivesTest method testStreamingCall.
@Test
public void testStreamingCall() throws IOException {
// As of right now only a few directives support streaming, but this includes |escapeHtml and
// |escapeJsString, so we should be able to transitively stream through all of that.
CompiledTemplates templates = compileFile("{namespace ns}", "", "{template .foo}", " {call .bar data=\"all\"/}", "{/template}", "", "{template .bar}", " <script>var x=\"{call .baz data=\"all\" /}\";</script>", "{/template}", "", "{template .baz kind=\"text\"}", " {@param future : ?}", " \"{$future}\" ", "{/template}", "");
RenderContext context = getDefaultContext(templates);
BufferingAppendable output = BufferingAppendable.buffering();
SettableFuture<String> future = SettableFuture.create();
CompiledTemplate template = templates.getTemplateFactory("ns.foo").create(SoyValueConverterUtility.newDict("future", future), EMPTY_DICT);
template.render(output, context);
assertThat(output.getAndClearBuffer()).isEqualTo("<script>var x=\"\\x22");
future.set("hello");
template.render(output, context);
assertThat(output.getAndClearBuffer()).isEqualTo("hello\\x22\";</script>");
}
use of com.google.template.soy.data.LoggingAdvisingAppendable.BufferingAppendable in project closure-templates by google.
the class BytecodeCompilerTest method testParamValidation.
@Test
public void testParamValidation() throws Exception {
CompiledTemplates templates = TemplateTester.compileTemplateBody("{@param foo : int}", "{$foo ?: -1}");
CompiledTemplate.Factory singleParam = templates.getTemplateFactory("ns.foo");
RenderContext context = getDefaultContext(templates);
BufferingAppendable builder = LoggingAdvisingAppendable.buffering();
SoyDict params = SoyValueConverterUtility.newDict("foo", IntegerData.forValue(1));
singleParam.create(params, EMPTY_DICT).render(builder, context);
assertThat(builder.getAndClearBuffer()).isEqualTo("1");
singleParam.create(EMPTY_DICT, EMPTY_DICT).render(builder, context);
assertThat(builder.getAndClearBuffer()).isEqualTo("-1");
templates = TemplateTester.compileTemplateBody("{@inject foo : int}", "{$foo}");
CompiledTemplate.Factory singleIj = templates.getTemplateFactory("ns.foo");
context = getDefaultContext(templates);
params = SoyValueConverterUtility.newDict("foo", IntegerData.forValue(1));
singleIj.create(SoyValueConverter.EMPTY_DICT, params).render(builder, context);
assertThat(builder.getAndClearBuffer()).isEqualTo("1");
params = SoyValueConverterUtility.newDict();
singleIj.create(SoyValueConverter.EMPTY_DICT, params).render(builder, context);
assertThat(builder.getAndClearBuffer()).isEqualTo("null");
}
use of com.google.template.soy.data.LoggingAdvisingAppendable.BufferingAppendable in project closure-templates by google.
the class BytecodeCompilerTest method renderWithContext.
private static String renderWithContext(CompiledTemplate.Factory factory, RenderContext context) throws IOException {
BufferingAppendable builder = LoggingAdvisingAppendable.buffering();
assertThat(factory.create(EMPTY_DICT, EMPTY_DICT).render(builder, context)).isEqualTo(RenderResult.done());
String string = builder.toString();
return string;
}
use of com.google.template.soy.data.LoggingAdvisingAppendable.BufferingAppendable in project closure-templates by google.
the class AbstractLoggingAdvisingAppendableTest method testLogonly_logonly_after_regular.
@Test
public void testLogonly_logonly_after_regular() throws IOException {
// test against the buffering version since it is a simple concrete implementation.
BufferingAppendable buffering = LoggingAdvisingAppendable.buffering();
buffering.enterLoggableElement(NOT_LOGONLY);
buffering.append("hello");
buffering.exitLoggableElement();
buffering.enterLoggableElement(LOGONLY);
buffering.append("logonly");
buffering.exitLoggableElement();
assertThat(buffering.toString()).isEqualTo("hello");
}
Aggregations