summary refs log tree commit diff stats
path: root/tests/pragmas
diff options
context:
space:
mode:
authorawr1 <41453959+awr1@users.noreply.github.com>2018-09-04 16:33:52 -0500
committerGitHub <noreply@github.com>2018-09-04 16:33:52 -0500
commiteb668003bf35671d7358e5f54e05820c0f4aef3d (patch)
treee5c5d6315f8ba4a5dd647bf67a4d0afb609916e7 /tests/pragmas
parent89ad1cc9b18db8320e5b170ee45888cf79d52001 (diff)
parent4aba2981dd47672744191bd17b39bb149f494637 (diff)
downloadNim-eb668003bf35671d7358e5f54e05820c0f4aef3d.tar.gz
Merge branch 'devel' into experimentalize-reorder
Diffstat (limited to 'tests/pragmas')
-rw-r--r--tests/pragmas/mpushexperimental.nim30
-rw-r--r--tests/pragmas/t8741.nim10
-rw-r--r--tests/pragmas/tpushexperimental.nim13
3 files changed, 53 insertions, 0 deletions
diff --git a/tests/pragmas/mpushexperimental.nim b/tests/pragmas/mpushexperimental.nim
new file mode 100644
index 000000000..569861c1d
--- /dev/null
+++ b/tests/pragmas/mpushexperimental.nim
@@ -0,0 +1,30 @@
+
+import macros
+
+macro enumerate(x: ForLoopStmt): untyped =
+  expectKind x, nnkForStmt
+  # we strip off the first for loop variable and use
+  # it as an integer counter:
+  result = newStmtList()
+  result.add newVarStmt(x[0], newLit(0))
+  var body = x[^1]
+  if body.kind != nnkStmtList:
+    body = newTree(nnkStmtList, body)
+  body.add newCall(bindSym"inc", x[0])
+  var newFor = newTree(nnkForStmt)
+  for i in 1..x.len-3:
+    newFor.add x[i]
+  # transform enumerate(X) to 'X'
+  newFor.add x[^2][1]
+  newFor.add body
+  result.add newFor
+
+proc main*[T](x: T) =
+  {.push experimental: "forLoopMacros".}
+
+  for a, b in enumerate(items([1, 2, 3])):
+    echo a, " ", b
+
+  for a2, b2 in enumerate([1, 2, 3, 5]):
+    echo a2, " ", b2
+  {.pop.}
diff --git a/tests/pragmas/t8741.nim b/tests/pragmas/t8741.nim
new file mode 100644
index 000000000..41f2f9e8a
--- /dev/null
+++ b/tests/pragmas/t8741.nim
@@ -0,0 +1,10 @@
+discard """
+  line: 9
+  errormsg: "cannot attach a custom pragma to 'a'"
+"""
+
+for a {.gensym, inject.} in @[1,2,3]:
+  discard
+
+for a {.foobar.} in @[1,2,3]:
+  discard
diff --git a/tests/pragmas/tpushexperimental.nim b/tests/pragmas/tpushexperimental.nim
new file mode 100644
index 000000000..301419f60
--- /dev/null
+++ b/tests/pragmas/tpushexperimental.nim
@@ -0,0 +1,13 @@
+discard """
+  output: '''0 1
+1 2
+2 3
+0 1
+1 2
+2 3
+3 5'''
+"""
+
+import mpushexperimental
+
+main(12)