1 package org.apache.velocity.test;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.StringWriter;
23
24 import junit.framework.Test;
25 import junit.framework.TestSuite;
26
27 import org.apache.velocity.VelocityContext;
28 import org.apache.velocity.app.VelocityEngine;
29 import org.apache.velocity.context.Context;
30
31
32
33
34
35
36
37 public class CommentsTestCase extends BaseTestCase
38 {
39
40 public static Test suite()
41 {
42 return new TestSuite(CommentsTestCase.class);
43 }
44
45
46
47
48
49 public CommentsTestCase(String name)
50 {
51 super(name);
52 }
53
54
55
56
57
58
59 public void testMultiLine()
60 throws Exception
61 {
62 VelocityEngine ve = new VelocityEngine();
63 ve.init();
64
65 Context context = new VelocityContext();
66 StringWriter writer = new StringWriter();
67 ve.evaluate(context, writer, "test","abc #* test\r\ntest2*#\r\ndef");
68 assertEquals("abc \r\ndef", writer.toString());
69 }
70
71
72
73
74
75 public void testSingleLine()
76 throws Exception
77 {
78 VelocityEngine ve = new VelocityEngine();
79 ve.init();
80
81 Context context = new VelocityContext();
82 StringWriter writer = new StringWriter();
83 ve.evaluate(context, writer, "test","123 ## test test\r\nabc");
84 assertEquals("123 abc", writer.toString());
85
86 context = new VelocityContext();
87 writer = new StringWriter();
88 ve.evaluate(context, writer, "test","123 \r\n## test test\r\nabc");
89 assertEquals("123 \r\nabc", writer.toString());
90
91 }
92
93
94
95
96
97 public void testCombined()
98 throws Exception
99 {
100 VelocityEngine ve = new VelocityEngine();
101 ve.init();
102
103 Context context = new VelocityContext();
104 StringWriter writer = new StringWriter();
105 ve.evaluate(context, writer, "test","test\r\n## #* *# ${user \r\nabc");
106 assertEquals("test\r\nabc", writer.toString());
107
108 }
109 }