You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by ge...@locus.apache.org on 2000/12/28 17:23:29 UTC
cvs commit: jakarta-velocity/test/templates/compare range.cmp
geirm 00/12/28 08:23:26
Modified: test test.properties
Added: test/templates range.vm
test/templates/compare range.cmp
Log:
Testbed support for the range operator [n..m]
Revision Changes Path
1.21 +1 -0 jakarta-velocity/test/test.properties
Index: test.properties
===================================================================
RCS file: /home/cvs/jakarta-velocity/test/test.properties,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- test.properties 2000/12/27 14:29:05 1.20
+++ test.properties 2000/12/28 16:23:13 1.21
@@ -33,3 +33,4 @@
test.template.31 = literal
test.template.32 = ifstatement
test.template.33 = math
+test.template.34 = range
1.1 jakarta-velocity/test/templates/range.vm
Index: range.vm
===================================================================
#*
@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
-----
[\$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> </td></tr>
#end
</table>
=done=
1.1 jakarta-velocity/test/templates/compare/range.cmp
Index: range.cmp
===================================================================
[1..5]
1 2 3 4 5
-----
[0..0]
0
-----
[-4..-5]
-4 -5
-----
[ 1 .. 5 ]
1 2 3 4 5
-----
[5..1]
5 4 3 2 1
-----
[-5..5]
-5 -4 -3 -2 -1 0 1 2 3 4 5
-----
[5..-5]
5 4 3 2 1 0 -1 -2 -3 -4 -5
-----
refs $a=1 $b=5 [$a..$b]
1 2 3 4 5
-----
[$a.. 7]
1 2 3 4 5 6 7
-----
[-7 ..$a]
-7 -6 -5 -4 -3 -2 -1 0 1
-----
[ -7 ..$a]
-7 -6 -5 -4 -3 -2 -1 0 1
------
setting in $foo -> [0..5] :
0 1 2 3 4 5
----
Now some use-case examples. Suppose we want a table to have 10 rows
<table>
<tr><td>a</td></tr>
<tr><td>b</td></tr>
<tr><td>c</td></tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
</table>
=done=