summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorZahary Karadjov <zahary@gmail.com>2012-03-19 12:06:38 +0200
committerZahary Karadjov <zahary@gmail.com>2012-03-19 12:06:38 +0200
commite43f8d842bd91d92caecd24c190881d1dddeaf38 (patch)
treebb8238e5881181cf784625847d5359e805da59a9 /tests
parente3b25e93ac95d192e42dfc56bf699f08d88ec99a (diff)
parent7d09aee438b335122adf6cc1de875e81ea736c96 (diff)
downloadNim-e43f8d842bd91d92caecd24c190881d1dddeaf38.tar.gz
merged branch overloading-for-macros
Diffstat (limited to 'tests')
-rwxr-xr-xtests/compile/tambsym2.nim4
-rw-r--r--tests/compile/tredef.nim29
-rwxr-xr-xtests/compile/ttableconstr.nim2
-rwxr-xr-xtests/compile/ttempl3.nim4
-rwxr-xr-xtests/compile/ttempl4.nim4
-rw-r--r--tests/reject/tprocredef.nim9
-rwxr-xr-xtests/reject/ttempl2.nim6
-rw-r--r--tests/rodfiles/bmethods.nim1
-rw-r--r--tests/rodfiles/bmethods2.nim3
-rwxr-xr-xtests/run/tambsys.nim14
-rwxr-xr-xtests/run/tcurrncy.nim2
-rwxr-xr-xtests/run/tints.nim4
-rwxr-xr-xtests/run/toverl2.nim14
-rwxr-xr-xtests/run/ttoseq.nim2
-rw-r--r--tests/run/tunittests.nim2
-rw-r--r--tests/run/utemplates.nim32
16 files changed, 102 insertions, 30 deletions
diff --git a/tests/compile/tambsym2.nim b/tests/compile/tambsym2.nim
index ecd9a4784..7758cc31a 100755
--- a/tests/compile/tambsym2.nim
+++ b/tests/compile/tambsym2.nim
@@ -1,8 +1,6 @@
 
 from sdl import PSurface
 
-discard SDL.CreateRGBSurface(SDL.SWSURFACE, 23, 34, 
+discard SDL.CreateRGBSurface(SDL.SWSURFACE, 23, 34,
       32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xff000000'i32)
 
-
-
diff --git a/tests/compile/tredef.nim b/tests/compile/tredef.nim
new file mode 100644
index 000000000..02d1f7776
--- /dev/null
+++ b/tests/compile/tredef.nim
@@ -0,0 +1,29 @@
+template foo(a: int, b: string) = nil
+foo(1, "test")
+
+proc bar(a: int, b: string) = nil
+bar(1, "test")
+
+template foo(a: int, b: string) = bar(a, b)
+foo(1, "test")
+
+block:
+  proc bar(a: int, b: string) = nil
+  template foo(a: int, b: string) = nil
+  foo(1, "test")
+  bar(1, "test")
+  
+proc baz =
+  proc foo(a: int, b: string) = nil
+  proc foo(b: string) =
+    template bar(a: int, b: string) = nil
+    bar(1, "test")
+    
+  foo("test")
+
+  block:
+    proc foo(b: string) = nil
+    foo("test")
+    foo(1, "test")
+
+baz()
diff --git a/tests/compile/ttableconstr.nim b/tests/compile/ttableconstr.nim
index 9433e9985..c627e68e8 100755
--- a/tests/compile/ttableconstr.nim
+++ b/tests/compile/ttableconstr.nim
@@ -1,6 +1,6 @@
 # Test if the new table constructor syntax works:
 
-template ignoreExpr(e: expr): stmt =
+template ignoreExpr(e: expr): stmt {.immediate.} =
   nil
 
 # test first class '..' syntactical citizen:  
diff --git a/tests/compile/ttempl3.nim b/tests/compile/ttempl3.nim
index 7b2c70f79..d8e67cc3e 100755
--- a/tests/compile/ttempl3.nim
+++ b/tests/compile/ttempl3.nim
@@ -26,13 +26,13 @@ echo(ha)
 
 
 # Test identifier generation:
-template prefix(name: expr): expr = `"hu" name`
+template prefix(name: expr): expr {.immediate.} = `"hu" name`
 
 var `hu "XYZ"` = "yay"
 
 echo prefix(XYZ)
 
-template typedef(name: expr, typ: typeDesc) = 
+template typedef(name: expr, typ: typeDesc) {.immediate.} =
   type
     `T name`* = typ
     `P name`* = ref `T name`
diff --git a/tests/compile/ttempl4.nim b/tests/compile/ttempl4.nim
index a5ad2000f..26c82e471 100755
--- a/tests/compile/ttempl4.nim
+++ b/tests/compile/ttempl4.nim
@@ -1,7 +1,7 @@
 
-template `:=`(name, val: expr): stmt =
+template `:=`(name, val: expr): stmt {.immediate.} =
   var name = val
-    
+
 ha := 1 * 4
 hu := "ta-da" == "ta-da"
 echo ha, hu
diff --git a/tests/reject/tprocredef.nim b/tests/reject/tprocredef.nim
new file mode 100644
index 000000000..86ed92b62
--- /dev/null
+++ b/tests/reject/tprocredef.nim
@@ -0,0 +1,9 @@
+discard """
+  file: "tprocredef.nim"
+  line: 8
+  errormsg: "redefinition of \'foo\'"
+"""
+
+proc foo(a: int, b: string) = nil
+proc foo(a: int, b: string) = nil
+
diff --git a/tests/reject/ttempl2.nim b/tests/reject/ttempl2.nim
index fba988f95..142bbb8c7 100755
--- a/tests/reject/ttempl2.nim
+++ b/tests/reject/ttempl2.nim
@@ -3,10 +3,10 @@ discard """
   line: 18
   errormsg: "undeclared identifier: \'b\'"
 """
-template declareInScope(x: expr, t: typeDesc): stmt = 
+template declareInScope(x: expr, t: typeDesc): stmt {.immediate.} =
   var x: t
   
-template declareInNewScope(x: expr, t: typeDesc): stmt = 
+template declareInNewScope(x: expr, t: typeDesc): stmt {.immediate.} =
   # open a new scope:
   block: 
     var x: t
@@ -17,5 +17,3 @@ a = 42  # works, `a` is known here
 declareInNewScope(b, int)
 b = 42  #ERROR_MSG undeclared identifier: 'b'
 
-
-
diff --git a/tests/rodfiles/bmethods.nim b/tests/rodfiles/bmethods.nim
index 995942ad6..39aa5368c 100644
--- a/tests/rodfiles/bmethods.nim
+++ b/tests/rodfiles/bmethods.nim
@@ -1,4 +1,5 @@
 discard """
+  disabled: true
   output: '''derived class
 base class
 '''
diff --git a/tests/rodfiles/bmethods2.nim b/tests/rodfiles/bmethods2.nim
index ac24a2201..0d1795a27 100644
--- a/tests/rodfiles/bmethods2.nim
+++ b/tests/rodfiles/bmethods2.nim
@@ -1,5 +1,6 @@
 discard """
-  output: '''derived class 2
+  disabled: true
+  output: '''derived class 2  
 base class
 '''
 """
diff --git a/tests/run/tambsys.nim b/tests/run/tambsys.nim
index a88615866..67522d7c9 100755
--- a/tests/run/tambsys.nim
+++ b/tests/run/tambsys.nim
@@ -2,12 +2,12 @@ discard """
   file: "tambsys.nim"
   output: ""
 """
-# Test ambiguous symbols

-

-import mambsys1, mambsys2

-

-var

-  v: mambsys1.TExport

-mambsys2.foo(3) #OUT

+# Test ambiguous symbols
+
+import mambsys1, mambsys2
+
+var
+  v: mambsys1.TExport
+mambsys2.foo(3) #OUT
 
 
diff --git a/tests/run/tcurrncy.nim b/tests/run/tcurrncy.nim
index a614de7af..d04620cfb 100755
--- a/tests/run/tcurrncy.nim
+++ b/tests/run/tcurrncy.nim
@@ -21,7 +21,7 @@ template Comparable(typ: typeDesc): stmt =
   proc `<=` * (x, y: typ): bool {.borrow.}
   proc `==` * (x, y: typ): bool {.borrow.}
 
-template DefineCurrency(typ, base: expr): stmt =
+template DefineCurrency(typ, base: expr): stmt {.immediate.} =
   type
     typ* = distinct base
   Additive(typ)
diff --git a/tests/run/tints.nim b/tests/run/tints.nim
index 6c9897860..fb2852af9 100755
--- a/tests/run/tints.nim
+++ b/tests/run/tints.nim
@@ -6,7 +6,7 @@ discard """
 
 var testNumber = 0
 
-template test(opr, a, b, c: expr): stmt = 
+template test(opr, a, b, c: expr): stmt {.immediate.} =
   # test the expression at compile and runtime
   block:
     const constExpr = opr(a, b)
@@ -43,5 +43,3 @@ test(`shl`, 0xffffffff'i32, 0x4'i32, 0xfffffff0'i32)
 
 Echo("Success") #OUT Success
 
-
-
diff --git a/tests/run/toverl2.nim b/tests/run/toverl2.nim
index 49b17da4d..dd9f075a8 100755
--- a/tests/run/toverl2.nim
+++ b/tests/run/toverl2.nim
@@ -1,6 +1,6 @@
 discard """
   file: "toverl2.nim"
-  output: "true012"
+  output: "true012innertrue"
 """
 # Test new overloading resolution rules
 
@@ -14,14 +14,20 @@ iterator toverl2(x: int): int =
   while res < x: 
     yield res
     inc(res)
-    
+
 var
   pp: proc (x: bool): string = toverl2
+
 stdout.write(pp(true))
+
 for x in toverl2(3): 
   stdout.write(toverl2(x))
-stdout.write("\n")
-#OUT true012
 
+block:
+  proc toverl2(x: int): string = return "inner"
+  stdout.write(toverl2(5))
+  stdout.write(true)
 
+stdout.write("\n")
+#OUT true012innertrue
 
diff --git a/tests/run/ttoseq.nim b/tests/run/ttoseq.nim
index d631a91e0..ec49489d0 100755
--- a/tests/run/ttoseq.nim
+++ b/tests/run/ttoseq.nim
@@ -2,7 +2,7 @@ discard """
   output: "23456"  
 """
 
-template toSeq*(iter: expr): expr =
+template toSeq*(iter: expr): expr {.immediate.} =
   var result: seq[type(iter)] = @[]
   for x in iter: add(result, x)
   result
diff --git a/tests/run/tunittests.nim b/tests/run/tunittests.nim
index fa7fe5075..b2ec10cdc 100644
--- a/tests/run/tunittests.nim
+++ b/tests/run/tunittests.nim
@@ -1,2 +1,2 @@
-import uclosures
+import uclosures, utemplates
 
diff --git a/tests/run/utemplates.nim b/tests/run/utemplates.nim
new file mode 100644
index 000000000..8fd3d242a
--- /dev/null
+++ b/tests/run/utemplates.nim
@@ -0,0 +1,32 @@
+import unittest
+
+template t(a: int): expr = "int"
+template t(a: string): expr = "string"
+
+test "templates can be overloaded":
+  check t(10) == "int"
+  check t("test") == "string"
+
+test "previous definitions can be further overloaded or hidden in local scopes":
+  template t(a: bool): expr = "bool"
+
+  check t(true) == "bool"
+  check t(10) == "int"
+  
+  template t(a: int): expr = "inner int"
+  check t(10) == "inner int"
+  check t("test") == "string"
+
+test "templates can be redefined multiple times":
+  template customAssert(cond: bool, msg: string): stmt =
+    if not cond: fail(msg)
+
+  template assertion_failed(body: stmt) =
+    template fail(msg: string): stmt = body
+
+  assertion_failed: check msg == "first fail path"
+  customAssert false, "first fail path"
+
+  assertion_failed: check msg == "second fail path"  
+  customAssert false, "second fail path"
+