mirror of
https://github.com/status-im/nim-stew.git
synced 2025-01-24 10:59:13 +00:00
Add tests for recordFields being used with empty objects
This commit is contained in:
parent
bb705bf17b
commit
b87fd80b0f
@ -76,8 +76,12 @@ macro isTuple*(T: type): untyped =
|
|||||||
|
|
||||||
proc skipRef*(T: NimNode): NimNode =
|
proc skipRef*(T: NimNode): NimNode =
|
||||||
result = T
|
result = T
|
||||||
if T.kind == nnkBracketExpr:
|
if T.kind == nnkBracketExpr and eqIdent(T[0], "ref"):
|
||||||
if eqIdent(T[0], bindSym"ref"):
|
result = T[1]
|
||||||
|
|
||||||
|
proc skipPtr*(T: NimNode): NimNode =
|
||||||
|
result = T
|
||||||
|
if T.kind == nnkBracketExpr and eqIdent(T[0], "ptr"):
|
||||||
result = T[1]
|
result = T[1]
|
||||||
|
|
||||||
template readPragma*(field: FieldDescription, pragmaName: static string): NimNode =
|
template readPragma*(field: FieldDescription, pragmaName: static string): NimNode =
|
||||||
|
@ -36,10 +36,14 @@ type
|
|||||||
DerivedFromRefType = ref object of DerivedType
|
DerivedFromRefType = ref object of DerivedType
|
||||||
anotherDerivedField: string
|
anotherDerivedField: string
|
||||||
|
|
||||||
|
EmptyObject = object
|
||||||
|
EmptyRefObject = ref object
|
||||||
|
EmptyPtrObject = ptr object
|
||||||
|
|
||||||
macro getFieldsLists(T: type): untyped =
|
macro getFieldsLists(T: type): untyped =
|
||||||
result = newTree(nnkBracket)
|
result = newTree(nnkBracket)
|
||||||
|
|
||||||
var resolvedType = skipRef getType(T)[1]
|
var resolvedType = skipPtr skipRef getType(T)[1]
|
||||||
doAssert resolvedType.kind == nnkSym
|
doAssert resolvedType.kind == nnkSym
|
||||||
var objectType = getImpl(resolvedType)
|
var objectType = getImpl(resolvedType)
|
||||||
doAssert objectType.kind == nnkTypeDef
|
doAssert objectType.kind == nnkTypeDef
|
||||||
@ -56,6 +60,10 @@ static:
|
|||||||
"anotherDerivedField"
|
"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")
|
let myType = MyType[string](myField: "test", myGeneric: "test", kind: true, first: "test")
|
||||||
|
|
||||||
suite "Macros":
|
suite "Macros":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user