diff options
Diffstat (limited to 'tests/concepts/tmanual.nim')
-rw-r--r-- | tests/concepts/tmanual.nim | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/concepts/tmanual.nim b/tests/concepts/tmanual.nim new file mode 100644 index 000000000..c917f5022 --- /dev/null +++ b/tests/concepts/tmanual.nim @@ -0,0 +1,42 @@ +discard """ + output: '''1 +2 +3 +4 +5 +6 +a +b +t +e +s +t +''' +""" + +template accept(e) = + static: assert compiles(e) + +template reject(e) = + static: assert(not compiles(e)) + +type + Container[T] = concept c + c.len is Ordinal + items(c) is T + for value in c: + type(value) is T + +proc takesIntContainer(c: Container[int]) = + for e in c: echo e + +takesIntContainer(@[1, 2, 3]) +reject takesIntContainer(@["x", "y"]) + +proc takesContainer(c: Container) = + for e in c: echo e + +takesContainer(@[4, 5, 6]) +takesContainer(@["a", "b"]) +takesContainer "test" +reject takesContainer(10) |