From baf4f8c9ebcf542fad62275f1513fd7ed62e777d Mon Sep 17 00:00:00 2001 From: Grzegorz Adam Hankiewicz Date: Sat, 6 Jul 2013 20:00:12 +0200 Subject: Documents idetools skMacro with failure test case. --- tests/caas/idetools_api.nim | 30 +++++++++++++++++++++++++++++- tests/caas/idetools_api.txt | 4 ++++ 2 files changed, 33 insertions(+), 1 deletion(-) (limited to 'tests') 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() diff --git a/tests/caas/idetools_api.txt b/tests/caas/idetools_api.txt index f4a2ee69e..3a350f60b 100644 --- a/tests/caas/idetools_api.txt +++ b/tests/caas/idetools_api.txt @@ -48,3 +48,7 @@ def\tskLabel\t$MODULE.findVowelPosition.loops\t\t # For some reason the use of the label with break displaces its position. > idetools --track:$TESTNIM,52,16 --def $SILENT def\tskLabel\t$MODULE.findVowelPosition.loops\t\t + +# Displaced macro usage by one character. +> idetools --track:$TESTNIM,80,2 --def $SILENT +def\tskMacro\t$MODULE.expect\tproc \(varargs\[expr\], stmt\): stmt\t -- cgit 1.4.1-2-gfad0 b01'/>
path: root/examples/htmlrefs.nim
blob: 8b668325f0a87d30c1c8c0bcb976104d39d36bf2 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14