diff options
Diffstat (limited to 'tests/vm')
-rw-r--r-- | tests/vm/tarrayboundeval.nim | 2 | ||||
-rw-r--r-- | tests/vm/tnimnode.nim | 18 | ||||
-rw-r--r-- | tests/vm/tvmmisc.nim | 66 |
3 files changed, 68 insertions, 18 deletions
diff --git a/tests/vm/tarrayboundeval.nim b/tests/vm/tarrayboundeval.nim index af9e33339..dc8c7ebdc 100644 --- a/tests/vm/tarrayboundeval.nim +++ b/tests/vm/tarrayboundeval.nim @@ -25,7 +25,7 @@ echo myconst, " ", int((KeyMax + 31) / 32) #bug 1304 or something: -const constArray: array [-3..2, int] = [-3, -2, -1, 0, 1, 2] +const constArray: array[-3..2, int] = [-3, -2, -1, 0, 1, 2] echo constArray[-2] diff --git a/tests/vm/tnimnode.nim b/tests/vm/tnimnode.nim index e5a41e3c2..60e3189b0 100644 --- a/tests/vm/tnimnode.nim +++ b/tests/vm/tnimnode.nim @@ -15,9 +15,9 @@ static: proc checkNode(arg: NimNode; name: string): void {. compileTime .} = echo "checking ", name - + assertEq arg.lispRepr , "StmtList(DiscardStmt(Empty()))" - + node = arg nodeArray = [arg] nodeSeq[0] = arg @@ -38,9 +38,9 @@ proc checkNode(arg: NimNode; name: string): void {. compileTime .} = static: # the root node that is used to generate the Ast var stmtList: NimNode - + stmtList = newStmtList(nnkDiscardStmt.newTree(newEmptyNode())) - + checkNode(stmtList, "direct construction") @@ -50,12 +50,12 @@ macro foo(stmtList: untyped): untyped = foo: discard - + static: stmtList = quote do: discard - checkNode(stmtList, "create with quote") + checkNode(newTree(nnkStmtList, stmtList), "create with quote") static: @@ -64,13 +64,13 @@ static: for i in 0 ..< 10: discard - let innerBody = loop[0][2] + let innerBody = loop[2] innerBody.add newCall(ident"echo", newLit("Hello World")) - assertEq loop[0][2].lispRepr, innerBody.lispRepr + assertEq loop[2].lispRepr, innerBody.lispRepr echo "OK" - + static: echo "testing creation of comment node" diff --git a/tests/vm/tvmmisc.nim b/tests/vm/tvmmisc.nim index b7112b099..42a58fa8f 100644 --- a/tests/vm/tvmmisc.nim +++ b/tests/vm/tvmmisc.nim @@ -1,16 +1,66 @@ - - # bug #4462 import macros -proc foo(t: typedesc) {.compileTime.} = - echo getType(t).treeRepr +block: + proc foo(t: typedesc) {.compileTime.} = + assert sameType(getType(t), getType(int)) -static: - foo(int) + static: + foo(int) # #4412 -proc default[T](t: typedesc[T]): T {.inline.} = discard +block: + proc default[T](t: typedesc[T]): T {.inline.} = discard + + static: + var x = default(type(0)) +# #6379 static: - var x = default(type(0)) + import algorithm + + var numArray = [1, 2, 3, 4, -1] + numArray.sort(cmp) + assert numArray == [-1, 1, 2, 3, 4] + + var str = "cba" + str.sort(cmp) + assert str == "abc" + +# #6086 +import math, sequtils, future + +block: + proc f: int = + toSeq(10..<10_000).filter( + a => a == ($a).map( + d => (d.ord-'0'.ord).int^4 + ).sum + ).sum + + var a = f() + const b = f() + + assert a == b + +block: + proc f(): seq[char] = + result = "hello".map(proc(x: char): char = x) + + var runTime = f() + const compTime = f() + assert runTime == compTime + +# #6083 +block: + proc abc(): seq[int] = + result = @[0] + result.setLen(2) + var tmp: int + + for i in 0 .. <2: + inc tmp + result[i] = tmp + + const fact1000 = abc() + assert fact1000 == @[1, 2] |