summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2014-03-07 22:28:48 +0100
committerAraq <rumpf_a@web.de>2014-03-07 22:28:48 +0100
commitdd216755ff61901eb0b08c56965f58fcabdf4a0e (patch)
tree56bbf3b8586fcbd7e79cfc008db3b8e05e4c3e2a /tests
parent91d842e1ec070a9ab7f883820bd6244526f5d622 (diff)
parent2cbe46daff73987d819ea0ca4bc6ada919d531d4 (diff)
downloadNim-dd216755ff61901eb0b08c56965f58fcabdf4a0e.tar.gz
Merge branch 'devel' of https://github.com/Araq/Nimrod into devel
Diffstat (limited to 'tests')
-rw-r--r--tests/iter/tanoniter1.nim2
-rw-r--r--tests/metatype/udtcmanual.nim43
-rw-r--r--tests/system/alloc.nim45
-rw-r--r--tests/types/tisopr.nim27
4 files changed, 114 insertions, 3 deletions
diff --git a/tests/iter/tanoniter1.nim b/tests/iter/tanoniter1.nim
index 578749caf..9f0d0a74b 100644
--- a/tests/iter/tanoniter1.nim
+++ b/tests/iter/tanoniter1.nim
@@ -8,7 +8,7 @@ discard """
 """
 
 proc factory(a, b: int): iterator (): int =
-  iterator foo(): int =
+  iterator foo(): int {.closure.} =
     var x = a
     while x <= b:
       yield x
diff --git a/tests/metatype/udtcmanual.nim b/tests/metatype/udtcmanual.nim
new file mode 100644
index 000000000..f22bd6ac6
--- /dev/null
+++ b/tests/metatype/udtcmanual.nim
@@ -0,0 +1,43 @@
+discard """
+  output: '''1
+2
+3
+4
+5
+6
+a
+b
+t
+e
+s
+t
+'''
+"""
+
+template accept(e: expr) =
+  static: assert compiles(e)
+
+template reject(e: expr) =
+  static: assert(not compiles(e))
+
+type
+  Container[T] = generic C
+    C.len is Ordinal
+    items(c) is iterator
+    for value in C:
+      value.type 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)
+
diff --git a/tests/system/alloc.nim b/tests/system/alloc.nim
new file mode 100644
index 000000000..665b448ac
--- /dev/null
+++ b/tests/system/alloc.nim
@@ -0,0 +1,45 @@
+var x: ptr int
+
+x = cast[ptr int](alloc(7))
+assert x != nil
+
+x = alloc(int, 3)
+assert x != nil
+x.dealloc()
+
+x = alloc0(int, 4)
+assert cast[ptr array[4, int]](x)[0] == 0
+assert cast[ptr array[4, int]](x)[1] == 0
+assert cast[ptr array[4, int]](x)[2] == 0
+assert cast[ptr array[4, int]](x)[3] == 0
+
+x = cast[ptr int](x.realloc(2))
+assert x != nil
+
+x = x.reallocType(4)
+assert x != nil
+x.dealloc()
+
+x = cast[ptr int](allocShared(100))
+assert x != nil
+deallocShared(x)
+
+x = allocShared(int, 3)
+assert x != nil
+x.deallocShared()
+
+x = allocShared0(int, 3)
+assert x != nil
+assert cast[ptr array[3, int]](x)[0] == 0
+assert cast[ptr array[3, int]](x)[1] == 0
+assert cast[ptr array[3, int]](x)[2] == 0
+
+x = cast[ptr int](reallocShared(x, 2))
+assert x != nil
+
+x = reallocType(x, 12)
+assert x != nil
+
+x = reallocSharedType(x, 1)
+assert x != nil
+x.deallocShared()
diff --git a/tests/types/tisopr.nim b/tests/types/tisopr.nim
index 6d3c51749..3c2b9ee5e 100644
--- a/tests/types/tisopr.nim
+++ b/tests/types/tisopr.nim
@@ -1,8 +1,8 @@
 discard """
-  output: "true true false yes"
+  output: '''true true false yes'''
 """
 
-proc IsVoid[T](): string = 
+proc IsVoid[T](): string =
   when T is void:
     result = "yes"
   else:
@@ -11,3 +11,26 @@ proc IsVoid[T](): string =
 const x = int is int
 echo x, " ", float is float, " ", float is string, " ", IsVoid[void]()
 
+template yes(e: expr): stmt =
+  static: assert e
+
+template no(e: expr): stmt =
+  static: assert(not e)
+
+var s = @[1, 2, 3]
+
+yes s.items is iterator
+no  s.items is proc
+
+yes s.items is iterator: int
+no  s.items is iterator: float
+
+yes s.items is iterator: TNumber
+no  s.items is iterator: object
+
+type 
+  Iter[T] = iterator: T
+
+yes s.items is Iter[TNumber]
+no  s.items is Iter[float]
+