Skip to content

Commit 7cac15f

Browse files
authored
Merge pull request #1153 from SijieMei/master
[ISSUE-567] Fix the test of issue 567
2 parents 25cc890 + 457d740 commit 7cac15f

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

handlebars/src/test/java/com/github/jknack/handlebars/issues/Issue567.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,20 @@ public class Issue567 extends v4Test {
1515

1616
@Test
1717
public void shouldKeepContextOnBlockParameter() throws Exception {
18-
shouldCompileTo(
18+
String[] expected = new String[] {
19+
" context is {v=a, k=0} context is {v=b, k=1} context is {v=c, k=2}",
20+
" context is {v=a, k=0} context is {v=b, k=1} context is {k=2, v=c}",
21+
" context is {v=a, k=0} context is {k=1, v=b} context is {v=c, k=2}",
22+
" context is {v=a, k=0} context is {k=1, v=b} context is {k=2, v=c}",
23+
" context is {k=0, v=a} context is {v=b, k=1} context is {v=c, k=2}",
24+
" context is {k=0, v=a} context is {v=b, k=1} context is {k=2, v=c}",
25+
" context is {k=0, v=a} context is {k=1, v=b} context is {v=c, k=2}",
26+
" context is {k=0, v=a} context is {k=1, v=b} context is {k=2, v=c}"
27+
};
28+
29+
hashShouldCompileTo(
1930
"{{#each foo as |v k|}}" + " context is {{{.}}}" + "{{/each}}",
2031
$("hash", $("foo", Arrays.asList("a", "b", "c"))),
21-
" context is {v=a, k=0} context is {v=b, k=1} context is {v=c, k=2}");
32+
expected);
2233
}
2334
}

handlebars/src/test/java/com/github/jknack/handlebars/v4Test.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package com.github.jknack.handlebars;
77

88
import static org.junit.jupiter.api.Assertions.assertEquals;
9+
import static org.junit.jupiter.api.Assertions.assertTrue;
910

1011
import java.io.IOException;
1112
import java.util.LinkedHashMap;
@@ -30,6 +31,17 @@ public void shouldCompileTo(final String template, final Hash data, final String
3031
assertEquals(expected, result, "'" + expected + "' should === '" + result + "': ");
3132
}
3233

34+
public void hashShouldCompileTo(final String template, final Hash data, final String[] expected)
35+
throws IOException {
36+
Template t = compile(template, data);
37+
Object hash = data.get("hash");
38+
String result = t.apply(configureContext(hash));
39+
assertTrue(
40+
java.util.Arrays.asList(expected).contains(result),
41+
"Result '" + result + "' does not match any of the expected values: " + java.util.Arrays.toString(expected)
42+
);
43+
}
44+
3345
protected Object configureContext(final Object context) {
3446
return context;
3547
}

0 commit comments

Comments
 (0)