• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#**
2
3@test velocimacro.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## inline VM : shows how a tablerow might be generated
12
13#macro( tablerow  $array $color )
14#foreach( $element in $array )
15   <tr><tdi bgcolor=$color>$element</td></tr>
16#end
17#end
18
19Now, use the \#quietnull example from the global library VM_global_library.vm :
20Now, there should be nothing in the brackets : >#quietnull($nada)<
21
22#set($foo = "hello!")
23Where there should be something here : >#quietnull($foo)<
24
25#set($arr = ["$10.24","$15.32","$12.15"])
26#set($col = "blue")
27
28<table>
29#tablerow( $arr $col)
30</table>
31
32
33Further tests.  The following VMs and non-VM should be properly escaped :
34\#tablerow
35\#quietnull
36\#notavm
37>\\#quietnull($nada)<
38
39Now try to define a new quietnull VM :
40#macro( quietnull $a )
41	QuietNull : $a
42#end
43
44It should have been rejected, as the default is to not let inlines override existing, and there
45should be a message in velocity.log.
46Therefore it should still function normally :
47>#quietnull($foo)<
48>#quietnull($nada)<
49
50We should be able to use argless VMs (and directives....)
51#macro( noargs )
52Hello! I have no args!
53#end
54
55#noargs()
56
57
58And there was a bug where I wasn't getting the params right for the use-instance :
59
60#macro( showarg $i )
61Arg :>$i<
62#end
63
64#showarg( $jdom.getRootElement().getChild("properties").getChild("author").getTextTrim() )
65
66String literals should work as you expect :
67#showarg( "stringliteral")
68
69
70Test boolean args :
71
72#testbool(true)
73#testbool(false)
74
75Test map args :
76
77#macro(showmap $map $key)
78$map.get($key)
79#end
80
81#set($map = {"a":"aval", "b":"bval" } )
82#showmap($map "a")
83#showmap($map "b")
84
85#showmap({"a":"avalinline", "b":"bvalinline"} "a")
86#showmap({"a":"avalinline", "b":"bvalinline"} "b")
87
88- Another fine Velocity Production -
89