Make einheit work for newest nim
This commit is contained in:
parent
58380fdc79
commit
c2f7e68742
1 changed files with 45 additions and 23 deletions
|
|
@ -43,6 +43,7 @@ template tupleObjToStr(obj): string {.dirty.} =
|
||||||
res.add("(")
|
res.add("(")
|
||||||
var firstElement = true
|
var firstElement = true
|
||||||
for name, value in n.fieldPairs():
|
for name, value in n.fieldPairs():
|
||||||
|
when compiles(value):
|
||||||
if not firstElement:
|
if not firstElement:
|
||||||
res.add(", ")
|
res.add(", ")
|
||||||
res.add(name)
|
res.add(name)
|
||||||
|
|
@ -207,6 +208,21 @@ template recursive(node, action): untyped {.dirty.} =
|
||||||
result.add helper(c)
|
result.add helper(c)
|
||||||
discard helper(node)
|
discard helper(node)
|
||||||
|
|
||||||
|
proc getNode(nodeKind: NimNodeKind, node: NimNode): NimNode =
|
||||||
|
## Gets the first node with nodeKind
|
||||||
|
var stack: seq[NimNode] = @[node]
|
||||||
|
|
||||||
|
while stack.len() > 0:
|
||||||
|
let newNode = stack.pop()
|
||||||
|
for i in 0 ..< newNode.len():
|
||||||
|
let child = newNode[i]
|
||||||
|
if child.kind == nodeKind:
|
||||||
|
return child
|
||||||
|
else:
|
||||||
|
stack.add(child)
|
||||||
|
|
||||||
|
return newEmptyNode()
|
||||||
|
|
||||||
template strRep(n: NimNode): untyped =
|
template strRep(n: NimNode): untyped =
|
||||||
toString(n)
|
toString(n)
|
||||||
|
|
||||||
|
|
@ -240,7 +256,7 @@ macro getSyms(code:untyped): untyped =
|
||||||
tableConstr.add(tableEntry(ch1))
|
tableConstr.add(tableEntry(ch1))
|
||||||
if ch1.len() > 0 and ch1[0].kind == nnkDotExpr:
|
if ch1.len() > 0 and ch1[0].kind == nnkDotExpr:
|
||||||
tableConstr.add(tableEntry(ch1[0][0]))
|
tableConstr.add(tableEntry(ch1[0][0]))
|
||||||
for i in 1..<ch1.len():
|
for i in 1 ..< ch1.len():
|
||||||
tableConstr.add(tableEntry(ch1[i]))
|
tableConstr.add(tableEntry(ch1[i]))
|
||||||
of nnkDotExpr:
|
of nnkDotExpr:
|
||||||
tableConstr.add(tableEntry(ch1))
|
tableConstr.add(tableEntry(ch1))
|
||||||
|
|
@ -450,7 +466,12 @@ macro testSuite*(head: untyped, body: untyped): untyped =
|
||||||
var baseMethodName = ident("runTests" & $baseName.toStrLit())
|
var baseMethodName = ident("runTests" & $baseName.toStrLit())
|
||||||
var typeMethodName = ident("runTests" & $typeName.toStrLit())
|
var typeMethodName = ident("runTests" & $typeName.toStrLit())
|
||||||
|
|
||||||
var runTests = getAst(runTestsProc(ident(objReference), typeName, baseMethodName, typeMethodName))
|
var runTests = getAst(
|
||||||
|
runTestsProc(
|
||||||
|
ident(objReference), typeName,
|
||||||
|
baseMethodName, typeMethodName
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
var
|
var
|
||||||
foundSetup = false
|
foundSetup = false
|
||||||
|
|
@ -514,11 +535,11 @@ macro testSuite*(head: untyped, body: untyped): untyped =
|
||||||
when compiles(self.baseMethod()):
|
when compiles(self.baseMethod()):
|
||||||
self.baseMethod()
|
self.baseMethod()
|
||||||
|
|
||||||
|
|
||||||
var setupProcTypename = ident("setup" & $typeName.toStrLit())
|
var setupProcTypename = ident("setup" & $typeName.toStrLit())
|
||||||
var baseMethodName = ident("setup" & $baseName.toStrLit())
|
var baseMethodName = ident("setup" & $baseName.toStrLit())
|
||||||
result.add(getAst(setupProc(ident(objReference), typeName, setupProcTypename)))
|
result.add(getAst(setupProc(ident(objReference), typeName, setupProcTypename)))
|
||||||
var setupBaseAst = getAst(setupDecl(ident(objReference), baseMethodName))
|
body.add(getAst(setupDecl(ident(objReference), baseMethodName)))
|
||||||
body.add(setupBaseAst[0])
|
|
||||||
|
|
||||||
if not foundTeardown:
|
if not foundTeardown:
|
||||||
template teardownProc(self, typeName, tdProc) =
|
template teardownProc(self, typeName, tdProc) =
|
||||||
|
|
@ -535,9 +556,8 @@ macro testSuite*(head: untyped, body: untyped): untyped =
|
||||||
result.add(getAst(teardownProc(ident(objReference),
|
result.add(getAst(teardownProc(ident(objReference),
|
||||||
typeName,
|
typeName,
|
||||||
teardownProcTypename)))
|
teardownProcTypename)))
|
||||||
var teardownBaseAst = getAst(teardownDecl(ident(objReference),
|
body.add(getAst(teardownDecl(ident(objReference),
|
||||||
baseTearMethodName))
|
baseTearMethodName)))
|
||||||
body.add(teardownBaseAst[0])
|
|
||||||
|
|
||||||
template setTestName(self, procName) =
|
template setTestName(self, procName) =
|
||||||
self.currentTestName = procName
|
self.currentTestName = procName
|
||||||
|
|
@ -719,7 +739,9 @@ macro testSuite*(head: untyped, body: untyped): untyped =
|
||||||
# OfInherit
|
# OfInherit
|
||||||
# Ident !"RootObj"
|
# Ident !"RootObj"
|
||||||
# Empty <= We want to replace this
|
# Empty <= We want to replace this
|
||||||
typeDecl[0][0][2][0][2] = recList
|
|
||||||
|
var objTyNode = getNode(nnkObjectTy, typeDecl)
|
||||||
|
objTyNode[2] = recList
|
||||||
|
|
||||||
# insert the type declaration
|
# insert the type declaration
|
||||||
result.insert(0, typeDecl)
|
result.insert(0, typeDecl)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue