01: /*
02: * Copyright 2008 Gerd Ziegler (www.gerdziegler.de)
03: * Licensed under the Apache License, Version 2.0 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at
06: * http://www.apache.org/licenses/LICENSE-2.0
07: * Unless required by applicable law or agreed to in writing,
08: * software distributed under the License is distributed on an
09: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
10: * either express or implied. See the License for the specific
11: * language governing permissions and limitations under the License.
12: * 09.03.2008
13: * @author www.gerdziegler.de
14: */
15: package org.ztemplates.test.render.impl;
16:
17: import java.util.HashMap;
18: import java.util.Map;
19:
20: import junit.framework.TestCase;
21:
22: import org.ztemplates.render.impl.ZReplaceUtil;
23:
24: public class ReplaceUtilTest extends TestCase {
25: public void test1() throws Exception {
26: StringBuffer in = new StringBuffer("${var}");
27: Map<String, Object> map = new HashMap<String, Object>();
28: map.put("var", "katzeklo");
29: StringBuffer ret = ZReplaceUtil.replace(in, map);
30: assertEquals(ret.toString(), "katzeklo", ret.toString());
31: }
32:
33: public void test11() throws Exception {
34: StringBuffer in = new StringBuffer("${var}");
35: Map<String, Object> map = new HashMap<String, Object>();
36: StringBuffer ret = ZReplaceUtil.replace(in, map);
37: assertEquals(ret.toString(), "${var}", ret.toString());
38: }
39:
40: public void test12() throws Exception {
41: StringBuffer in = new StringBuffer("${}");
42: Map<String, Object> map = new HashMap<String, Object>();
43: StringBuffer ret = ZReplaceUtil.replace(in, map);
44: assertEquals(ret.toString(), "${}", ret.toString());
45: }
46:
47: public void test2() throws Exception {
48: StringBuffer in = new StringBuffer("--$--${var}--$-}");
49: Map<String, Object> map = new HashMap<String, Object>();
50: map.put("var", "katzeklo");
51: StringBuffer ret = ZReplaceUtil.replace(in, map);
52: assertEquals(ret.toString(), "--$--katzeklo--$-}", ret
53: .toString());
54: }
55:
56: public void test3() throws Exception {
57: StringBuffer in = new StringBuffer("--$--$-{var}--$-}");
58: Map<String, Object> map = new HashMap<String, Object>();
59: map.put("var", "katzeklo");
60: StringBuffer ret = ZReplaceUtil.replace(in, map);
61: assertEquals(ret.toString(), "--$--$-{var}--$-}", ret
62: .toString());
63: }
64:
65: public void test4() throws Exception {
66: StringBuffer in = new StringBuffer("--$--${var{--$-{");
67: Map<String, Object> map = new HashMap<String, Object>();
68: map.put("var", "katzeklo");
69: StringBuffer ret = ZReplaceUtil.replace(in, map);
70: assertEquals(ret.toString(), "--$--${var{--$-{", ret.toString());
71: }
72:
73: public void test5() throws Exception {
74: StringBuffer in = new StringBuffer("--$--${var{--$-}");
75: Map<String, Object> map = new HashMap<String, Object>();
76: StringBuffer ret = ZReplaceUtil.replace(in, map);
77: assertEquals(ret.toString(), "--$--${var{--$-}", ret.toString());
78: }
79: }
|