diff options
author | Araq <rumpf_a@web.de> | 2018-09-14 15:48:07 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2018-09-14 15:48:07 +0200 |
commit | 5709736e827ef844c98afa8fcad08d2f789f93b4 (patch) | |
tree | 7fecb2f49b475163b699c702ccd75d99d0357fb5 /tests | |
parent | 5ee904643af3c5bf126121cd9534ddcb11cd4630 (diff) | |
parent | 382fe446c3926f7976de09b7a1d8ad131912c7b6 (diff) | |
download | Nim-5709736e827ef844c98afa8fcad08d2f789f93b4.tar.gz |
Merge branch 'devel' into araq-better-docgen
Diffstat (limited to 'tests')
-rw-r--r-- | tests/arithm/tcast.nim | 43 | ||||
-rw-r--r-- | tests/assert/tfailedassert_stacktrace.nim | 19 | ||||
-rw-r--r-- | tests/ccgbugs/tborrowmagic.nim | 8 | ||||
-rw-r--r-- | tests/ccgbugs/thtiobj.nim | 8 | ||||
-rw-r--r-- | tests/js/t7534.nim | 7 | ||||
-rw-r--r-- | tests/js/t8914.nim | 12 | ||||
-rw-r--r-- | tests/js/taddnilstr.nim | 4 | ||||
-rw-r--r-- | tests/js/tstrconcat.nim | 5 | ||||
-rw-r--r-- | tests/macros/tcollect.nim | 63 | ||||
-rw-r--r-- | tests/seq/t7346.nim | 10 | ||||
-rw-r--r-- | tests/typerel/t8905.nim | 7 | ||||
-rw-r--r-- | tests/types/t6969.nim | 10 | ||||
-rw-r--r-- | tests/types/t7581.nim | 1 |
13 files changed, 193 insertions, 4 deletions
diff --git a/tests/arithm/tcast.nim b/tests/arithm/tcast.nim index 954e2e677..4017ed1c5 100644 --- a/tests/arithm/tcast.nim +++ b/tests/arithm/tcast.nim @@ -4,6 +4,9 @@ B0 B1 B2 B3 +B4 +B5 +B6 ''' """ @@ -14,6 +17,14 @@ template crossCheck(ty: untyped, exp: untyped) = echo "Got ", ct echo "Expected ", rt +template add1(x: uint8): untyped = x + 1 +template add1(x: uint16): untyped = x + 1 +template add1(x: uint32): untyped = x + 1 + +template sub1(x: uint8): untyped = x - 1 +template sub1(x: uint16): untyped = x - 1 +template sub1(x: uint32): untyped = x - 1 + block: when true: echo "B0" @@ -34,10 +45,34 @@ block: crossCheck(uint64, (-1).uint64 + 5'u64) echo "B3" - crossCheck(int8, 0'u8 - 5'u8) - crossCheck(int16, 0'u16 - 5'u16) - crossCheck(int32, 0'u32 - 5'u32) - crossCheck(int64, 0'u64 - 5'u64) + doAssert $sub1(0'u8) == "255" + doAssert $sub1(0'u16) == "65535" + doAssert $sub1(0'u32) == "4294967295" + + echo "B4" + doAssert $add1(255'u8) == "0" + doAssert $add1(65535'u16) == "0" + doAssert $add1(4294967295'u32) == "0" + + echo "B5" + crossCheck(int32, high(int32)) + crossCheck(int32, high(int32).int32) + crossCheck(int32, low(int32)) + crossCheck(int32, low(int32).int32) + crossCheck(int64, high(int8).int16.int32.int64) + crossCheck(int64, low(int8).int16.int32.int64) + + echo "B6" + crossCheck(int64, 0xFFFFFFFFFFFFFFFF'u64) + crossCheck(int32, 0xFFFFFFFFFFFFFFFF'u64) + crossCheck(int16, 0xFFFFFFFFFFFFFFFF'u64) + crossCheck(int8 , 0xFFFFFFFFFFFFFFFF'u64) + + # Out of range conversion, caught for `let`s only + # crossCheck(int8, 0'u8 - 5'u8) + # crossCheck(int16, 0'u16 - 5'u16) + # crossCheck(int32, 0'u32 - 5'u32) + # crossCheck(int64, 0'u64 - 5'u64) # crossCheck(int8, 0'u16 - 129'u16) # crossCheck(uint8, 0'i16 + 257'i16) diff --git a/tests/assert/tfailedassert_stacktrace.nim b/tests/assert/tfailedassert_stacktrace.nim new file mode 100644 index 000000000..43171ef6c --- /dev/null +++ b/tests/assert/tfailedassert_stacktrace.nim @@ -0,0 +1,19 @@ +discard """ + output: ''' +tfailedassert_stacktrace.nim(16) tfailedassert_stacktrace +tfailedassert_stacktrace.nim(15) foo +system.nim(3778) failedAssertImpl +system.nim(3771) raiseAssert +system.nim(2818) sysFatal +''' +""" + + + +try: + proc foo() = + assert(false) + foo() +except AssertionError: + let e = getCurrentException() + echo e.getStackTrace diff --git a/tests/ccgbugs/tborrowmagic.nim b/tests/ccgbugs/tborrowmagic.nim new file mode 100644 index 000000000..8d42ddcd8 --- /dev/null +++ b/tests/ccgbugs/tborrowmagic.nim @@ -0,0 +1,8 @@ +type + Bytes = distinct seq[byte] + +proc add(x: var Bytes; b: byte) {.borrow.} +var x = @[].Bytes +x.add(42) +let base = cast[seq[byte]](x) +doAssert base.len == 1 and base[0] == 42 diff --git a/tests/ccgbugs/thtiobj.nim b/tests/ccgbugs/thtiobj.nim new file mode 100644 index 000000000..7a656905f --- /dev/null +++ b/tests/ccgbugs/thtiobj.nim @@ -0,0 +1,8 @@ +discard """ + targets: "c cpp" +""" + +import typeinfo + +var x = "" +discard (getPointer(toAny(x))) diff --git a/tests/js/t7534.nim b/tests/js/t7534.nim new file mode 100644 index 000000000..64aadb8d6 --- /dev/null +++ b/tests/js/t7534.nim @@ -0,0 +1,7 @@ +proc f(x: int): int = + result = case x + of 1: 2 + elif x == 2: 3 + else: 1 + +doAssert 2 == f(f(f(f(1)))) diff --git a/tests/js/t8914.nim b/tests/js/t8914.nim new file mode 100644 index 000000000..ff716b42a --- /dev/null +++ b/tests/js/t8914.nim @@ -0,0 +1,12 @@ +discard """ + output: ''' +@[42] +@[24, 42] +''' +""" + +var x = @[42,4242] +x.delete(1) +echo x +x.insert(24) +echo x diff --git a/tests/js/taddnilstr.nim b/tests/js/taddnilstr.nim new file mode 100644 index 000000000..f5b934fdd --- /dev/null +++ b/tests/js/taddnilstr.nim @@ -0,0 +1,4 @@ +var x = "foo".cstring +var y: string +add(y, x) +doAssert y == "foo" diff --git a/tests/js/tstrconcat.nim b/tests/js/tstrconcat.nim new file mode 100644 index 000000000..37c8db687 --- /dev/null +++ b/tests/js/tstrconcat.nim @@ -0,0 +1,5 @@ +var x: string +var y = "foo" +add(x, y) +y[0] = 'm' +doAssert y == "moo" and x == "foo" diff --git a/tests/macros/tcollect.nim b/tests/macros/tcollect.nim new file mode 100644 index 000000000..ae28ab61b --- /dev/null +++ b/tests/macros/tcollect.nim @@ -0,0 +1,63 @@ +discard """ + output: '''@[2, 3, 4, 2, 3, 4, 2, 3, 4, 2, 3, 4, 2, 3, 4] +@[0, 1, 2, 3]''' +""" + +const data = [1,2,3,4,5,6] + +import macros + +macro collect(body): untyped = + # analyse the body, find the deepest expression 'it' and replace it via + # 'result.add it' + let res = genSym(nskVar, "collectResult") + + when false: + proc detectForLoopVar(n: NimNode): NimNode = + if n.kind == nnkForStmt: + result = n[0] + else: + for x in n: + result = detectForLoopVar(x) + if result != nil: return result + return nil + + proc t(n, res: NimNode): NimNode = + case n.kind + of nnkStmtList, nnkStmtListExpr, nnkBlockStmt, nnkBlockExpr, + nnkWhileStmt, + nnkForStmt, nnkIfExpr, nnkIfStmt, nnkTryStmt, nnkCaseStmt, + nnkElifBranch, nnkElse, nnkElifExpr: + result = copyNimTree(n) + if n.len >= 1: + result[^1] = t(n[^1], res) + else: + if true: #n == it: + template adder(res, it) = + res.add it + result = getAst adder(res, n) + else: + result = n + + when false: + let it = detectForLoopVar(body) + if it == nil: error("no for loop in body", body) + + let v = newTree(nnkVarSection, + newTree(nnkIdentDefs, res, newTree(nnkBracketExpr, bindSym"seq", + newCall(bindSym"type", body)), newEmptyNode())) + + result = newTree(nnkStmtListExpr, v, t(body, res), res) + #echo repr result + +let stuff = collect: + var i = -1 + while i < 4: + inc i + for it in data: + if it < 5 and it > 1: + it + +echo stuff + +echo collect(for i in 0..3: i) diff --git a/tests/seq/t7346.nim b/tests/seq/t7346.nim new file mode 100644 index 000000000..ef2fd5b79 --- /dev/null +++ b/tests/seq/t7346.nim @@ -0,0 +1,10 @@ +when not defined(nimNewRuntime): + {.error: "This bug could only be reproduced with --newruntime".} + +type + Obj = object + a: int + +proc `=`(a: var Obj, b: Obj) = discard + +let a: seq[Obj] = @[] \ No newline at end of file diff --git a/tests/typerel/t8905.nim b/tests/typerel/t8905.nim new file mode 100644 index 000000000..9383962cf --- /dev/null +++ b/tests/typerel/t8905.nim @@ -0,0 +1,7 @@ +type + Foo[T] = distinct seq[T] + Bar[T] = object + +proc newFoo[T](): Foo[T] = Foo[T](newSeq[T]()) + +var x = newFoo[Bar[int]]() diff --git a/tests/types/t6969.nim b/tests/types/t6969.nim new file mode 100644 index 000000000..d6ce5e62a --- /dev/null +++ b/tests/types/t6969.nim @@ -0,0 +1,10 @@ +discard """ +errormsg: "invalid type: 'object' for var" +line: 6 +""" + +var a: object a: int +# or +var b: ref object a: int +# or +var c: ptr object a: int \ No newline at end of file diff --git a/tests/types/t7581.nim b/tests/types/t7581.nim new file mode 100644 index 000000000..796f30271 --- /dev/null +++ b/tests/types/t7581.nim @@ -0,0 +1 @@ +discard int -1 \ No newline at end of file |