summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorZahary Karadjov <zahary@gmail.com>2013-12-29 00:00:37 +0200
committerZahary Karadjov <zahary@gmail.com>2013-12-29 00:00:37 +0200
commit66a255652572b48440b68878e99d7f5290e384b3 (patch)
tree3349b1791218a3416209569848244245e087009d /tests
parenteb1d23c0c745c64225e8db22f62d8ebf596f4448 (diff)
downloadNim-66a255652572b48440b68878e99d7f5290e384b3.tar.gz
make more tests green
Diffstat (limited to 'tests')
-rw-r--r--tests/compile/tloops.nim128
-rw-r--r--tests/run/tmemoization.nim8
-rw-r--r--tests/run/tstaticparams.nim12
-rw-r--r--tests/run/ttypetraits.nim2
-rw-r--r--tests/run/tusingstatement.nim24
5 files changed, 80 insertions, 94 deletions
diff --git a/tests/compile/tloops.nim b/tests/compile/tloops.nim
index 2b1765b00..f6f939769 100644
--- a/tests/compile/tloops.nim
+++ b/tests/compile/tloops.nim
@@ -1,67 +1,67 @@
-# Test nested loops and some other things

-

-proc andTest() =

-  var a = 0 == 5 and 6 == 6

-

-proc incx(x: var int) = # is built-in proc

-  x = x + 1

-

-proc decx(x: var int) =

-  x = x - 1

-

-proc First(y: var int) =

-  var x: int

-  i_ncx(x)

-  if x == 10:

-    y = 0

-  else:

-    if x == 0:

-      incx(x)

-    else:

-      x=11

-

-proc TestLoops() =

-  var i, j: int

-  while i >= 0:

-    if i mod 3 == 0:

-      break

-    i = i + 1

-    while j == 13:

-      j = 13

-      break

-    break

-

-  while True:

-    break

-

-

-proc Foo(n: int): int =

-    var

-        a, old: int

-        b, c: bool

-    F_irst(a)

-    if a == 10:

-        a = 30

-    elif a == 11:

-        a = 22

-    elif a == 12:

-        a = 23

-    elif b:

-        old = 12

-    else:

-        a = 40

-

-    #

-    b = false or 2 == 0 and 3 == 9

-    a = 0 + 3 * 5 + 6 + 7 + +8 # 36

-    while b:

-        a = a + 3

-    a = a + 5

-    write(stdout, "Hello!")

-

-

-# We should come till here :-)

-discard Foo(345)

+# Test nested loops and some other things
+
+proc andTest() =
+  var a = 0 == 5 and 6 == 6
+
+proc incx(x: var int) = # is built-in proc
+  x = x + 1
+
+proc decx(x: var int) =
+  x = x - 1
+
+proc First(y: var int) =
+  var x: int
+  i_ncx(x)
+  if x == 10:
+    y = 0
+  else:
+    if x == 0:
+      incx(x)
+    else:
+      x=11
+
+proc TestLoops() =
+  var i, j: int
+  while i >= 0:
+    if i mod 3 == 0:
+      break
+    i = i + 1
+    while j == 13:
+      j = 13
+      break
+    break
+
+  while True:
+    break
+
+
+proc Foo(n: int): int =
+    var
+        a, old: int
+        b, c: bool
+    F_irst(a)
+    if a == 10:
+        a = 30
+    elif a == 11:
+        a = 22
+    elif a == 12:
+        a = 23
+    elif b:
+        old = 12
+    else:
+        a = 40
+
+    #
+    b = false or 2 == 0 and 3 == 9
+    a = 0 + 3 * 5 + 6 + 7 + +8 # 36
+    while b:
+        a = a + 3
+    a = a + 5
+    write(stdout, "Hello!")
+
+
+# We should come till here :-)
+discard Foo(345)
 
 # test the new type symbol lookup feature:
 
diff --git a/tests/run/tmemoization.nim b/tests/run/tmemoization.nim
index b59ff44ea..180acd89b 100644
--- a/tests/run/tmemoization.nim
+++ b/tests/run/tmemoization.nim
@@ -1,6 +1,6 @@
 discard """
-  msg:    "test 1\ntest 2"
-  output: "TEST 1\nTEST 2\nTEST 2"
+  msg:    "test 1\ntest 2\ntest 3"
+  output: "TEST 1\nTEST 2\nTEST 3"
 """
 
 import strutils
@@ -10,8 +10,8 @@ proc foo(s: static[string]): string =
 
   const R = s.toUpper
   return R
-  
+
 echo foo("test 1")
 echo foo("test 2")
-echo foo("test " & $2)
+echo foo("test " & $3)
 
diff --git a/tests/run/tstaticparams.nim b/tests/run/tstaticparams.nim
index 23d644bce..b1377443b 100644
--- a/tests/run/tstaticparams.nim
+++ b/tests/run/tstaticparams.nim
@@ -10,9 +10,9 @@ type
   TBar[T; I: static[int]] = object
     data: array[I, T]
 
-  #TA1[T; I: static[int]] = array[I, T]
-  #TA2[T; I: static[int]] = array[0..I, T]
-  TA3[T; I: static[int]] = array[I-1, T]
+  TA1[T; I: static[int]] = array[I, T]
+  # TA2[T; I: static[int]] = array[0..I, T]
+  # TA3[T; I: static[int]] = array[I-1, T]
 
 proc takeFoo(x: TFoo) =
   echo "abracadabra"
@@ -25,7 +25,7 @@ var y: TBar[float, 4]
 echo high(y.data)
 
 var
-  t1: TA1
-  t2: TA2
-  t3: TA3
+  t1: TA1[float, 1]
+  # t2: TA2[string, 4]
+  # t3: TA3[int, 10]
 
diff --git a/tests/run/ttypetraits.nim b/tests/run/ttypetraits.nim
index 9a4a7d0d3..4344855eb 100644
--- a/tests/run/ttypetraits.nim
+++ b/tests/run/ttypetraits.nim
@@ -1,6 +1,6 @@
 discard """
   msg:    "int\nstring\nTBar[int]"
-  output: "int\nstring\nTBar[int]\nint\nrange 0..2\nstring"
+  output: "int\nstring\nTBar[int]\nint\nrange 0..2(int)\nstring"
 """
 
 import typetraits
diff --git a/tests/run/tusingstatement.nim b/tests/run/tusingstatement.nim
index b9d466377..a33aced4c 100644
--- a/tests/run/tusingstatement.nim
+++ b/tests/run/tusingstatement.nim
@@ -8,25 +8,11 @@ import
 
 # This macro mimics the using statement from C#
 #
-# XXX: 
-#  It doen't match the C# version exactly yet.
-#  In particular, it's not recursive, which prevents it from dealing 
-#  with exceptions thrown from the variable initializers when multiple.
-#  variables are used.
+# It's kept only as a test for the macro system
+# Nimrod's destructors offer a mechanism for automatic 
+# disposal of resources.
 #
-#  Also, since nimrod relies less on exceptions in general, a more
-#  idiomatic definition could be:
-#  var x = init()
-#  if opened(x): 
-#    try:
-#      body
-#    finally:
-#      close(x)
-#
-#  `opened` here could be an overloaded proc which any type can define.
-#  A common practice can be returing an Optional[Resource] obj for which
-#  `opened` is defined to `optional.hasValue`
-macro using(e: expr): stmt {.immediate.} =
+macro autoClose(e: expr): stmt {.immediate.} =
   let e = callsite()
   if e.len != 3:
     error "Using statement: unexpected number of arguments. Got " &
@@ -97,7 +83,7 @@ proc close(r: var TResource) =
 proc use(r: var TResource) =
   write(stdout, "Using " & r.field & ".")
 
-using(r = openResource("test")):
+autoClose(r = openResource("test")):
   use r