1#* 2 3@test range.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 10Tests the range operator [n..m] 11 12*# 13[1..5] 14#foreach($i in [1..5]) $i #end 15 16----- 17[0..0] 18#foreach($i in [0..0]) $i #end 19 20----- 21[-4..-5] 22#foreach($i in [-4..-5]) $i #end 23 24----- 25[ 1 .. 5 ] 26#foreach($i in [ 1 .. 5 ]) $i #end 27 28----- 29[5..1] 30#foreach($i in [5..1]) $i #end 31 32----- 33[-5..5] 34#foreach($i in [-5..5]) $i #end 35 36----- 37[5..-5] 38#foreach($i in [5..-5]) $i #end 39 40----- 41#set($a = 1) 42#set($b = 5) 43refs \$a=$a \$b=$b [\$a..\$b] 44#foreach($i in [$a..$b]) $i #end 45 46----- 47#set($a = 1) 48#set($b = "5") 49refs \$a=$a \$b="$b" [\$a.."\$b"] 50#foreach($i in [$a..$b]) $i #end 51 52----- 53[\$a.. 7] 54#foreach($i in [$a.. 7]) $i #end 55 56----- 57[-7 ..\$a] 58#foreach($i in [-7 ..$a]) $i #end 59 60----- 61[ -7 ..\$a] 62#foreach($i in[ -7 ..$a]) $i #end 63 64------ 65#set($foo = [0..5]) 66setting in \$foo -> [0..5] : 67#foreach($i in $foo )$i #end 68 69---- 70 71Now some use-case examples. Suppose we want a table to have 10 rows 72 73#set($arr = ["a","b","c"]) 74 75<table> 76#foreach($i in $arr) 77<tr><td>$i</td></tr> 78#end 79#foreach($i in [4..10]) 80<tr><td> </td></tr> 81#end 82</table> 83 84---- 85Wide loop should not OOM 86#foreach($i in [0..67000000]) 87#if($i == 100) 88that's enough 89#break 90#end 91#end 92 93=done= 94