Show the name of variable that is null or missing

If Compliler.nullValue contains a substring "{{name}}", then this substring
will be replaced with the name of variable.
For example, if nullValue="?{{name}}?" and variable is resolved to null,
then string "?foo?" will be used.
This commit is contained in:
pmenhart
2013-01-23 15:59:52 -05:00
parent 6e71dad5f2
commit 8b0d063ffd
3 changed files with 29 additions and 2 deletions
@@ -444,6 +444,21 @@ public class MustacheTest
"foobar", "{{missing}}{{notmissing}}", context("notmissing", "bar"));
}
@Test public void testMissingValueWithDefaultSubstitution () {
test(Mustache.compiler().defaultValue("?{{name}}?"),
"?missing?bar", "{{missing}}{{notmissing}}", context("notmissing", "bar"));
}
@Test public void testMissingValueWithDefaultSubstitution2 () {
test(Mustache.compiler().defaultValue("{{{{name}}}}"),
"{{missing}}bar", "{{missing}}{{notmissing}}", context("notmissing", "bar"));
}
@Test public void testMissingValueWithDefaultSubstitution3 () {
test(Mustache.compiler().defaultValue("{{?{{name}}?}}"),
"{{?missing?}}bar", "{{missing}}{{notmissing}}", context("notmissing", "bar"));
}
@Test public void testNullValueGetsDefault () {
test(Mustache.compiler().defaultValue("foo"),
"foobar", "{{nullvar}}{{nonnullvar}}", new Object() {