Skip to content

Commit 3123416

Browse files
committed
Prettify ExpectedNodeInterpreter
1 parent 962c671 commit 3123416

2 files changed

Lines changed: 14 additions & 9 deletions

File tree

src/test/java/com/hubspot/jinjava/ExpectedNodeInterpreter.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,20 @@ public ExpectedNodeInterpreter(JinjavaInterpreter interpreter, Tag tag, String p
2626
public String assertExpectedOutput(String name) {
2727
TagNode tagNode = (TagNode) fixture(name);
2828
String output = tag.interpret(tagNode, interpreter);
29-
assertThat(output.trim()).isEqualTo(expected(name).trim());
29+
assertThat(ExpectedTemplateInterpreter.prettify(output.trim()))
30+
.isEqualTo(ExpectedTemplateInterpreter.prettify(expected(name).trim()));
3031
return output;
3132
}
3233

3334
public Node fixture(String name) {
3435
try {
3536
return new TreeParser(
3637
interpreter,
37-
Resources.toString(
38-
Resources.getResource(String.format("%s/%s.jinja", path, name)),
39-
StandardCharsets.UTF_8
38+
ExpectedTemplateInterpreter.simplify(
39+
Resources.toString(
40+
Resources.getResource(String.format("%s/%s.jinja", path, name)),
41+
StandardCharsets.UTF_8
42+
)
4043
)
4144
)
4245
.buildTree()
@@ -49,9 +52,11 @@ public Node fixture(String name) {
4952

5053
public String expected(String name) {
5154
try {
52-
return Resources.toString(
53-
Resources.getResource(String.format("%s/%s.expected.jinja", path, name)),
54-
StandardCharsets.UTF_8
55+
return ExpectedTemplateInterpreter.simplify(
56+
Resources.toString(
57+
Resources.getResource(String.format("%s/%s.expected.jinja", path, name)),
58+
StandardCharsets.UTF_8
59+
)
5560
);
5661
} catch (IOException e) {
5762
throw new RuntimeException(e);

src/test/java/com/hubspot/jinjava/ExpectedTemplateInterpreter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public String assertExpectedNonEagerOutput(String name) {
135135
return output;
136136
}
137137

138-
private String prettify(String string) {
138+
static String prettify(String string) {
139139
return string.replaceAll("([}%]})([^\\s])", "$1\\\\\n$2");
140140
}
141141

@@ -172,7 +172,7 @@ private String expected(String name) {
172172
}
173173
}
174174

175-
private String simplify(String prettified) {
175+
static String simplify(String prettified) {
176176
return prettified.replaceAll("\\\\\n\\s*", "");
177177
}
178178

0 commit comments

Comments
 (0)