A few tweaks to default delims patch (and some tidying):
- triple-stache mode reverted to only work with {{{ }}} rather than working
with whatever default delims you set; I think this is more in the spirit of
the Mustache spec
- Compiler.withDelims takes a delims string rather than the internal Delims
class which callers don't care about or have access to
- nixed Delims constructors, made updateDelims fluent
- nixed DelimsTest, it wasn't testing anything that wasn't also already tested
by the functional tests in MustacheTest
This commit is contained in:
@@ -1,38 +0,0 @@
|
||||
package com.samskivert.mustache;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.core.IsEqual.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class DelimsTest {
|
||||
|
||||
@Test public void shouldConstructDefaultDelims () {
|
||||
test(new Mustache.Delims(), '{', '{', '}', '}', true);
|
||||
}
|
||||
|
||||
@Test public void shouldUpdateDefaultDelims () {
|
||||
Mustache.Delims delims = new Mustache.Delims();
|
||||
delims.updateDelims("<% %>");
|
||||
test(delims, '<', '%', '%', '>', false);
|
||||
}
|
||||
|
||||
@Test public void shouldConstructCustomDelims () {
|
||||
test(new Mustache.Delims("<% %>"), '<', '%', '%', '>', true);
|
||||
}
|
||||
|
||||
@Test public void shouldUpdateCustomConstructedDelims () {
|
||||
Mustache.Delims delims = new Mustache.Delims("<% %>");
|
||||
delims.updateDelims("{{ }}");
|
||||
test(delims, '{', '{', '}', '}', false);
|
||||
}
|
||||
|
||||
protected void test (Mustache.Delims delims, char start1, char start2, char end1, char end2, boolean isDefault)
|
||||
{
|
||||
assertThat(delims.start1, equalTo(start1));
|
||||
assertThat(delims.start2, equalTo(start2));
|
||||
assertThat(delims.end1, equalTo(end1));
|
||||
assertThat(delims.end2, equalTo(end2));
|
||||
assertThat(delims.isDefault(), equalTo(isDefault));
|
||||
}
|
||||
}
|
||||
@@ -4,10 +4,6 @@
|
||||
|
||||
package com.samskivert.mustache;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
@@ -18,6 +14,9 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* Various unit tests.
|
||||
@@ -517,23 +516,20 @@ public class MustacheTest
|
||||
}
|
||||
|
||||
@Test public void testNonStandardDefaultDelims () {
|
||||
test(Mustache.compiler().withDelims(new Mustache.Delims("<% %>")), "bar", "<%foo%>", new Object() {
|
||||
test(Mustache.compiler().withDelims("<% %>"), "bar", "<%foo%>", new Object() {
|
||||
String foo = "bar";
|
||||
});
|
||||
}
|
||||
|
||||
protected void test (Mustache.Compiler compiler, String expected, String template, Object ctx)
|
||||
{
|
||||
protected void test (Mustache.Compiler compiler, String expected, String template, Object ctx) {
|
||||
assertEquals(expected, compiler.compile(template).execute(ctx));
|
||||
}
|
||||
|
||||
protected void test (String expected, String template, Object ctx)
|
||||
{
|
||||
protected void test (String expected, String template, Object ctx) {
|
||||
test(Mustache.compiler(), expected, template, ctx);
|
||||
}
|
||||
|
||||
protected Object context (Object... data)
|
||||
{
|
||||
protected Object context (Object... data) {
|
||||
Map<String, Object> ctx = new HashMap<String, Object>();
|
||||
for (int ii = 0; ii < data.length; ii += 2) {
|
||||
ctx.put(data[ii].toString(), data[ii+1]);
|
||||
|
||||
Reference in New Issue
Block a user