diff options
author | Araq <rumpf_a@web.de> | 2014-06-26 15:58:41 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2014-06-26 15:58:41 +0200 |
commit | eed443d4b390b10e710d80619f5a7bc19fefb8d1 (patch) | |
tree | 2afd2ae53f92ec92d30596ebfc718bc599542829 /tests | |
parent | e712dbaef55070fd418e66f2a069f5c94714da7d (diff) | |
download | Nim-eed443d4b390b10e710d80619f5a7bc19fefb8d1.tar.gz |
rewrote lambdalifting; fixes deeply nested closures
Diffstat (limited to 'tests')
-rw-r--r-- | tests/closure/tclosure.nim | 8 | ||||
-rw-r--r-- | tests/closure/tnestedclosure.nim | 36 |
2 files changed, 40 insertions, 4 deletions
diff --git a/tests/closure/tclosure.nim b/tests/closure/tclosure.nim index d9e7b8ee4..764aaa97d 100644 --- a/tests/closure/tclosure.nim +++ b/tests/closure/tclosure.nim @@ -1,7 +1,6 @@ discard """ file: "tclosure.nim" - output: "2 4 6 8 10" - disabled: true + output: "1 3 6 11 20" """ # Test the closure implementation @@ -30,7 +29,8 @@ proc testA() = testA() myData.each do (x: int): - write(stout, x) + write(stdout, x) + write(stdout, " ") #OUT 2 4 6 8 10 @@ -42,6 +42,6 @@ type proc getInterf(): ITest = var shared: int - return (setter: proc (x) = shared = x, + return (setter: proc (x: int) = shared = x, getter: proc (): int = return shared) diff --git a/tests/closure/tnestedclosure.nim b/tests/closure/tnestedclosure.nim new file mode 100644 index 000000000..6a76e003e --- /dev/null +++ b/tests/closure/tnestedclosure.nim @@ -0,0 +1,36 @@ +discard """ + output: '''foo88 +23 24foo 88 +foo88 +23 24foo 88''' +""" + +# test nested closure +proc main(param: int) = + var foo = 23 + proc outer(outerParam: string) = + var outerVar = 88 + echo outerParam, outerVar + proc inner() = + block Test: + echo foo, " ", param, outerParam, " ", outerVar + inner() + outer("foo") + +# test simple closure within dummy 'main': +proc dummy = + proc main2(param: int) = + var foo = 23 + proc outer(outerParam: string) = + var outerVar = 88 + echo outerParam, outerVar + proc inner() = + block Test: + echo foo, " ", param, outerParam, " ", outerVar + inner() + outer("foo") + main2(24) + +dummy() + +main(24) |