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:
Michael Bayne
2011-02-28 11:52:40 -08:00
parent c271e7df12
commit f4cfa40c2b
3 changed files with 85 additions and 34 deletions
@@ -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));