This commit is contained in:
Andreas Rumpf 2016-07-22 12:29:05 +02:00
commit fc0bb82802
2 changed files with 34 additions and 25 deletions

View file

@ -259,31 +259,34 @@ macro check*(conditions: stmt): stmt {.immediate.} =
proc inspectArgs(exp: NimNode): NimNode = proc inspectArgs(exp: NimNode): NimNode =
result = copyNimTree(exp) result = copyNimTree(exp)
for i in countup(1, exp.len - 1): if exp[0].kind == nnkIdent and
if exp[i].kind notin nnkLiterals: $exp[0] in ["and", "or", "not", "in", "notin", "==", "<=",
inc counter ">=", "<", ">", "!=", "is", "isnot"]:
var arg = newIdentNode(":p" & $counter) for i in countup(1, exp.len - 1):
var argStr = exp[i].toStrLit if exp[i].kind notin nnkLiterals:
var paramAst = exp[i] inc counter
if exp[i].kind == nnkIdent: var arg = newIdentNode(":p" & $counter)
argsPrintOuts.add getAst(print(argStr, paramAst)) var argStr = exp[i].toStrLit
if exp[i].kind in nnkCallKinds: var paramAst = exp[i]
var callVar = newIdentNode(":c" & $counter) if exp[i].kind == nnkIdent:
argsAsgns.add getAst(asgn(callVar, paramAst)) argsPrintOuts.add getAst(print(argStr, paramAst))
result[i] = callVar if exp[i].kind in nnkCallKinds:
argsPrintOuts.add getAst(print(argStr, callVar)) var callVar = newIdentNode(":c" & $counter)
if exp[i].kind == nnkExprEqExpr: argsAsgns.add getAst(asgn(callVar, paramAst))
# ExprEqExpr result[i] = callVar
# Ident !"v" argsPrintOuts.add getAst(print(argStr, callVar))
# IntLit 2 if exp[i].kind == nnkExprEqExpr:
result[i] = exp[i][1] # ExprEqExpr
if exp[i].typekind notin {ntyTypeDesc}: # Ident !"v"
argsAsgns.add getAst(asgn(arg, paramAst)) # IntLit 2
argsPrintOuts.add getAst(print(argStr, arg)) result[i] = exp[i][1]
if exp[i].kind != nnkExprEqExpr: if exp[i].typekind notin {ntyTypeDesc}:
result[i] = arg argsAsgns.add getAst(asgn(arg, paramAst))
else: argsPrintOuts.add getAst(print(argStr, arg))
result[i][1] = arg if exp[i].kind != nnkExprEqExpr:
result[i] = arg
else:
result[i][1] = arg
case checked.kind case checked.kind
of nnkCallKinds: of nnkCallKinds:

View file

@ -83,3 +83,9 @@ suite "suite with both":
test "unittest with both 2": test "unittest with both 2":
check c == 2 check c == 2
suite "bug #4494":
test "Uniqueness check":
var tags = @[1, 2, 3, 4, 5]
check:
allIt(0..3, tags[it] != tags[it + 1])