summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/errmsgs/tgcsafety.nim3
-rw-r--r--tests/errmsgs/tunknown_named_parameter.nim24
-rw-r--r--tests/js/tjsffi.nim4
-rw-r--r--tests/js/tseqops.nim4
-rw-r--r--tests/js/tthismangle.nim23
-rw-r--r--tests/macros/tgetimpl.nim31
-rw-r--r--tests/stdlib/tunittest.nim19
-rw-r--r--tests/system/tostring.nim10
-rw-r--r--tests/template/tprocparshadow.nim19
-rw-r--r--tests/vm/tmisc_vm.nim (renamed from tests/vm/trgba.nim)15
10 files changed, 145 insertions, 7 deletions
diff --git a/tests/errmsgs/tgcsafety.nim b/tests/errmsgs/tgcsafety.nim
index 4d192db90..ffc6905b0 100644
--- a/tests/errmsgs/tgcsafety.nim
+++ b/tests/errmsgs/tgcsafety.nim
@@ -5,7 +5,8 @@ nimout: '''
 type mismatch: got <AsyncHttpServer, Port, proc (req: Request): Future[system.void]{.locks: <unknown>.}>
 but expected one of:
 proc serve(server: AsyncHttpServer; port: Port;
-          callback: proc (request: Request): Future[void]; address = ""): Future[void]
+          callback: proc (request: Request): Future[void] {.closure, gcsafe.};
+          address = ""): Future[void]
   first type mismatch at position: 3
   required type: proc (request: Request): Future[system.void]{.closure, gcsafe.}
   but expression 'cb' is of type: proc (req: Request): Future[system.void]{.locks: <unknown>.}
diff --git a/tests/errmsgs/tunknown_named_parameter.nim b/tests/errmsgs/tunknown_named_parameter.nim
new file mode 100644
index 000000000..b6b855136
--- /dev/null
+++ b/tests/errmsgs/tunknown_named_parameter.nim
@@ -0,0 +1,24 @@
+discard """
+cmd: "nim check $file"
+errormsg: "type mismatch: got <string, set[char], maxsplits: int literal(1)>"
+nimout: '''
+proc rsplit(s: string; sep: string; maxsplit: int = -1): seq[string]
+  first type mismatch at position: 2
+  required type: string
+  but expression '{':'}' is of type: set[char]
+proc rsplit(s: string; sep: char; maxsplit: int = -1): seq[string]
+  first type mismatch at position: 2
+  required type: char
+  but expression '{':'}' is of type: set[char]
+proc rsplit(s: string; seps: set[char] = Whitespace; maxsplit: int = -1): seq[string]
+  first type mismatch at position: 3
+  unknown named parameter: maxsplits
+
+expression: rsplit("abc:def", {':'}, maxsplits = 1)
+'''
+"""
+
+# bug #8043
+
+import strutils
+"abc:def".rsplit({':'}, maxsplits = 1)
diff --git a/tests/js/tjsffi.nim b/tests/js/tjsffi.nim
index 156ca89e3..213d05964 100644
--- a/tests/js/tjsffi.nim
+++ b/tests/js/tjsffi.nim
@@ -267,8 +267,8 @@ block:
   type TestObject = object
     a: int
     onWhatever: proc(e: int): int
-  proc handleWhatever(that: TestObject, e: int): int =
-    e + that.a
+  proc handleWhatever(this: TestObject, e: int): int =
+    e + this.a
   proc test(): bool =
     let obj = TestObject(a: 9, onWhatever: bindMethod(handleWhatever))
     obj.onWhatever(1) == 10
diff --git a/tests/js/tseqops.nim b/tests/js/tseqops.nim
index d10e1ca6a..af664222c 100644
--- a/tests/js/tseqops.nim
+++ b/tests/js/tseqops.nim
@@ -1,8 +1,8 @@
 discard """
   output: '''(x: 0, y: 0)
 (x: 5, y: 0)
-@[(x: 2, y: 4), (x: 4, y: 5), (x: 4, y: 5)]
-@[(a: 3, b: 3), (a: 1, b: 1), (a: 2, b: 2)]
+@[(x: "2", y: 4), (x: "4", y: 5), (x: "4", y: 5)]
+@[(a: "3", b: 3), (a: "1", b: 1), (a: "2", b: 2)]
 '''
 """
 
diff --git a/tests/js/tthismangle.nim b/tests/js/tthismangle.nim
new file mode 100644
index 000000000..880abcc83
--- /dev/null
+++ b/tests/js/tthismangle.nim
@@ -0,0 +1,23 @@
+proc moo1(this: int) =
+  doAssert this == 42
+
+proc moo2(x: int) =
+  var this = x
+  doAssert this == 42
+
+proc moo3() =
+  for this in [1,1,1]:
+    doAssert this == 1
+
+proc moo4() =
+  type
+    X = object
+      this: int
+
+  var q = X(this: 42)
+  doAssert q.this == 42
+
+moo1(42)
+moo2(42)
+moo3()
+moo4()
diff --git a/tests/macros/tgetimpl.nim b/tests/macros/tgetimpl.nim
index d38492934..715c969f3 100644
--- a/tests/macros/tgetimpl.nim
+++ b/tests/macros/tgetimpl.nim
@@ -1,6 +1,7 @@
 discard """
   msg: '''"muhaha"
 proc poo(x, y: int) =
+  let y = x 
   echo ["poo"]'''
 """
 
@@ -10,11 +11,39 @@ const
   foo = "muhaha"
 
 proc poo(x, y: int) =
+  let y = x
   echo "poo"
 
 macro m(x: typed): untyped =
-  echo repr x.symbol.getImpl
+  echo repr x.getImpl
   result = x
 
 discard m foo
 discard m poo
+
+#------------
+
+macro checkOwner(x: typed, check_id: static[int]): untyped = 
+  let sym = case check_id:
+    of 0: x
+    of 1: x.getImpl.body[0][0][0]
+    of 2: x.getImpl.body[0][0][^1]
+    of 3: x.getImpl.body[1][0]
+    else: x
+  result = newStrLitNode($sym.owner.symKind)
+
+macro isSameOwner(x, y: typed): untyped = 
+  result = 
+    if x.owner == y.owner: bindSym"true"
+    else: bindSym"false"
+    
+
+static:
+  doAssert checkOwner(foo, 0) == "nskModule"
+  doAssert checkOwner(poo, 0) == "nskModule"
+  doAssert checkOwner(poo, 1) == "nskProc"
+  doAssert checkOwner(poo, 2) == "nskProc"
+  doAssert checkOwner(poo, 3) == "nskModule"
+  doAssert isSameOwner(foo, poo)
+  doAssert isSameOwner(foo, echo) == false
+  doAssert isSameOwner(poo, len) == false
diff --git a/tests/stdlib/tunittest.nim b/tests/stdlib/tunittest.nim
index 86b9fd037..c8656bbff 100644
--- a/tests/stdlib/tunittest.nim
+++ b/tests/stdlib/tunittest.nim
@@ -13,6 +13,8 @@ discard """
 
 [Suite] bug #5784
 
+[Suite] test suite
+
 [Suite] test name filtering
 
 '''
@@ -123,6 +125,23 @@ suite "bug #5784":
     var obj: Obj
     check obj.isNil or obj.field == 0
 
+type
+    SomeType = object
+        value: int
+        children: seq[SomeType]
+
+# bug #5252
+
+proc `==`(a, b: SomeType): bool =
+    return a.value == b.value
+
+suite "test suite":
+    test "test":
+        let a = SomeType(value: 10)
+        let b = SomeType(value: 10)
+
+        check(a == b)
+
 when defined(testing):
   suite "test name filtering":
     test "test name":
diff --git a/tests/system/tostring.nim b/tests/system/tostring.nim
index 42c07c0a4..04b37f133 100644
--- a/tests/system/tostring.nim
+++ b/tests/system/tostring.nim
@@ -106,4 +106,12 @@ var nilstring: string
 bar(nilstring)
 
 static:
-  stringCompare()
\ No newline at end of file
+  stringCompare()
+
+# bug 8847
+var a2: cstring = "fo\"o2"
+
+block:
+  var s: string
+  s.addQuoted a2
+  doAssert s == "\"fo\\\"o2\""
diff --git a/tests/template/tprocparshadow.nim b/tests/template/tprocparshadow.nim
index b99cd0b6c..de1c2d941 100644
--- a/tests/template/tprocparshadow.nim
+++ b/tests/template/tprocparshadow.nim
@@ -9,3 +9,22 @@ template something(name: untyped) =
 
 something(what)
 what(10)
+
+# bug #4750
+
+type
+  O = object
+    i: int
+
+  OP = ptr O
+
+template alf(p: pointer): untyped =
+  cast[OP](p)
+
+
+proc t1(al: pointer) =
+  var o = alf(al)
+
+proc t2(alf: pointer) =
+  var x = alf
+  var o = alf(x)
diff --git a/tests/vm/trgba.nim b/tests/vm/tmisc_vm.nim
index 923ea1b2e..6eb3dd627 100644
--- a/tests/vm/trgba.nim
+++ b/tests/vm/tmisc_vm.nim
@@ -2,6 +2,8 @@ discard """
   output: '''[127, 127, 0, 255]
 [127, 127, 0, 255]
 '''
+
+  nimout: '''caught Exception'''
 """
 
 #bug #1009
@@ -34,3 +36,16 @@ proc ABGR*(val: int| int64): TAggRgba8 =
 const
   c1 = ABGR(0xFF007F7F)
 echo ABGR(0xFF007F7F).repr, c1.repr
+
+
+# bug 8740
+
+static:
+  try:
+    raise newException(ValueError, "foo")
+  except Exception:
+    echo "caught Exception"
+  except Defect:
+    echo "caught Defect"
+  except ValueError:
+    echo "caught ValueError"