diff options
author | Grzegorz Adam Hankiewicz <gradha@imap.cc> | 2013-07-06 20:00:12 +0200 |
---|---|---|
committer | Grzegorz Adam Hankiewicz <gradha@imap.cc> | 2013-07-06 20:00:12 +0200 |
commit | baf4f8c9ebcf542fad62275f1513fd7ed62e777d (patch) | |
tree | 8851cbcf5dcb1af9d5bec1d202dc4c4a272a598f /tests/caas/idetools_api.nim | |
parent | 383d047763a4ef336fca7e299dd36d0c71a29d58 (diff) | |
download | Nim-baf4f8c9ebcf542fad62275f1513fd7ed62e777d.tar.gz |
Documents idetools skMacro with failure test case.
Diffstat (limited to 'tests/caas/idetools_api.nim')
-rw-r--r-- | tests/caas/idetools_api.nim | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/tests/caas/idetools_api.nim b/tests/caas/idetools_api.nim index 351ec0583..7d27ffdf8 100644 --- a/tests/caas/idetools_api.nim +++ b/tests/caas/idetools_api.nim @@ -1,4 +1,4 @@ -import unicode, sequtils +import unicode, sequtils, macros proc test_enums() = var o: Tfile @@ -53,3 +53,31 @@ proc findVowelPosition(text: string) = echo found findVowelPosition("Zerg") # should output 1, position of vowel. + +macro expect*(exceptions: varargs[expr], body: stmt): stmt {.immediate.} = + ## Expect docstrings + let exp = callsite() + template expectBody(errorTypes, lineInfoLit: expr, + body: stmt): PNimrodNode {.dirty.} = + try: + body + assert false + except errorTypes: + nil + + var body = exp[exp.len - 1] + + var errorTypes = newNimNode(nnkBracket) + for i in countup(1, exp.len - 2): + errorTypes.add(exp[i]) + + result = getAst(expectBody(errorTypes, exp.lineinfo, body)) + +proc err = + raise newException(EArithmetic, "some exception") + +proc testMacro() = + expect(EArithmetic): + err() + +testMacro() |