Moved falsey-ness detection into compiler.

Fixes #39.

This fixes a bug where falsey values were not properly triggering inverted
sections, and consolidates some logic.

Also did some renaming. Couldn't help myself.
This commit is contained in:
Michael Bayne
2013-07-03 16:47:21 -07:00
parent 6e3051c3ba
commit 9441d062a6
2 changed files with 42 additions and 26 deletions
@@ -146,9 +146,17 @@ public class MustacheTest
}
@Test public void testSectionWithFalseyEmptyString () {
test(Mustache.compiler().emptyStringIsFalse(true), "", "{{#foo}}test{{/foo}}", new Object() {
Object ctx = new Object() {
String foo = "";
});
String bar = "nonempty";
};
// test normal sections with falsey empty string
Mustache.Compiler compiler = Mustache.compiler().emptyStringIsFalse(true);
test(compiler, "", "{{#foo}}test{{/foo}}", ctx);
test(compiler, "test", "{{#bar}}test{{/bar}}", ctx);
// test inverted sections with falsey empty string
test(compiler, "test", "{{^foo}}test{{/foo}}", ctx);
test(compiler, "", "{{^bar}}test{{/bar}}", ctx);
}
@Test public void testSectionWithNonFalseyZero () {