@@ -23,35 +23,31 @@ public void shouldParseTextTemplate() throws Exception {
23
23
the (sw .toString ()).shouldBeEqual (source );
24
24
}
25
25
26
+ private String processAll (List <TemplateNode > nodes , Map values ) throws Exception {
27
+ StringWriter sw = new StringWriter ();
28
+ for (TemplateNode node : nodes ) {
29
+ node .process (values , sw );
30
+ }
31
+ return sw .toString ();
32
+ }
33
+
26
34
@ Test
27
35
public void shouldTokenizeTemplate () throws Exception {
28
36
List <TemplateNode > tokens = new TemplateParser (
29
- "Hello $ {first_name}, your code is <b>${$ {foo.size()}$ {invalid()}}</b> $ {one.two.three.four}" )
37
+ "Hello % {first_name}, your code is <b>%{% {foo.size()}% {invalid()}}</b> % {one.two.three.four}" )
30
38
.parse ();
31
- a (tokens .size ()).shouldBeEqual (6 );
32
- Map values = map (
39
+ the (tokens .size ()).shouldBeEqual (6 );
40
+ the ( processAll ( tokens , map (
33
41
"first_name" , "John" ,
34
42
"foo" , map (),
35
- "one" , map ("two" , map ("three" , map ("four" , "five" ))));
36
- StringWriter sw = new StringWriter ();
37
- tokens .get (0 ).process (values , sw );
38
- tokens .get (1 ).process (values , sw );
39
- tokens .get (2 ).process (values , sw );
40
- tokens .get (3 ).process (values , sw );
41
- tokens .get (4 ).process (values , sw );
42
- tokens .get (5 ).process (values , sw );
43
- the (sw .toString ()).shouldBeEqual ("Hello John, your code is <b>${0${invalid()}}</b> five" );
43
+ "one" , map ("two" , map ("three" , map ("four" , "five" )))
44
+ ))).shouldBeEqual ("Hello John, your code is <b>%{0%{invalid()}}</b> five" );
44
45
}
45
46
46
47
@ Test
47
48
public void shouldParseBuiltIn () throws Exception {
48
- List <TemplateNode > tokens = new TemplateParser ("<b>${article.content esc}</b>" ).parse ();
49
- a (tokens .size ()).shouldBeEqual (3 );
50
- Map values = map ("article" , map ("content" , "R&B" ));
51
- StringWriter sw = new StringWriter ();
52
- tokens .get (0 ).process (values , sw );
53
- tokens .get (1 ).process (values , sw );
54
- tokens .get (2 ).process (values , sw );
55
- the (sw .toString ()).shouldBeEqual ("<b>R&B</b>" );
49
+ List <TemplateNode > tokens = new TemplateParser ("<b>%{article.content esc}</b>" ).parse ();
50
+ the (tokens .size ()).shouldBeEqual (3 );
51
+ the (processAll (tokens , map ("article" , map ("content" , "R&B" )))).shouldBeEqual ("<b>R&B</b>" );
56
52
}
57
53
}
0 commit comments