aboutsummaryrefslogtreecommitdiff
path: root/velocity-engine-core/src/test/resources/templates/range.vm
blob: 4fdbb0213c17025cf25e2fc6dcbe8cef36c92715 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#*

@test range.vm

This template is used for Velocity regression testing.
If you alter this template make sure you change the
corresponding comparison file so that the regression 
test doesn't fail incorrectly.

Tests the range operator [n..m]

*#
[1..5]
#foreach($i in [1..5]) $i #end

-----
[0..0]
#foreach($i in [0..0]) $i #end

-----
[-4..-5]
#foreach($i in [-4..-5]) $i #end

-----
[ 1 .. 5 ]
#foreach($i in [ 1 .. 5 ]) $i #end

-----
[5..1]
#foreach($i in [5..1]) $i #end

-----
[-5..5]
#foreach($i in [-5..5]) $i #end

-----
[5..-5]
#foreach($i in [5..-5]) $i #end

-----
#set($a = 1)
#set($b = 5)
refs \$a=$a \$b=$b [\$a..\$b]
#foreach($i in [$a..$b]) $i #end

-----
#set($a = 1)
#set($b = "5")
refs \$a=$a \$b="$b" [\$a.."\$b"]
#foreach($i in [$a..$b]) $i #end

-----
[\$a.. 7]
#foreach($i in [$a.. 7]) $i #end

-----
[-7 ..\$a]
#foreach($i in [-7 ..$a]) $i #end

-----
[ -7 ..\$a]
#foreach($i in[ -7 ..$a]) $i #end

------
#set($foo = [0..5])
setting in \$foo -> [0..5] :
#foreach($i in $foo )$i #end

----

Now some use-case examples.  Suppose we want a table to have 10 rows

#set($arr = ["a","b","c"])

<table>
#foreach($i in $arr)
<tr><td>$i</td></tr>
#end
#foreach($i in [4..10])
<tr><td>&nbsp;</td></tr>
#end
</table>

----
Wide loop should not OOM
#foreach($i in [0..67000000])
#if($i == 100)
that's enough
#break
#end
#end

=done=