Re-escape \r and \n in failure reports.

This commit is contained in:
Michael Bayne
2014-12-16 09:44:46 -08:00
parent ef4184404d
commit 79c7fd2cb0
@@ -436,6 +436,12 @@ public class MustacheTest
testNewlineSkipping("\r\n"); testNewlineSkipping("\r\n");
} }
@Test public void testTrimBlank () {
Mustache.StringSegment str = new Mustache.StringSegment(" \r\n ", false);
assertEquals("Text( )-1/0", str.trimLeadBlank().toString());
assertEquals("Text( \\r\\n)3/-1", str.trimTrailBlank().toString());
}
protected void testNewlineSkipping (String sep) { protected void testNewlineSkipping (String sep) {
String tmpl = "list:" + sep + String tmpl = "list:" + sep +
"{{#items}}" + sep + "{{#items}}" + sep +
@@ -743,13 +749,17 @@ public class MustacheTest
} }
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)); assertEquals(uncrlf(expected), uncrlf(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); test(Mustache.compiler(), expected, template, ctx);
} }
protected static String uncrlf (String text) {
return text == null ? null : text.replace("\r", "\\r").replace("\n", "\\n");
}
protected Object context (Object... data) { protected Object context (Object... data) {
Map<String, Object> ctx = new HashMap<String, Object>(); Map<String, Object> ctx = new HashMap<String, Object>();
for (int ii = 0; ii < data.length; ii += 2) { for (int ii = 0; ii < data.length; ii += 2) {