-
-
Notifications
You must be signed in to change notification settings - Fork 384
/
Copy pathPseudoVarsTest.java
68 lines (58 loc) · 1.65 KB
/
PseudoVarsTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package com.github.jknack.handlebars;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.Test;
/**
* Unit test for pseudo-vars.
*
* @author edgar.espina
* @since 0.3.0
*/
public class PseudoVarsTest {
@Test
public void list() throws IOException {
String input =
"{{#list}}i={{@index}}\neven={{@even}}\nodd={{@odd}}\nfirst={{@first}}\nlast={{@last}}\ni+1={{@index_1}}\n{{/list}}";
Handlebars handlebars = new Handlebars();
assertEquals("i=0\n" +
"even=even\n" +
"odd=\n" +
"first=first\n" +
"last=\n" +
"i+1=1\n" +
"i=1\n" +
"even=\n" +
"odd=odd\n" +
"first=\n" +
"last=\n" +
"i+1=2\n" +
"i=2\n" +
"even=even\n" +
"odd=\n" +
"first=\n" +
"last=last\n" +
"i+1=3\n",
handlebars.compileInline(input).apply(new Object() {
@SuppressWarnings("unused")
public List<String> getList() {
return Arrays.asList("a", "b", "c");
}
}));
}
@Test
public void lostParent$51() throws IOException {
String input =
"{{#parent}}{{#list}}{{@index}}. {{name}} {{/list}}{{/parent}}";
Handlebars handlebars = new Handlebars();
Map<String, Object> parent = new HashMap<>();
parent.put("name", "px");
parent.put("list", Arrays.asList("a", "b"));
Map<String, Object> context = new HashMap<>();
context.put("parent", parent);
assertEquals("0. px 1. px ", handlebars.compileInline(input).apply(context));
}
}