1 package org.apache.velocity.test;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
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 * Test comments
33 *
34 * @author <a href="mailto:wglass@forio.com">Will Glass-Husain</a>
35 * @version $Id: CommentsTestCase.java 569256 2007-08-24 05:41:08Z wglass $
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 * Default constructor.
47 * @param name
48 */
49 public CommentsTestCase(String name)
50 {
51 super(name);
52 }
53
54
55 /**
56 * Test multiline comments
57 * @throws Exception
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 * Test single line comments
73 * @throws Exception
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 * Test combined comments
95 * @throws Exception
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 }