fix corner case with custom pragma (#42)
The AST changes when you call the same custom pragma more than once.
This commit is contained in:
parent
585059d2fb
commit
9826fddd1c
|
@ -78,7 +78,20 @@ proc shortEnumName(n: NimNode): NimNode =
|
|||
proc traversePragma(pragma: NimNode):
|
||||
tuple[isCommandOrArgument: bool, defaultValue, namePragma: string] =
|
||||
pragma.expectKind nnkPragma
|
||||
for child in pragma:
|
||||
var child: NimNode
|
||||
|
||||
for childNode in pragma:
|
||||
child = childNode
|
||||
|
||||
if child.kind == nnkCall:
|
||||
# A custom pragma was used more than once (e.g.: {.pragma: posixOnly, hidden.}) and the
|
||||
# AST is now:
|
||||
# ```
|
||||
# Call
|
||||
# Sym "hidden"
|
||||
# ```
|
||||
child = child[0]
|
||||
|
||||
case child.kind
|
||||
of nnkSym:
|
||||
let sym = $child
|
||||
|
|
|
@ -10,7 +10,8 @@
|
|||
import
|
||||
test_ignore,
|
||||
test_config_file,
|
||||
test_envvar
|
||||
test_envvar,
|
||||
test_pragma
|
||||
|
||||
when defined(windows):
|
||||
import test_winreg
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
import
|
||||
std/unittest,
|
||||
../confutils,
|
||||
../confutils/defs
|
||||
|
||||
{.pragma: customPragma, hidden.}
|
||||
|
||||
type
|
||||
TestConf* = object
|
||||
statusBarEnabled* {.
|
||||
customPragma
|
||||
desc: "Display a status bar at the bottom of the terminal screen"
|
||||
defaultValue: true
|
||||
name: "status-bar" }: bool
|
||||
|
||||
statusBarEnabled2* {.
|
||||
customPragma
|
||||
desc: "Display a status bar at the bottom of the terminal screen"
|
||||
defaultValue: true
|
||||
name: "status-bar2" }: bool
|
||||
|
||||
suite "test custom pragma":
|
||||
test "funny AST when called twice":
|
||||
let conf = TestConf.load()
|
||||
doAssert(conf.statusBarEnabled == true)
|
||||
doAssert(conf.statusBarEnabled2 == true)
|
||||
|
Loading…
Reference in New Issue