Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,20 @@ public class Issue567 extends v4Test {

@Test
public void shouldKeepContextOnBlockParameter() throws Exception {
shouldCompileTo(
String[] expected = new String[] {
" context is {v=a, k=0} context is {v=b, k=1} context is {v=c, k=2}",
" context is {v=a, k=0} context is {v=b, k=1} context is {k=2, v=c}",
" context is {v=a, k=0} context is {k=1, v=b} context is {v=c, k=2}",
" context is {v=a, k=0} context is {k=1, v=b} context is {k=2, v=c}",
" context is {k=0, v=a} context is {v=b, k=1} context is {v=c, k=2}",
" context is {k=0, v=a} context is {v=b, k=1} context is {k=2, v=c}",
" context is {k=0, v=a} context is {k=1, v=b} context is {v=c, k=2}",
" context is {k=0, v=a} context is {k=1, v=b} context is {k=2, v=c}"
};

hashShouldCompileTo(
"{{#each foo as |v k|}}" + " context is {{{.}}}" + "{{/each}}",
$("hash", $("foo", Arrays.asList("a", "b", "c"))),
" context is {v=a, k=0} context is {v=b, k=1} context is {v=c, k=2}");
expected);
}
}
12 changes: 12 additions & 0 deletions handlebars/src/test/java/com/github/jknack/handlebars/v4Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package com.github.jknack.handlebars;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

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

public void hashShouldCompileTo(final String template, final Hash data, final String[] expected)
throws IOException {
Template t = compile(template, data);
Object hash = data.get("hash");
String result = t.apply(configureContext(hash));
assertTrue(
java.util.Arrays.asList(expected).contains(result),
"Result '" + result + "' does not match any of the expected values: " + java.util.Arrays.toString(expected)
);
}

protected Object configureContext(final Object context) {
return context;
}
Expand Down