From: Jean Privat Date: Wed, 7 Oct 2015 01:56:32 +0000 (-0400) Subject: tests: add tests for multi-iterators X-Git-Tag: v0.7.9~39^2~3 X-Git-Url: http://nitlanguage.org tests: add tests for multi-iterators Signed-off-by: Jean Privat --- diff --git a/tests/base_for_multi.nit b/tests/base_for_multi.nit new file mode 100644 index 0000000..b71eafd --- /dev/null +++ b/tests/base_for_multi.nit @@ -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 index 0000000..4ca5830 --- /dev/null +++ b/tests/sav/base_for_multi.res @@ -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 index 0000000..6327cc5 --- /dev/null +++ b/tests/sav/base_for_multi_alt1.res @@ -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`. diff --git a/tests/sav/test_comprehension.res b/tests/sav/test_comprehension.res index cdb7bd8..d0d25ad 100644 --- a/tests/sav/test_comprehension.res +++ b/tests/sav/test_comprehension.res @@ -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 diff --git a/tests/test_comprehension.nit b/tests/test_comprehension.nit index 2d65d97..7af4ab2 100644 --- a/tests/test_comprehension.nit +++ b/tests/test_comprehension.nit @@ -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(",")