Skip to content

Commit 57121ca

Browse files
author
Sam Pullara
committed
add encoded test
1 parent 8e92fd0 commit 57121ca

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

builder/src/test/java/com/sampullara/mustache/UnexecuteTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,35 @@ int taxed_value() {
7474
assertEquals(getContents(root, "unambiguoussimple.txt"), sw.toString());
7575
}
7676

77+
@Test
78+
public void testSimpleUnexecuteEncoded() throws MustacheException, IOException {
79+
MustacheJava c = init();
80+
Mustache m = c.parseFile("unambiguoussimple.html");
81+
StringWriter sw = new StringWriter();
82+
m.execute(sw, new Scope(new Object() {
83+
String name = "<Chris>";
84+
int value = 10000;
85+
86+
int taxed_value() {
87+
return (int) (this.value - (this.value * 0.4));
88+
}
89+
90+
boolean in_ca = true;
91+
}));
92+
assertEquals(getContents(root, "unambiguoussimpleencoded.txt"), sw.toString());
93+
94+
Scope scope = m.unexecute(sw.toString());
95+
assertEquals("<Chris>", scope.get("name"));
96+
assertEquals("10000", scope.get("value"));
97+
Scope in_ca = new Scope();
98+
in_ca.put("taxed_value", "6000");
99+
assertEquals(Arrays.asList(in_ca), scope.get("in_ca"));
100+
101+
sw = new StringWriter();
102+
m.execute(sw, scope);
103+
assertEquals(getContents(root, "unambiguoussimpleencoded.txt"), sw.toString());
104+
}
105+
77106
@Test
78107
public void testComplexUnexecute() throws MustacheException, IOException {
79108
Scope scope = new Scope(new Object() {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Hello &lt;Chris&gt;
2+
You have just won $10000!
3+
4+
Well, $6000, after taxes.

0 commit comments

Comments
 (0)