summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2018-09-22 11:10:53 +0200
committerAraq <rumpf_a@web.de>2018-09-22 13:29:00 +0200
commit6892ce336cdc5e24080619512fab13f7d0194429 (patch)
tree6871072b3c1879cc59f3f626634fbfa2144cae40 /tests
parent3717e0e314d9eb67addd7455b4d2e3fbe264fe14 (diff)
downloadNim-6892ce336cdc5e24080619512fab13f7d0194429.tar.gz
enhance iterator test case, ensure consistency between inline and closure iterators regarding parameter passing semantics
Diffstat (limited to 'tests')
-rw-r--r--tests/iter/titer3.nim37
1 files changed, 35 insertions, 2 deletions
diff --git a/tests/iter/titer3.nim b/tests/iter/titer3.nim
index ab95dd7bd..cc603fd85 100644
--- a/tests/iter/titer3.nim
+++ b/tests/iter/titer3.nim
@@ -1,6 +1,14 @@
 discard """
   file: "titer3.nim"
-  output: "1231"
+  output: '''1231
+4
+6
+8
+--------
+4
+6
+8
+'''
 """
 
 iterator count1_3: int =
@@ -17,6 +25,31 @@ iterator iter1(a: openArray[int]): int =
 
 var x = [[1, 2, 3], [4, 5, 6]]
 for y in iter1(x[0]): write(stdout, $y)
+writeLine(stdout, "")
 
-#OUT 1231
+# ensure closure and inline iterators have the same behaviour wrt
+# parameter passing
 
+iterator clo(a: int): int {.closure.} =
+  yield 0+a
+  yield 1+a
+  yield 2+a
+
+iterator inl(a: int): int {.inline.} =
+  yield 0+a
+  yield 1+a
+  yield 2+a
+
+proc main =
+  var y = 4
+  for i in clo(y):
+    echo i
+    inc y
+
+  echo "--------"
+  y = 4
+  for i in inl(y):
+    echo i
+    inc y
+
+main()