Skip to content

Commit

Permalink
Prettify ExpectedNodeInterpreter
Browse files Browse the repository at this point in the history
  • Loading branch information
jasmith-hs committed Sep 6, 2024
1 parent d34d5ec commit 41cc648
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
19 changes: 12 additions & 7 deletions src/test/java/com/hubspot/jinjava/ExpectedNodeInterpreter.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,20 @@ public ExpectedNodeInterpreter(JinjavaInterpreter interpreter, Tag tag, String p
public String assertExpectedOutput(String name) {
TagNode tagNode = (TagNode) fixture(name);
String output = tag.interpret(tagNode, interpreter);
assertThat(output.trim()).isEqualTo(expected(name).trim());
assertThat(ExpectedTemplateInterpreter.prettify(output.trim()))
.isEqualTo(ExpectedTemplateInterpreter.prettify(expected(name).trim()));
return output;
}

public Node fixture(String name) {
try {
return new TreeParser(
interpreter,
Resources.toString(
Resources.getResource(String.format("%s/%s.jinja", path, name)),
StandardCharsets.UTF_8
ExpectedTemplateInterpreter.simplify(
Resources.toString(
Resources.getResource(String.format("%s/%s.jinja", path, name)),
StandardCharsets.UTF_8
)
)
)
.buildTree()
Expand All @@ -49,9 +52,11 @@ public Node fixture(String name) {

public String expected(String name) {
try {
return Resources.toString(
Resources.getResource(String.format("%s/%s.expected.jinja", path, name)),
StandardCharsets.UTF_8
return ExpectedTemplateInterpreter.simplify(
Resources.toString(
Resources.getResource(String.format("%s/%s.expected.jinja", path, name)),
StandardCharsets.UTF_8
)
);
} catch (IOException e) {
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public String assertExpectedNonEagerOutput(String name) {
return output;
}

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

Expand Down Expand Up @@ -172,7 +172,7 @@ private String expected(String name) {
}
}

private String simplify(String prettified) {
static String simplify(String prettified) {
return prettified.replaceAll("\\\\\n\\s*", "");
}

Expand Down

0 comments on commit 41cc648

Please sign in to comment.