Fixed broken test. Added closureScope test.
This commit is contained in:
parent
ecfcf49a9d
commit
e61cfea78b
2 changed files with 16 additions and 2 deletions
|
|
@ -1 +1,4 @@
|
|||
discard """
|
||||
output: ""
|
||||
"""
|
||||
import "../template/utemplates", "../closure/uclosures"
|
||||
|
|
|
|||
|
|
@ -1,12 +1,23 @@
|
|||
# This test is included from within tunittests
|
||||
import unittest
|
||||
|
||||
test "loop variables are captured by copy":
|
||||
test "loop variables are captured by ref":
|
||||
var funcs: seq[proc (): int {.closure.}] = @[]
|
||||
|
||||
for i in 0..10:
|
||||
let ii = i
|
||||
funcs.add do -> int: return ii * ii
|
||||
|
||||
check funcs[0]() == 100
|
||||
check funcs[3]() == 100
|
||||
|
||||
test "loop variables in closureScope are captured by copy":
|
||||
var funcs: seq[proc (): int {.closure.}] = @[]
|
||||
|
||||
for i in 0..10:
|
||||
closureScope:
|
||||
let ii = i
|
||||
funcs.add do -> int: return ii * ii
|
||||
|
||||
check funcs[0]() == 0
|
||||
check funcs[3]() == 9
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue