summary refs log tree commit diff stats
path: root/tests/borrow
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2014-01-13 02:10:03 +0100
committerAraq <rumpf_a@web.de>2014-01-13 02:10:03 +0100
commit20b5f31c03fb556ec0aa2428a40adbac004d8987 (patch)
tree58086941e7d6bb8f480ca1173a95722ada9435b2 /tests/borrow
parent51ee524109cf7e3e86c676bc1676063a01bfd979 (diff)
downloadNim-20b5f31c03fb556ec0aa2428a40adbac004d8987.tar.gz
new tester; all tests categorized
Diffstat (limited to 'tests/borrow')
-rw-r--r--tests/borrow/tborrow.nim21
-rw-r--r--tests/borrow/tinvalidborrow.nim17
2 files changed, 38 insertions, 0 deletions
diff --git a/tests/borrow/tborrow.nim b/tests/borrow/tborrow.nim
new file mode 100644
index 000000000..8e6aeba74
--- /dev/null
+++ b/tests/borrow/tborrow.nim
@@ -0,0 +1,21 @@
+discard """
+  output: "4887 true"
+"""
+
+# test the new borrow feature that works with generics:
+
+proc `++`*[T: int | float](a, b: T): T =
+  result = a + b
+  
+type
+  DI = distinct int
+  DF = distinct float
+  DS = distinct string
+  
+proc `++`(x, y: DI): DI {.borrow.}
+proc `++`(x, y: DF): DF {.borrow.}
+
+proc `$`(x: DI): string {.borrow.}
+proc `$`(x: DF): string {.borrow.}
+
+echo  4544.DI ++ 343.di, " ", (4.5.df ++ 0.5.df).float == 5.0
diff --git a/tests/borrow/tinvalidborrow.nim b/tests/borrow/tinvalidborrow.nim
new file mode 100644
index 000000000..9ab9e8d64
--- /dev/null
+++ b/tests/borrow/tinvalidborrow.nim
@@ -0,0 +1,17 @@
+discard """
+  line: 11
+  errormsg: "no symbol to borrow from found"
+"""
+
+# bug #516
+
+type
+  TAtom = culong
+
+proc `==`*(a, b: TAtom): bool {.borrow.}
+
+var
+  d, e: TAtom
+
+echo( $(d == e) )
+