Add option to treat zero as a falsy value

In javascript implementation, zero is a falsy value and is treated as a false boolean.
An option is added (false by default) to treat zero as a falsy value as in javascript implementation.

It means that section like:

{{#zeroValue}}foo{{/zeroValue}}

will not be rendered.
This commit is contained in:
Mickael Jeanroy
2013-05-08 22:24:40 +02:00
parent 426faf92c5
commit 4300b1213e
2 changed files with 48 additions and 10 deletions
@@ -145,6 +145,30 @@ public class MustacheTest
});
}
@Test public void testSectionWithLongValueZero () {
test(Mustache.compiler().zeroIsFalse(true), "", "{{#foo}}test{{/foo}}", new Object() {
Long foo = 0L;
});
}
@Test public void testSectionWithIntegerValueZero () {
test(Mustache.compiler().zeroIsFalse(true), "", "{{#foo}}test{{/foo}}", new Object() {
Integer foo = 0;
});
}
@Test public void testSectionWithFloatValueZero () {
test(Mustache.compiler().zeroIsFalse(true), "", "{{#foo}}test{{/foo}}", new Object() {
Float foo = 0F;
});
}
@Test public void testSectionWithDoubleValueZero () {
test(Mustache.compiler().zeroIsFalse(true), "", "{{#foo}}test{{/foo}}", new Object() {
Double foo = 0D;
});
}
@Test public void testMissingSection () {
test("", "{{#foo}}{{bar}}{{/foo}}", new Object() {
// no foo