diff options
Diffstat (limited to 'tests/closure/tclosure.nim')
-rw-r--r-- | tests/closure/tclosure.nim | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/tests/closure/tclosure.nim b/tests/closure/tclosure.nim index 7e2ec7a77..401a71d40 100644 --- a/tests/closure/tclosure.nim +++ b/tests/closure/tclosure.nim @@ -1,5 +1,5 @@ discard """ - target: "c" + targets: "c" output: ''' 1 3 6 11 20 foo foo88 @@ -38,10 +38,10 @@ joinable: false block tclosure: - proc map(n: var openarray[int], fn: proc (x: int): int {.closure}) = + proc map(n: var openArray[int], fn: proc (x: int): int {.closure}) = for i in 0..n.len-1: n[i] = fn(n[i]) - proc each(n: openarray[int], fn: proc(x: int) {.closure.}) = + proc each(n: openArray[int], fn: proc(x: int) {.closure.}) = for i in 0..n.len-1: fn(n[i]) @@ -65,7 +65,7 @@ block tclosure: # bug #5015 - type Mutator = proc(matched: string): string {.noSideEffect, gcsafe, locks: 0.} + type Mutator = proc(matched: string): string {.noSideEffect, gcsafe.} proc putMutated( MutatorCount: static[int], @@ -239,19 +239,19 @@ block doNotation: b.onClick do (e: Event): echo "click at ", e.x, ",", e.y - b.onFocusLost: + b.onFocusLost do (): echo "lost focus 1" - b.onFocusLost do: + b.onFocusLost do (): echo "lost focus 2" - b.onUserEvent("UserEvent 1") do: + b.onUserEvent("UserEvent 1") do (): discard - b.onUserEvent "UserEvent 2": + onUserEvent(b, "UserEvent 2") do (): discard - b.onUserEvent("UserEvent 3"): + b.onUserEvent("UserEvent 3") do (): discard b.onUserEvent("UserEvent 4", () => echo "event 4") @@ -491,3 +491,14 @@ block tnoclosure: row = zip(row & @[0], @[0] & row).mapIt(it[0] + it[1]) echo row pascal(10) + +block: # bug #22297 + iterator f: int {.closure.} = + try: + yield 12 + finally: + return 14 + + let s = f + doAssert s() == 12 + doAssert s() == 14 |