Add tests for recordFields being used with empty objects
This commit is contained in:
parent
bb705bf17b
commit
b87fd80b0f
|
@ -76,9 +76,13 @@ macro isTuple*(T: type): untyped =
|
|||
|
||||
proc skipRef*(T: NimNode): NimNode =
|
||||
result = T
|
||||
if T.kind == nnkBracketExpr:
|
||||
if eqIdent(T[0], bindSym"ref"):
|
||||
result = T[1]
|
||||
if T.kind == nnkBracketExpr and eqIdent(T[0], "ref"):
|
||||
result = T[1]
|
||||
|
||||
proc skipPtr*(T: NimNode): NimNode =
|
||||
result = T
|
||||
if T.kind == nnkBracketExpr and eqIdent(T[0], "ptr"):
|
||||
result = T[1]
|
||||
|
||||
template readPragma*(field: FieldDescription, pragmaName: static string): NimNode =
|
||||
let p = findPragma(field.pragmas, bindSym(pragmaName))
|
||||
|
|
|
@ -36,10 +36,14 @@ type
|
|||
DerivedFromRefType = ref object of DerivedType
|
||||
anotherDerivedField: string
|
||||
|
||||
EmptyObject = object
|
||||
EmptyRefObject = ref object
|
||||
EmptyPtrObject = ptr object
|
||||
|
||||
macro getFieldsLists(T: type): untyped =
|
||||
result = newTree(nnkBracket)
|
||||
|
||||
var resolvedType = skipRef getType(T)[1]
|
||||
var resolvedType = skipPtr skipRef getType(T)[1]
|
||||
doAssert resolvedType.kind == nnkSym
|
||||
var objectType = getImpl(resolvedType)
|
||||
doAssert objectType.kind == nnkTypeDef
|
||||
|
@ -56,6 +60,10 @@ static:
|
|||
"anotherDerivedField"
|
||||
]
|
||||
|
||||
doAssert getFieldsLists(EmptyObject).len == 0
|
||||
doAssert getFieldsLists(EmptyRefObject).len == 0
|
||||
doAssert getFieldsLists(EmptyPtrObject).len == 0
|
||||
|
||||
let myType = MyType[string](myField: "test", myGeneric: "test", kind: true, first: "test")
|
||||
|
||||
suite "Macros":
|
||||
|
|
Loading…
Reference in New Issue