simple unit test and better documentation for the user defined type classes
This commit is contained in:
parent
4cea15d274
commit
a068aaed3c
8 changed files with 113 additions and 57 deletions
28
tests/run/tusertypeclasses.nim
Normal file
28
tests/run/tusertypeclasses.nim
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
discard """
|
||||
output: "Sortable\nSortable\nContainer"
|
||||
"""
|
||||
|
||||
import typetraits
|
||||
|
||||
type
|
||||
TObj = object
|
||||
x: int
|
||||
|
||||
Sortable = generic x, y
|
||||
(x < y) is bool
|
||||
|
||||
ObjectContainer = generic C
|
||||
C.len is ordinal
|
||||
for v in items(C):
|
||||
v.type is tuple|object
|
||||
|
||||
proc foo(c: ObjectContainer) =
|
||||
echo "Container"
|
||||
|
||||
proc foo(x: Sortable) =
|
||||
echo "Sortable"
|
||||
|
||||
foo 10
|
||||
foo "test"
|
||||
foo(@[TObj(x: 10), TObj(x: 20)])
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue