test cases for the new typedesc features
This commit is contained in:
parent
badb6c0f66
commit
c899b51b52
2 changed files with 28 additions and 2 deletions
|
|
@ -1,10 +1,12 @@
|
|||
import unittest
|
||||
import unittest, typetraits
|
||||
|
||||
type
|
||||
TFoo[T, U] = object
|
||||
x: T
|
||||
y: U
|
||||
|
||||
proc getTypeName(t: typedesc): string = t.name
|
||||
|
||||
proc foo(T: typedesc[float], a: expr): string =
|
||||
result = "float " & $(a.len > 5)
|
||||
|
||||
|
|
@ -21,6 +23,9 @@ template foo(T: typedesc[seq]): expr = "seq"
|
|||
test "types can be used as proc params":
|
||||
# XXX: `check` needs to know that TFoo[int, float] is a type and
|
||||
# cannot be assigned for a local variable for later inspection
|
||||
check ((string.getTypeName == "string"))
|
||||
check ((getTypeName(int) == "int"))
|
||||
|
||||
check ((foo(TFoo[int, float], 1000) == "TFoo 1000"))
|
||||
|
||||
var f = 10.0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue