• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#*
2
3@test interpolation.vm
4
5This template is used for Velocity regression testing.
6If you alter this template make sure you change the
7corresponding comparison file so that the regression
8test doesn't fail incorrectly.
9
10*#
11
12Start with simple string interpolation :
13
14#set($name = "jason")
15$provider.concat("it will cost you $10.00", "")
16
17#set($image = "dog")
18$provider.concat("${image}.jpg", "")
19
20#set($foo_bar = "foobar")
21$provider.concat("${foo_bar}.jpg", "")
22
23#set($foo__bar = "foobar")
24$provider.concat("${foo__bar}.jpg", "")
25
26#set($one = 1)
27#set($two = 2)
28#set($three = 3)
29$provider.concat("${one}${two}${three}", "")
30$provider.concat("$one $two $three", "")
31
32How about a directive?  Sure :
33
34#set($arr = ["a","b","c"])
35#set($foo = "#foreach($a in $arr) >$a< #end")
36
37$foo
38
39For our next trick, lets interpolate a.... VelociMacro!
40
41#macro( interpfoo )
42  Hi, I'm a VM!
43#end
44
45#set($ivm = "#interpfoo()")
46
47$ivm
48
49And now, for something completely different :
50
51#set($code = "#if(false) True #else False #end")
52
53$code
54
55Now, non interpolated stringlits :
56
57#set($a = "$code")
58#set($b = '$code')
59#set($c = '$!$\!code')
60
61$a
62$b
63$c
64
65Now, check comments within strings.  double quotes they should be removed.
66Single quotes, they should be kept literal.
67
68#set($c1 = "test##test")
69#set($c2 = "test ##test")
70#set($c3 = "##test")
71#set($c4 = "test#* hello *#test")
72#set($c5 = 'test##test')
73#set($c6 = 'test#* hello *#test')
74
75$c1
76$c2
77$c3
78$c4
79$c5
80$c6
81
82-- end --
83