diff options
author | Jasper Jenkins <jasper.vs.jenkins@gmail.com> | 2019-05-13 11:50:21 -0700 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2019-05-13 20:50:21 +0200 |
commit | 6fc74cec55b75291ad8e3f7735f8d2134505321a (patch) | |
tree | fe76a45da968cfffa4a275a7ecc059fc09e8d29b /tests/iter | |
parent | fb1c3a95a5288bd3bd3986a3f5055e979f4a5106 (diff) | |
download | Nim-6fc74cec55b75291ad8e3f7735f8d2134505321a.tar.gz |
Iterator fixes (#11234)
Diffstat (limited to 'tests/iter')
-rw-r--r-- | tests/iter/titer13.nim | 72 | ||||
-rw-r--r-- | tests/iter/titerassignerr.nim | 8 | ||||
-rw-r--r-- | tests/iter/titerautoerr1.nim | 8 | ||||
-rw-r--r-- | tests/iter/titerautoerr2.nim | 8 | ||||
-rw-r--r-- | tests/iter/titerautoerr3.nim | 9 |
5 files changed, 105 insertions, 0 deletions
diff --git a/tests/iter/titer13.nim b/tests/iter/titer13.nim new file mode 100644 index 000000000..716f59900 --- /dev/null +++ b/tests/iter/titer13.nim @@ -0,0 +1,72 @@ +discard """ + output: '''b yields +c yields +a returns +b yields +b returns +c yields + + +1 +2 +3 +4 +''' +""" + +block: + template tloop(iter: untyped) = + for i in iter(): + echo i + + template twhile(iter: untyped) = + let it = iter + while not finished(it): + echo it() + + iterator a(): auto {.closure.} = + if true: return "a returns" + yield "a yields" + + iterator b(): auto {.closure.} = + yield "b yields" + if true: return "b returns" + + iterator c(): auto {.closure.} = + yield "c yields" + if true: return + + iterator d(): auto {.closure.} = + if true: return + yield "d yields" + + tloop(a) + tloop(b) + tloop(c) + tloop(d) + twhile(a) + twhile(b) + twhile(c) + twhile(d) + +block: + iterator a: auto = + yield 1 + for x in a(): + echo x + + let b = iterator: int = + yield 2 + for x in b(): + echo x + + let c = iterator: auto = + yield 3 + for x in c(): + echo x + +block: + iterator myIter2(): auto {.closure.} = + yield 4 + for a in myIter2(): + echo a diff --git a/tests/iter/titerassignerr.nim b/tests/iter/titerassignerr.nim new file mode 100644 index 000000000..caa56c4ad --- /dev/null +++ b/tests/iter/titerassignerr.nim @@ -0,0 +1,8 @@ +discard """ + errormsg: "inline iterators are not first-class / cannot be assigned to variables" + line: 8 +""" + +iterator foo: int = + yield 2 +let x = foo diff --git a/tests/iter/titerautoerr1.nim b/tests/iter/titerautoerr1.nim new file mode 100644 index 000000000..c7e5642c8 --- /dev/null +++ b/tests/iter/titerautoerr1.nim @@ -0,0 +1,8 @@ +discard """ + errormsg: "type mismatch: got <int literal(1)> but expected 'string'" + line: 8 +""" + +iterator a(): auto {.closure.} = + if true: return "str" + yield 1 diff --git a/tests/iter/titerautoerr2.nim b/tests/iter/titerautoerr2.nim new file mode 100644 index 000000000..eb48a36f9 --- /dev/null +++ b/tests/iter/titerautoerr2.nim @@ -0,0 +1,8 @@ +discard """ + errormsg: "type mismatch: got <string> but expected 'int literal(1)'" + line: 8 +""" + +iterator b(): auto {.closure.} = + yield 1 + if true: return "str" diff --git a/tests/iter/titerautoerr3.nim b/tests/iter/titerautoerr3.nim new file mode 100644 index 000000000..e47b65540 --- /dev/null +++ b/tests/iter/titerautoerr3.nim @@ -0,0 +1,9 @@ +discard """ + errormsg: "cannot infer the return type of 'bar'" + line: 6 +""" + +iterator bar(): auto = + discard +for t in bar(): + discard |