Documents idetools skMacro with failure test case.
This commit is contained in:
parent
383d047763
commit
baf4f8c9eb
3 changed files with 53 additions and 1 deletions
|
|
@ -326,6 +326,26 @@ skLet
|
||||||
col 7: ""
|
col 7: ""
|
||||||
|
|
||||||
|
|
||||||
|
skMacro
|
||||||
|
-------
|
||||||
|
|
||||||
|
The fourth column will be the empty string if the macro is being
|
||||||
|
defined, since at that point in the file the parser hasn't processed
|
||||||
|
the full line yet. The signature will be returned complete in
|
||||||
|
posterior instances of the macro.
|
||||||
|
|
||||||
|
| **Third column**: module + [n scope nesting] + macro name.
|
||||||
|
| **Fourth column**: signature of the macro including return type.
|
||||||
|
| **Docstring**: docstring if available.
|
||||||
|
|
||||||
|
.. code-block:: nimrod
|
||||||
|
proc testMacro() =
|
||||||
|
expect(EArithmetic):
|
||||||
|
--> col 2: idetools_api.expect
|
||||||
|
col 3: proc (varargs[expr], stmt): stmt
|
||||||
|
col 7: ""
|
||||||
|
|
||||||
|
|
||||||
skMethod
|
skMethod
|
||||||
--------
|
--------
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import unicode, sequtils
|
import unicode, sequtils, macros
|
||||||
|
|
||||||
proc test_enums() =
|
proc test_enums() =
|
||||||
var o: Tfile
|
var o: Tfile
|
||||||
|
|
@ -53,3 +53,31 @@ proc findVowelPosition(text: string) =
|
||||||
echo found
|
echo found
|
||||||
|
|
||||||
findVowelPosition("Zerg") # should output 1, position of vowel.
|
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()
|
||||||
|
|
|
||||||
|
|
@ -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.
|
# For some reason the use of the label with break displaces its position.
|
||||||
> idetools --track:$TESTNIM,52,16 --def $SILENT
|
> idetools --track:$TESTNIM,52,16 --def $SILENT
|
||||||
def\tskLabel\t$MODULE.findVowelPosition.loops\t\t
|
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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue