nim-stew/tests/test_objects.nim

55 lines
1.0 KiB
Nim
Raw Normal View History

2020-04-22 12:41:42 +00:00
import
unittest, typetraits,
2020-03-29 15:34:45 +00:00
../stew/objects
when defined(nimHasUsed):
{.used.}
suite "Objects":
test "baseType":
type
Foo = ref object of RootObj
Bar = ref object of Foo
Baz = object of RootObj
Bob = object of Baz
Bill = ref object of Bob
var
foo = Foo()
bar = Bar()
baz = Baz()
bob = Bob()
bill = Bill()
when defined(nimTypeNames):
check:
foo.baseType == "Foo:ObjectType"
bar.baseType == "Bar:ObjectType"
baz.baseType == "Baz"
bob.baseType == "Bob"
bill.baseType == "Bill:ObjectType"
proc f(o: Foo) =
check $o.type == "Foo"
check o.baseType == "Bar:ObjectType"
f(bar)
2020-04-22 12:41:42 +00:00
test "declval":
proc foo(x: int): string =
discard
proc foo(x: var int): float =
discard
type
T1 = typeof foo(declval(int))
T2 = typeof foo(declval(var int))
T3 = typeof foo(declval(lent int))
check:
T1 is string
T2 is float
T3 is string