diff options
author | Zahary Karadjov <zahary@gmail.com> | 2013-08-19 01:17:07 +0300 |
---|---|---|
committer | Zahary Karadjov <zahary@gmail.com> | 2013-08-19 01:17:07 +0300 |
commit | f127bc387a8e45635a9e4aa9208df4c8e8c0f276 (patch) | |
tree | e419605536a1cc1d3bcd14fe40c7b2f1f740e2fe /tests | |
parent | 50403afb5c8d49f2d9046498ea714251a3e4ad90 (diff) | |
download | Nim-f127bc387a8e45635a9e4aa9208df4c8e8c0f276.tar.gz |
Revert "Revert "test cases for the new features""
This reverts commit e1b668c868dbc647bb5da98d8e4769c2c9b351fd.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/compile/tgenericdefaults.nim | 29 | ||||
-rw-r--r-- | tests/compile/ttypeclasses.nim | 21 | ||||
-rw-r--r-- | tests/run/tstaticparams.nim | 17 |
3 files changed, 67 insertions, 0 deletions
diff --git a/tests/compile/tgenericdefaults.nim b/tests/compile/tgenericdefaults.nim new file mode 100644 index 000000000..ad96f1851 --- /dev/null +++ b/tests/compile/tgenericdefaults.nim @@ -0,0 +1,29 @@ +type + TFoo[T, U, R = int] = object + x: T + y: U + z: R + + TBar[T] = TFoo[T, array[4, T], T] + +var x1: TFoo[int, float] + +static: + assert type(x1.x) is int + assert type(x1.y) is float + assert type(x1.z) is int + +var x2: TFoo[string, R = float, U = seq[int]] + +static: + assert type(x2.x) is string + assert type(x2.y) is seq[int] + assert type(x2.z) is float + +var x3: TBar[float] + +static: + assert type(x3.x) is float + assert type(x3.y) is array[4, float] + assert type(x3.z) is float + diff --git a/tests/compile/ttypeclasses.nim b/tests/compile/ttypeclasses.nim index 5e23e8489..677229868 100644 --- a/tests/compile/ttypeclasses.nim +++ b/tests/compile/ttypeclasses.nim @@ -5,6 +5,8 @@ type T1 = expr T2 = expr + Numeric = int|float + proc takesExpr(x, y) = echo x, y @@ -32,3 +34,22 @@ takesFoo(f, f) takes2Types(1, 1, "string") takes2Types[string, int]("test", "test", 1) +proc takesSeq(x: seq) = + echo "seq" + +takesSeq(@[1, 2, 3]) +takesSeq(@["x", "y", "z"]) + +proc takesSeqOfFoos(x: seq[TFoo]) = + echo "foo seq" + +var sf = newSeq[TFoo[int]](3) + +takesSeq(sf) +takesSeqOfFoos(sf) + +proc takesFooOfNumeric(x: TFoo[Numeric]) = + echo "foo of numeric" + +takesFooOfNumeric(sf[0]) + diff --git a/tests/run/tstaticparams.nim b/tests/run/tstaticparams.nim new file mode 100644 index 000000000..3e501ed8b --- /dev/null +++ b/tests/run/tstaticparams.nim @@ -0,0 +1,17 @@ +discard """ + file: "tstaticparams.nim" + output: "abracadabra\ntest" +""" + +type + TFoo[T; Val: expr[string]] = object + data: array[4, T] + +proc takeFoo(x: TFoo) = + echo "abracadabra" + echo TFoo.Val + +var x: TFoo[int, "test"] + +takeFoo(x) + |