Added a "standards mode" based on patches from mrdon. In standards mode, we do
not search parent contexts for name bindings, nor do we support compound keys.
Also added support for {{.}} which has the same semantics as {{this}}. I must
have missed this when reading the Mustache spec.
This commit is contained in:
@@ -203,6 +203,33 @@ public class MustacheTest
|
||||
}
|
||||
}
|
||||
|
||||
@Test public void testStandardsModeWithNullValuesInLoop () {
|
||||
String tmpl = "first line\n{{#nonexistent}}foo{{/nonexistent}}\nsecond line";
|
||||
String result = Mustache.compiler().standardsMode(true).compile(tmpl).execute(new Object());
|
||||
assertEquals("first line\nsecond line", result);
|
||||
}
|
||||
|
||||
@Test public void testStandardsModeWithNullValuesInInverseLoop () {
|
||||
String tmpl = "first line\n{{^nonexistent}}foo{{/nonexistent}} \nsecond line";
|
||||
String result = Mustache.compiler().standardsMode(true).compile(tmpl).execute(new Object());
|
||||
assertEquals("first line\nfoo \nsecond line", result);
|
||||
}
|
||||
|
||||
@Test public void testStandardsModeWithDotValue () {
|
||||
String tmpl = "{{#foo}}:{{.}}:{{/foo}}";
|
||||
String result = Mustache.compiler().standardsMode(true).compile(tmpl).
|
||||
execute(Collections.singletonMap("foo", "bar"));
|
||||
assertEquals(":bar:", result);
|
||||
}
|
||||
|
||||
@Test(expected = MustacheException.class)
|
||||
public void testStandardsModeWithNoParentContextSearching () {
|
||||
String tmpl = "{{#parent}}foo{{parentProperty}}bar{{/parent}}";
|
||||
String result = Mustache.compiler().standardsMode(true).compile(tmpl).
|
||||
execute(context("parent", new Object(),
|
||||
"parentProperty", "bar"));
|
||||
}
|
||||
|
||||
protected void test (String expected, String template, Object ctx)
|
||||
{
|
||||
assertEquals(expected, Mustache.compiler().compile(template).execute(ctx));
|
||||
|
||||
Reference in New Issue
Block a user