1 package org.apache.velocity.test.issues;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.velocity.test.BaseEvalTestCase;
23 import org.apache.velocity.VelocityContext;
24 import org.apache.velocity.runtime.RuntimeConstants;
25
26
27
28
29 public class Velocity615TestCase extends BaseEvalTestCase
30 {
31 public Velocity615TestCase(String name)
32 {
33 super(name);
34 }
35
36 public void setUp() throws Exception
37 {
38 super.setUp();
39 engine.setProperty("velocimacro.permissions.allow.inline", "true");
40 engine.setProperty("velocimacro.permissions.allow.inline.to.replace.global", "false");
41 engine.setProperty("velocimacro.permissions.allow.inline.local.scope", "true");
42 engine.setProperty("velocimacro.context.localscope", "false");
43 engine.setProperty("velocimacro.arguments.strict", "true");
44 }
45
46 public void testIt()
47 {
48 String template = "#set( $foo = 'old' )"+
49 "#macro( test $foo )"+
50 "#set( $foo = \"new $foo \" )"+
51 "$foo"+
52 "#end"+
53 "#test( 'foo' )"+
54 "$foo";
55 assertEvalEquals("new foo new foo ", template);
56 }
57
58 public void testForIrrationallyFearedRelatedPossibleProblem()
59 {
60 context.put("i", new Inc());
61 String template = "#macro( test $a )"+
62 "$a"+
63 "$a"+
64 "#end"+
65 "#test( \"$i\" )$i";
66 assertEvalEquals("012", template);
67 }
68
69 public void testForIrrationallyFearedRelatedPossibleProblem2()
70 {
71 context.put("i", new Inc());
72 String template = "#macro( test $a )"+
73 "#set( $a = 'a' )"+
74 "$a"+
75 "$a"+
76 "#end"+
77 "#test( \"$i\" )$i";
78 assertEvalEquals("aa0", template);
79 }
80
81 public void testForIrrationallyFearedRelatedPossibleProblem3()
82 {
83 context.put("i", new Inc());
84 String template = "#macro( test $a )"+
85 "$a"+
86 "$a"+
87 "#end"+
88 "#test( $i )$i";
89 assertEvalEquals("012", template);
90 }
91
92 public void testForIrrationallyFearedRelatedPossibleProblem4()
93 {
94 context.put("i", new Inc());
95 String template = "#macro( test $a )"+
96 "$a"+
97 "$a"+
98 "#end"+
99 "#test( $i.plus() )$i";
100 assertEvalEquals("012", template);
101 }
102
103 public void testForIrrationallyFearedRelatedPossibleProblem5()
104 {
105 context.put("i", new Inc());
106 String template = "#macro( test $a )"+
107 "#set( $a = $i )"+
108 "$a"+
109 "$a"+
110 "#end"+
111 "#test( 'a' )$i";
112 assertEvalEquals("012", template);
113 }
114
115 public static class Inc
116 {
117 private int i=0;
118
119 public int plus()
120 {
121 return i++;
122 }
123
124 public String toString()
125 {
126 return String.valueOf(i++);
127 }
128 }
129
130 }