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 org.apache.velocity.exception.VelocityException;
23 import org.apache.velocity.runtime.RuntimeConstants;
24
25
26
27
28
29 public class StrictCompareTestCase extends BaseTestCase
30 {
31 public StrictCompareTestCase(String name)
32 {
33 super(name);
34 }
35
36 public void setUp() throws Exception
37 {
38 super.setUp();
39 engine.setProperty(RuntimeConstants.RUNTIME_REFERENCES_STRICT, Boolean.TRUE);
40 context.put("NULL", null);
41 context.put("a", "abc");
42 context.put("b", new Integer(3));
43 context.put("TRUE", Boolean.TRUE);
44 }
45
46 public void testCompare()
47 {
48 assertVelocityEx("#if($a > $NULL)#end");
49 assertVelocityEx("#if($a < $NULL)#end");
50 assertVelocityEx("#if($a >= $NULL)#end");
51 assertVelocityEx("#if($a <= $NULL)#end");
52
53 assertVelocityEx("#if($NULL > $a)#end");
54 assertVelocityEx("#if($NULL < $a)#end");
55 assertVelocityEx("#if($NULL >= $a)#end");
56 assertVelocityEx("#if($NULL <= $a)#end");
57
58 assertVelocityEx("#if($NULL >= $NULL)#end");
59 assertVelocityEx("#if($a >= $b)#end");
60 assertVelocityEx("#if($a <= $b)#end");
61 assertVelocityEx("#if($a > $b)#end");
62 assertVelocityEx("#if($a < $b)#end");
63
64 assertVelocityEx("#if($a < 5)#end");
65 assertVelocityEx("#if($a > 5)#end");
66 }
67
68
69
70
71 public void assertVelocityEx(String template)
72 {
73 assertEvalException(template, VelocityException.class);
74 }
75 }