tests: add tests for multi-iterators
authorJean Privat <jean@pryen.org>
Wed, 7 Oct 2015 01:56:32 +0000 (21:56 -0400)
committerJean Privat <jean@pryen.org>
Wed, 7 Oct 2015 12:53:46 +0000 (08:53 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

tests/base_for_multi.nit [new file with mode: 0644]
tests/sav/base_for_multi.res [new file with mode: 0644]
tests/sav/base_for_multi_alt1.res [new file with mode: 0644]
tests/sav/test_comprehension.res
tests/test_comprehension.nit

diff --git a/tests/base_for_multi.nit b/tests/base_for_multi.nit
new file mode 100644 (file)
index 0000000..b71eafd
--- /dev/null
@@ -0,0 +1,46 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+var a = [10, 20, 30, 40]
+var m = new HashMap[Int, Int]
+m[1] = 11
+m[2] = 22
+m[3] = 33
+m[4] = 44
+
+0.output
+for i in a, j in [1..10[, k in a, l1, l2 in m do
+       i.output
+       j.output
+       k.output
+       l1.output
+       l2.output
+       '\n'.output
+end
+
+0.output
+for i in a, j in [1..10[, x in [0..0[, k in a, l1, l2 in m do
+       i.output
+       j.output
+       k.output
+       l1.output
+       l2.output
+       x.output
+       '\n'.output
+end
+0.output
+
+#alt1# for i in i do end
+#alt1# for i in j, j in [1..5] do end
+#alt1# for i in [1..2], j in i do end
diff --git a/tests/sav/base_for_multi.res b/tests/sav/base_for_multi.res
new file mode 100644 (file)
index 0000000..4ca5830
--- /dev/null
@@ -0,0 +1,27 @@
+0
+10
+1
+10
+1
+11
+
+20
+2
+20
+2
+22
+
+30
+3
+30
+3
+33
+
+40
+4
+40
+4
+44
+
+0
+0
diff --git a/tests/sav/base_for_multi_alt1.res b/tests/sav/base_for_multi_alt1.res
new file mode 100644 (file)
index 0000000..6327cc5
--- /dev/null
@@ -0,0 +1,3 @@
+alt/base_for_multi_alt1.nit:44,10: Error: method or variable `i` unknown in `Sys`.
+alt/base_for_multi_alt1.nit:45,10: Error: method or variable `j` unknown in `Sys`.
+alt/base_for_multi_alt1.nit:46,23: Error: method or variable `i` unknown in `Sys`.
index cdb7bd8..d0d25ad 100644 (file)
@@ -3,3 +3,4 @@
 12,14,32,34
 3,5,7,9
 11,12,13,14;21,22,23,24;31,32,33,34;41,42,43,44
+14,23,32,41
index 2d65d97..7af4ab2 100644 (file)
@@ -33,3 +33,7 @@ print a4.join(",")
 # Multi-dimensional
 var a5 = [for i in c1 do [for j in c1 do i*10+j]]
 print([for i in a5 do i.join(",")].join(";"))
+
+# Multi-iteration (zip)
+var a6 = [for i in c1, j in c1.reverse_iterator do i * 10 + j]
+print a6.join(",")