Simple support for decompiling fragments.

There are limitations! See the javadoc for Template.Fragment.decompile.

Closes #75.
This commit is contained in:
Michael Bayne
2016-04-14 08:24:54 -07:00
parent 59c45a2da7
commit 546f78318e
3 changed files with 100 additions and 0 deletions
@@ -594,6 +594,42 @@ public abstract class SharedTests extends GWTTestCase
}));
}
@Test public void testLambdaDecompile () {
test("Foo {{a}}, Bar {{a}}", "{{#lam}}Foo {{a}}{{/lam}}, {{#lam}}Bar {{a}}{{/lam}}",
context("lam", new Mustache.Lambda() {
public void execute (Template.Fragment frag, Writer out) throws IOException {
out.write(frag.decompile());
}
}));
// whitespace inside tags is dropped!
test("Foo {{a}}, Bar {{a}}", "{{#lam}}Foo {{a}}{{/lam}}, {{#lam}}Bar {{ a }}{{/lam}}",
context("lam", new Mustache.Lambda() {
public void execute (Template.Fragment frag, Writer out) throws IOException {
out.write(frag.decompile());
}
}));
// custom delimiters are ignored!
test("Foo {{a}}, Bar {{a}}",
"{{#lam}}Foo {{a}}{{/lam}}, {{=(( ))=}}((#lam))Bar ((a))((/lam))",
context("lam", new Mustache.Lambda() {
public void execute (Template.Fragment frag, Writer out) throws IOException {
out.write(frag.decompile());
}
}));
// coalesced whitespace around section tags is preserved
test("{{#section}}\n" +
"{{a}}\n" +
"{{/section}}",
"{{#lam}}{{#section}}\n" +
"{{a}}\n" +
"{{/section}}{{/lam}}",
context("lam", new Mustache.Lambda() {
public void execute (Template.Fragment frag, Writer out) throws IOException {
out.write(frag.decompile());
}
}));
}
@Test public void testNonStandardDefaultDelims () {
test(Mustache.compiler().withDelims("<% %>"), "bar", "<%foo%>", context("foo", "bar"));
}