summary refs log tree commit diff stats
path: root/tests/macros/tclosuremacro.nim
diff options
context:
space:
mode:
authorhlaaftana <10591326+hlaaftana@users.noreply.github.com>2020-05-03 11:22:49 +0300
committerGitHub <noreply@github.com>2020-05-03 10:22:49 +0200
commit3e060cfb0ab6b1affe26a7b09e6b4192e0d68a7f (patch)
tree40aa857657e65d3b1884297a78be40fdfa39c23c /tests/macros/tclosuremacro.nim
parentb56432bd8a56864679b21f4176717ad2f30e7b79 (diff)
downloadNim-3e060cfb0ab6b1affe26a7b09e6b4192e0d68a7f.tar.gz
=> supports pragmas & names (+ changed behavior) (#14200)
* => supports pragmas & names (+ changed behavior)

(x, y: int) is now parsed as (x: int, y: int) instead of
(x: auto, y: int) inside => and ->.

* fix pragma check

* fixes, use since & LHS of -> supports pragmas
Diffstat (limited to 'tests/macros/tclosuremacro.nim')
-rw-r--r--tests/macros/tclosuremacro.nim31
1 files changed, 15 insertions, 16 deletions
diff --git a/tests/macros/tclosuremacro.nim b/tests/macros/tclosuremacro.nim
index 9f2137dec..5c41c317a 100644
--- a/tests/macros/tclosuremacro.nim
+++ b/tests/macros/tclosuremacro.nim
@@ -1,19 +1,16 @@
 discard """
-  output: '''10
-10
-10
-3
-3
+  output: '''
 noReturn
-6
 calling mystuff
 yes
 calling mystuff
 yes
+calling sugarWithPragma
+sugarWithPragma called
 '''
 """
 
-import future, macros
+import sugar, macros
 
 proc twoParams(x: (int, int) -> int): int =
   result = x(5, 5)
@@ -30,23 +27,23 @@ proc noReturn(x: () -> void) =
 proc doWithOneAndTwo(f: (int, int) -> int): int =
   f(1,2)
 
-echo twoParams(proc (a, b: auto): auto = a + b)
-echo twoParams((x, y) => x + y)
-
-echo oneParam(x => x+5)
-
-echo noParams(() => 3)
-
-echo doWithOneAndTwo((x, y) => x + y)
+doAssert twoParams(proc (a, b: auto): auto = a + b) == 10
+doAssert twoParams((x, y) => x + y) == 10
+doAssert oneParam(x => x+5) == 10
+doAssert noParams(() => 3) == 3
+doAssert doWithOneAndTwo((x, y) => x + y) == 3
 
 noReturn((() -> void) => echo("noReturn"))
 
 proc pass2(f: (int, int) -> int): (int) -> int =
   ((x: int) -> int) => f(2, x)
 
-echo pass2((x, y) => x + y)(4)
+doAssert pass2((x, y) => x + y)(4) == 6
 
+fun(x, y: int) {.noSideEffect.} => x + y
 
+doAssert typeof(fun) is (proc (x, y: int): int {.nimcall.})
+doAssert fun(3, 4) == 7
 
 proc register(name: string; x: proc()) =
   echo "calling ", name
@@ -72,3 +69,5 @@ macro m(x: untyped): untyped =
 m:
   proc mystuff() =
     echo "yes"
+
+sugarWithPragma() {.m.} => echo "sugarWithPragma called"