mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-18 06:51:18 +00:00
simple unit test and better documentation for the user defined type classes
This commit is contained in:
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)])
|
||||
|
||||
Reference in New Issue
Block a user