mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-20 14:25:23 +00:00
Fixed broken test. Added closureScope test.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user