diff options
Diffstat (limited to 'tests/misc')
53 files changed, 376 insertions, 382 deletions
diff --git a/tests/misc/t99bott.nim b/tests/misc/t99bott.nim index 62ccfbe16..f60023818 100644 --- a/tests/misc/t99bott.nim +++ b/tests/misc/t99bott.nim @@ -1,9 +1,9 @@ discard """ + errormsg: "cannot evaluate at compile time: bn" file: "t99bott.nim" line: 26 - errormsg: "cannot evaluate at compile time: bn" - disabled: false """ + ## 99 Bottles of Beer ## http://www.99-bottles-of-beer.net/ ## Nim version @@ -30,7 +30,3 @@ for bn in countdown(99, 1): echo "No more bottles of beer on the wall, no more bottles of beer." echo "Go to the store and buy some more, 99 bottles of beer on the wall." - - - - diff --git a/tests/misc/tack.nim b/tests/misc/tack.nim index a0afab9e8..458395ef6 100644 --- a/tests/misc/tack.nim +++ b/tests/misc/tack.nim @@ -1,5 +1,4 @@ discard """ - file: "tack.nim" output: "125" """ # the Ackermann function @@ -17,5 +16,4 @@ proc ack(x, y: int): int = # echo(ack(0, 0)) write(stdout, ack(3, 4)) #OUT 125 - - +write stdout, "\n" diff --git a/tests/misc/tbug511622.nim b/tests/misc/tbug511622.nim index a5360423d..4b30e96e6 100644 --- a/tests/misc/tbug511622.nim +++ b/tests/misc/tbug511622.nim @@ -1,5 +1,4 @@ discard """ - file: "tbug511622.nim" output: "3" """ import StrUtils, Math @@ -11,6 +10,3 @@ proc FibonacciA(n: int): int64 = return int64((pow(p, fn) + pow(q, fn)) / sqrt(5.0)) echo FibonacciA(4) #OUT 3 - - - diff --git a/tests/misc/tcmdline.nim b/tests/misc/tcmdline.nim index cb8cb402c..71e1301ca 100644 --- a/tests/misc/tcmdline.nim +++ b/tests/misc/tcmdline.nim @@ -1,3 +1,7 @@ +discard """ +outputsub: "Number of parameters: 0" +joinable: false +""" # Test the command line import diff --git a/tests/misc/tcolonisproc.nim b/tests/misc/tcolonisproc.nim index 665e9e604..c10dabcf1 100644 --- a/tests/misc/tcolonisproc.nim +++ b/tests/misc/tcolonisproc.nim @@ -1,3 +1,9 @@ +discard """ +output: ''' +1 +2 +''' +""" proc p(a, b: int, c: proc ()) = c() diff --git a/tests/misc/tdllvar.nim b/tests/misc/tdllvar.nim index 1c1238e8d..68029ddf4 100644 --- a/tests/misc/tdllvar.nim +++ b/tests/misc/tdllvar.nim @@ -1,3 +1,7 @@ +discard """ +disabled: true +""" + import os proc getDllName: string = @@ -12,5 +16,3 @@ proc myImport2(s: int) {.cdecl, importc, dynlib: getDllName().} myImport("test2") myImport2(12) - - diff --git a/tests/misc/temit.nim b/tests/misc/temit.nim index c83235659..ee7455d4c 100644 --- a/tests/misc/temit.nim +++ b/tests/misc/temit.nim @@ -1,5 +1,4 @@ discard """ - file: "temit.nim" output: "509" """ # Test the new ``emit`` pragma: @@ -14,7 +13,3 @@ proc embedsC() = {.emit: """printf("%d\n", cvariable + (int)`nimVar`);""".} embedsC() - - - - diff --git a/tests/misc/tendian.nim b/tests/misc/tendian.nim deleted file mode 100644 index 91044f4d5..000000000 --- a/tests/misc/tendian.nim +++ /dev/null @@ -1,3 +0,0 @@ -# test the new endian magic - -writeLine(stdout, repr(system.cpuEndian)) diff --git a/tests/misc/tevents.nim b/tests/misc/tevents.nim index caf674084..045c9fc5b 100644 --- a/tests/misc/tevents.nim +++ b/tests/misc/tevents.nim @@ -1,8 +1,9 @@ discard """ -file: "tevents.nim" -output: '''HandlePrintEvent: Output -> Handled print event +output: ''' +HandlePrintEvent: Output -> Handled print event HandlePrintEvent2: Output -> printing for ME -HandlePrintEvent2: Output -> printing for ME''' +HandlePrintEvent2: Output -> printing for ME +''' """ import events @@ -45,4 +46,3 @@ ee.emit(obj.printEvent, eventargs) obj.printEvent.removeHandler(handleprintevent2) ee.emit(obj.printEvent, eventargs) - diff --git a/tests/misc/tgenconstraints.nim b/tests/misc/tgenconstraints.nim index 6e8fdc738..829da5173 100644 --- a/tests/misc/tgenconstraints.nim +++ b/tests/misc/tgenconstraints.nim @@ -1,8 +1,8 @@ discard """ + errormsg: "cannot instantiate T2" file: "tgenconstraints.nim" line: 25 disabled: true - errormsg: "cannot instantiate T2" """ type @@ -29,4 +29,3 @@ proc bar(x: int|TNumber): T1[type(x)] {.discardable.} = bar "test" bar 100 bar 1.1 - diff --git a/tests/misc/tgetstartmilsecs.nim b/tests/misc/tgetstartmilsecs.nim deleted file mode 100644 index bf508dd54..000000000 --- a/tests/misc/tgetstartmilsecs.nim +++ /dev/null @@ -1,7 +0,0 @@ -# -import times, os - -var start = epochTime() -os.sleep(1000) - -echo epochTime() - start #OUT 1000 diff --git a/tests/misc/thallo.nim b/tests/misc/thallo.nim index 17e6089ed..7172a6b46 100644 --- a/tests/misc/thallo.nim +++ b/tests/misc/thallo.nim @@ -1,4 +1,8 @@ -# Hallo +discard """ +action: compile +""" + +# noted this seems to be an old test file designed for manual testing. import os, strutils, macros @@ -7,7 +11,7 @@ type TMyEnum = enum meA, meB, meC, meD -when isMainModule: +when true: {.hint: "this is the main file".} proc fac[T](x: T): T = @@ -80,5 +84,5 @@ for i in 2..6: for j in countdown(i+4, 2): echo(fac(i * j)) -when isMainModule: +when true: {.hint: "this is the main file".} diff --git a/tests/misc/theaproots.nim b/tests/misc/theaproots.nim index 77d0207b0..1ea3c86b9 100644 --- a/tests/misc/theaproots.nim +++ b/tests/misc/theaproots.nim @@ -1,3 +1,7 @@ +discard """ +action: compile +""" + type Bar = object x: int diff --git a/tests/misc/thintoff.nim b/tests/misc/thintoff.nim deleted file mode 100644 index 95318ce9b..000000000 --- a/tests/misc/thintoff.nim +++ /dev/null @@ -1,12 +0,0 @@ -discard """ - file: "thintoff.nim" - output: "0" -""" - -{.hint[XDeclaredButNotUsed]: off.} -var - x: int - -echo x #OUT 0 - - diff --git a/tests/misc/tinc.nim b/tests/misc/tinc.nim index 7819775e3..91f6223e2 100644 --- a/tests/misc/tinc.nim +++ b/tests/misc/tinc.nim @@ -1,12 +1,8 @@ discard """ + errormsg: "type mismatch: got <int>" file: "tinc.nim" line: 8 - errormsg: "type mismatch: got <int>" """ var x = 0 inc(x+1) - - - - diff --git a/tests/misc/tinit.nim b/tests/misc/tinit.nim index 02607909b..207cb17e8 100644 --- a/tests/misc/tinit.nim +++ b/tests/misc/tinit.nim @@ -1,5 +1,4 @@ discard """ - file: "tinit.nim" output: "Hello from module! Hello from main module!" """ # Test the new init section in modules @@ -8,5 +7,3 @@ import minit write(stdout, "Hello from main module!\n") #OUT Hello from module! Hello from main module! - - diff --git a/tests/misc/tinout.nim b/tests/misc/tinout.nim index 46af2f5de..bae0fb185 100644 --- a/tests/misc/tinout.nim +++ b/tests/misc/tinout.nim @@ -1,7 +1,7 @@ discard """ + errormsg: "type mismatch: got <int literal(3)>" file: "tinout.nim" line: 12 - errormsg: "type mismatch: got <int literal(3)>" """ # Test in out checking for parameters @@ -12,5 +12,3 @@ proc b() = abc(3) #ERROR b() - - diff --git a/tests/misc/tinvalidarrayaccess.nim b/tests/misc/tinvalidarrayaccess.nim index 03105b41b..57ad38b85 100644 --- a/tests/misc/tinvalidarrayaccess.nim +++ b/tests/misc/tinvalidarrayaccess.nim @@ -1,14 +1,21 @@ discard """ - errormsg: "index out of bounds" - line: 11 + errormsg: "index out of bounds: (a:0) <= (i:2) <= (b:1) " + line: 18 """ +block: + try: + let a = @[1,2] + echo a[3] + except Exception as e: + doAssert e.msg == "index out of bounds: (i:3) <= (n:1) " -type TTestArr = array[0..1, int16] -var f: TTestArr -f[0] = 30 -f[1] = 40 -f[2] = 50 -f[3] = 60 +block: + type TTestArr = array[0..1, int16] + var f: TTestArr + f[0] = 30 + f[1] = 40 + f[2] = 50 + f[3] = 60 -echo(repr(f)) + echo(repr(f)) diff --git a/tests/misc/tinvalidarrayaccess2.nim b/tests/misc/tinvalidarrayaccess2.nim new file mode 100644 index 000000000..86d349457 --- /dev/null +++ b/tests/misc/tinvalidarrayaccess2.nim @@ -0,0 +1,16 @@ +discard """ + errormsg: "index out of bounds: (a:0) <= (i:3) <= (b:1) " + line: 9 +""" + +# Note: merge in tinvalidarrayaccess.nim pending https://github.com/nim-lang/Nim/issues/9906 + +let a = [1,2] +echo a[3] + +when false: + # TOOD: this case is not yet handled, giving: "index out of bounds" + proc fun()= + let a = @[1,2] + echo a[3] + static: fun() diff --git a/tests/misc/tinvalidnewseq.nim b/tests/misc/tinvalidnewseq.nim index 66e9388ef..dec00fd4a 100644 --- a/tests/misc/tinvalidnewseq.nim +++ b/tests/misc/tinvalidnewseq.nim @@ -1,7 +1,7 @@ discard """ + errormsg: "type mismatch: got <array[0..6, string], int literal(7)>" file: "tinvalidnewseq.nim" line: 15 - errormsg: "type mismatch: got <array[0..6, string], int literal(7)>" """ import re, strutils @@ -22,6 +22,3 @@ var r: TUrl r = parseUrl(r"http://google.com/search?var=bleahdhsad") echo(r.domain) - - - diff --git a/tests/misc/tissue710.nim b/tests/misc/tissue710.nim index e2cca0024..ec125b840 100644 --- a/tests/misc/tissue710.nim +++ b/tests/misc/tissue710.nim @@ -1,7 +1,7 @@ discard """ + errorMsg: "attempting to call routine: '||'" file: "tissue710.nim" line: 8 - errorMsg: "attempting to call routine: '||'" """ var sum = 0 for x in 3..1000: diff --git a/tests/misc/tlastmod.nim b/tests/misc/tlastmod.nim index 538b5e656..1cc1d4bd9 100644 --- a/tests/misc/tlastmod.nim +++ b/tests/misc/tlastmod.nim @@ -1,18 +1,25 @@ +discard """ +outputsub: "is newer than" +""" # test the new LastModificationTime() proc +let + file1 = "tests/testdata/data.csv" + file2 = "tests/testdata/doc1.xml" + import os, times, strutils proc main() = var - a, b: TTime - a = getLastModificationTime(paramStr(1)) - b = getLastModificationTime(paramStr(2)) + a, b: Time + a = getLastModificationTime(file1) + b = getLastModificationTime(file2) writeLine(stdout, $a) writeLine(stdout, $b) if a < b: - write(stdout, "$2 is newer than $1\n" % [paramStr(1), paramStr(2)]) + write(stdout, "$2 is newer than $1\n" % [file1, file2]) else: - write(stdout, "$1 is newer than $2\n" % [paramStr(1), paramStr(2)]) + write(stdout, "$1 is newer than $2\n" % [file1, file2]) main() diff --git a/tests/misc/tloops.nim b/tests/misc/tloops.nim index b160500af..61e0baf10 100644 --- a/tests/misc/tloops.nim +++ b/tests/misc/tloops.nim @@ -1,3 +1,10 @@ +discard """ +output: ''' +Hello!(x: 1, y: 2, z: 3) +(x: 1.0, y: 2.0) +''' +""" + # Test nested loops and some other things proc andTest() = @@ -84,4 +91,3 @@ proc main[T]() = echo myType2 main[int]() - diff --git a/tests/misc/tmandelbrot.nim b/tests/misc/tmandelbrot.nim deleted file mode 100644 index 504628313..000000000 --- a/tests/misc/tmandelbrot.nim +++ /dev/null @@ -1,57 +0,0 @@ -discard """ - cmd: "nim $target --hints:on -d:release $options $file" -""" - -# -*- nim -*- - -import math -import os -import strutils - -type TComplex = tuple[re, im: float] - -proc `+` (a, b: TComplex): TComplex = - return (a.re + b.re, a.im + b.im) - -proc `*` (a, b: TComplex): TComplex = - result.re = a.re * b.re - a.im * b.im - result.im = a.re * b.im + a.im * b.re - -proc abs2 (a: TComplex): float = - return a.re * a.re + a.im * a.im - -var size = parseInt(paramStr(1)) -var bit = 128 -var byteAcc = 0 - -stdout.writeLine("P4") -stdout.write($size) -stdout.write(" ") -stdout.writeLine($size) - -var fsize = float(size) -for y in 0 .. size-1: - var fy = 2.0 * float(y) / fsize - 1.0 - for x in 0 .. size-1: - var z = (0.0, 0.0) - var c = (float(2*x) / fsize - 1.5, fy) - - block iter: - for i in 0 .. 49: - z = z*z + c - if abs2(z) >= 4.0: - break iter - byteAcc = byteAcc + bit - - if bit > 1: - bit = bit div 2 - else: - stdout.write(chr(byteAcc)) - bit = 128 - byteAcc = 0 - - if bit != 128: - stdout.write(chr(byteAcc)) - bit = 128 - byteAcc = 0 - diff --git a/tests/misc/tmemoization.nim b/tests/misc/tmemoization.nim index 840eb3b0d..c65692608 100644 --- a/tests/misc/tmemoization.nim +++ b/tests/misc/tmemoization.nim @@ -1,5 +1,5 @@ discard """ - msg: "test 1\ntest 2\ntest 3" + nimout: "test 1\ntest 2\ntest 3" output: "TEST 1\nTEST 2\nTEST 3" """ diff --git a/tests/misc/tnew.nim b/tests/misc/tnew.nim index 89f34a621..2d9a64461 100644 --- a/tests/misc/tnew.nim +++ b/tests/misc/tnew.nim @@ -1,3 +1,11 @@ +discard """ +outputsub: ''' +Simple tree node allocation worked! +Simple cycle allocation worked! +''' +joinable: false +""" + # Test the implementation of the new operator # and the code generation for gc walkers # (and the garbage collector): diff --git a/tests/misc/tnewuns.nim b/tests/misc/tnewuns.nim deleted file mode 100644 index d6bae4fb1..000000000 --- a/tests/misc/tnewuns.nim +++ /dev/null @@ -1,12 +0,0 @@ -# test the new unsigned operations: - -import - strutils - -var - x, y: int - -x = 1 -y = high(int) - -writeLine(stdout, $ ( x +% y ) ) diff --git a/tests/misc/tnoinst.nim b/tests/misc/tnoinst.nim index 25ebe8dfc..85db1e8e7 100644 --- a/tests/misc/tnoinst.nim +++ b/tests/misc/tnoinst.nim @@ -1,6 +1,6 @@ discard """ - line: 12 errormsg: "instantiate 'notConcrete' explicitly" + line: 12 disabled: "true" """ @@ -14,4 +14,3 @@ proc wrap[T]() = wrap[int]() - diff --git a/tests/misc/tnolen.nim b/tests/misc/tnolen.nim index 2831e5048..e0e8025d4 100644 --- a/tests/misc/tnolen.nim +++ b/tests/misc/tnolen.nim @@ -1,9 +1,8 @@ discard """ - line: 8 errormsg: "type mismatch: got <int literal(3)>" + line: 8 """ # please finally disallow Len(3) echo len(3) - diff --git a/tests/misc/tnoop.nim b/tests/misc/tnoop.nim index e1e25b44e..a1365cfbe 100644 --- a/tests/misc/tnoop.nim +++ b/tests/misc/tnoop.nim @@ -1,8 +1,9 @@ discard """ nimout: ''' - found 'a' of kind 'var'''' + found 'a' of kind 'var' + ''' file: "tnoop.nim" - line: 12 + line: 13 errormsg: "attempting to call routine: 'a'" """ diff --git a/tests/misc/tnot.nim b/tests/misc/tnot.nim index 5c268981e..a3669705b 100644 --- a/tests/misc/tnot.nim +++ b/tests/misc/tnot.nim @@ -1,7 +1,7 @@ discard """ + errormsg: "type mismatch" file: "tnot.nim" line: 14 - errormsg: "type mismatch" """ # BUG: following compiles, but should not: diff --git a/tests/misc/tparseopt.nim b/tests/misc/tparseopt.nim index badbc59ad..cbed5d476 100644 --- a/tests/misc/tparseopt.nim +++ b/tests/misc/tparseopt.nim @@ -1,5 +1,4 @@ discard """ - file: "tparseopt.nim" output: ''' parseopt first round @@ -9,6 +8,8 @@ kind: cmdLongOption key:val -- left: kind: cmdLongOption key:val -- debug:3 kind: cmdShortOption key:val -- l:4 kind: cmdShortOption key:val -- r:2 +cmdLongOption foo +cmdLongOption path parseoptNoVal kind: cmdLongOption key:val -- left: kind: cmdLongOption key:val -- debug:3 @@ -34,44 +35,49 @@ from parseopt2 import nil block: - echo "parseopt" - for kind, key, val in parseopt.getopt(): - echo "kind: ", kind, "\tkey:val -- ", key, ":", val + echo "parseopt" + for kind, key, val in parseopt.getopt(): + echo "kind: ", kind, "\tkey:val -- ", key, ":", val - # pass custom cmdline arguments - echo "first round" - var argv = "--left --debug:3 -l=4 -r:2" - var p = parseopt.initOptParser(argv) - for kind, key, val in parseopt.getopt(p): - echo "kind: ", kind, "\tkey:val -- ", key, ":", val - break - # reset getopt iterator and check arguments are returned correctly. - echo "second round" - for kind, key, val in parseopt.getopt(p): - echo "kind: ", kind, "\tkey:val -- ", key, ":", val + # pass custom cmdline arguments + echo "first round" + var argv = "--left --debug:3 -l=4 -r:2" + var p = parseopt.initOptParser(argv) + for kind, key, val in parseopt.getopt(p): + echo "kind: ", kind, "\tkey:val -- ", key, ":", val + break + # reset getopt iterator and check arguments are returned correctly. + echo "second round" + for kind, key, val in parseopt.getopt(p): + echo "kind: ", kind, "\tkey:val -- ", key, ":", val + + # bug #9619 + var x = parseopt.initOptParser(@["--foo:", "--path"], allowWhitespaceAfterColon = false) + for kind, key, val in parseopt.getopt(x): + echo kind, " ", key block: - echo "parseoptNoVal" - # test NoVal mode with custom cmdline arguments - var argv = "--left --debug:3 -l -r:2 --debug 2 --debug=1 -r1 -r=0 -lr4" - var p = parseopt.initOptParser(argv, - shortNoVal = {'l'}, longNoVal = @["left"]) - for kind, key, val in parseopt.getopt(p): - echo "kind: ", kind, "\tkey:val -- ", key, ":", val + echo "parseoptNoVal" + # test NoVal mode with custom cmdline arguments + var argv = "--left --debug:3 -l -r:2 --debug 2 --debug=1 -r1 -r=0 -lr4" + var p = parseopt.initOptParser(argv, + shortNoVal = {'l'}, longNoVal = @["left"]) + for kind, key, val in parseopt.getopt(p): + echo "kind: ", kind, "\tkey:val -- ", key, ":", val block: - echo "parseopt2" - for kind, key, val in parseopt2.getopt(): - echo "kind: ", kind, "\tkey:val -- ", key, ":", val + echo "parseopt2" + for kind, key, val in parseopt2.getopt(): + echo "kind: ", kind, "\tkey:val -- ", key, ":", val - # pass custom cmdline arguments - echo "first round" - var argv: seq[string] = @["--left", "--debug:3", "-l=4", "-r:2"] - var p = parseopt2.initOptParser(argv) - for kind, key, val in parseopt2.getopt(p): - echo "kind: ", kind, "\tkey:val -- ", key, ":", val - break - # reset getopt iterator and check arguments are returned correctly. - echo "second round" - for kind, key, val in parseopt2.getopt(p): - echo "kind: ", kind, "\tkey:val -- ", key, ":", val + # pass custom cmdline arguments + echo "first round" + var argv: seq[string] = @["--left", "--debug:3", "-l=4", "-r:2"] + var p = parseopt2.initOptParser(argv) + for kind, key, val in parseopt2.getopt(p): + echo "kind: ", kind, "\tkey:val -- ", key, ":", val + break + # reset getopt iterator and check arguments are returned correctly. + echo "second round" + for kind, key, val in parseopt2.getopt(p): + echo "kind: ", kind, "\tkey:val -- ", key, ":", val diff --git a/tests/misc/tpos.nim b/tests/misc/tpos.nim index bedb62e62..f7607d643 100644 --- a/tests/misc/tpos.nim +++ b/tests/misc/tpos.nim @@ -1,5 +1,4 @@ discard """ - file: "tpos.nim" output: "6" """ # test this particular function @@ -30,6 +29,5 @@ proc mypos(sub, s: string, start: int = 0): int = var sub = "hello" var s = "world hello" write(stdout, mypos(sub, s)) +write stdout, "\n" #OUT 6 - - diff --git a/tests/misc/tprep.nim b/tests/misc/tprep.nim index 8f40300d6..45f25b790 100644 --- a/tests/misc/tprep.nim +++ b/tests/misc/tprep.nim @@ -1,3 +1,11 @@ +discard """ +nimout: ''' +tprep.nim(25, 9) Hint: Case 2 [User] +tprep.nim(27, 11) Hint: Case 2.3 [User] +''' +outputsub: "" +""" + # Test the features that used to belong to the preprocessor import diff --git a/tests/misc/tquicksort.nim b/tests/misc/tquicksort.nim index 0867a3769..017c73fbc 100644 --- a/tests/misc/tquicksort.nim +++ b/tests/misc/tquicksort.nim @@ -17,10 +17,7 @@ proc echoSeq(a: seq[int]) = for i in low(a)..high(a): echo(a[i]) -var - list: seq[int] - -list = QuickSort(@[89,23,15,23,56,123,356,12,7,1,6,2,9,4,3]) -echoSeq(list) - +let list = QuickSort(@[89,23,15,23,56,123,356,12,7,1,6,2,9,4,3]) +let expected = @[1, 2, 3, 4, 6, 7, 9, 12, 15, 23, 56, 89, 123, 356] +doAssert list == expected diff --git a/tests/misc/tradix.nim b/tests/misc/tradix.nim index 07674af18..5be89530f 100644 --- a/tests/misc/tradix.nim +++ b/tests/misc/tradix.nim @@ -1,9 +1,37 @@ +discard """ +output: ''' +start tradix.nim +false +false +false +false +false +false +false +false +false +false +128 +1 +2 +3 +4 +255 +17 +45 +19000 +4294967288 +''' +""" + # implements and tests an efficient radix tree ## another method to store an efficient array of pointers: ## We use a radix tree with node compression. ## There are two node kinds: +echo "start tradix.nim" + const BitsPerUnit = 8*sizeof(int) type @@ -101,7 +129,7 @@ proc excl*(r: PRadixNode, a: ByteAddress): bool = proc addLeaf(r: var PRadixNode, a: int): bool = if r == nil: # a linear node: - var x = cast[ptr TRadixNodeLinear](alloc(sizeof(TRadixNodeLinear))) + var x = cast[ptr TRadixNodeLinear](alloc0(sizeof(TRadixNodeLinear))) x.kind = rnLeafLinear x.len = 1'i8 x.keys[0] = toU8(a) @@ -137,7 +165,7 @@ proc addInner(r: var PRadixNode, a: int, d: int): bool = var k = a shr d and 0xff if r == nil: # a linear node: - var x = cast[ptr TRadixNodeLinear](alloc(sizeof(TRadixNodeLinear))) + var x = cast[ptr TRadixNodeLinear](alloc0(sizeof(TRadixNodeLinear))) x.kind = rnLinear x.len = 1'i8 x.keys[0] = toU8(k) @@ -221,99 +249,3 @@ proc main() = for x in elements(r): echo(x) main() - - -when false: - proc traverse(r: PRadixNode, prefix: int, d: int) = - if r == nil: return - case r.kind - of rnLeafBits: - assert(d == 0) - var x = cast[ptr TRadixNodeLeafBits](r) - # iterate over any bit: - for i in 0..high(x.b): - if x.b[i] != 0: # test all bits for zero - for j in 0..BitsPerUnit-1: - if testBit(x.b[i], j): - visit(prefix or i*BitsPerUnit+j) - of rnLeafLinear: - assert(d == 0) - var x = cast[ptr TRadixNodeLeafLinear](r) - for i in 0..ze(x.len)-1: - visit(prefix or ze(x.keys[i])) - of rnFull: - var x = cast[ptr TRadixNodeFull](r) - for i in 0..high(r.b): - if r.b[i] != nil: - traverse(r.b[i], prefix or (i shl d), d-8) - of rnLinear: - var x = cast[ptr TRadixNodeLinear](r) - for i in 0..ze(x.len)-1: - traverse(x.vals[i], prefix or (ze(x.keys[i]) shl d), d-8) - - type - TRadixIter {.final.} = object - r: PRadixNode - p: int - x: int - - proc init(i: var TRadixIter, r: PRadixNode) = - i.r = r - i.x = 0 - i.p = 0 - - proc nextr(i: var TRadixIter): PRadixNode = - if i.r == nil: return nil - case i.r.kind - of rnFull: - var r = cast[ptr TRadixNodeFull](i.r) - while i.x <= high(r.b): - if r.b[i.x] != nil: - i.p = i.x - return r.b[i.x] - inc(i.x) - of rnLinear: - var r = cast[ptr TRadixNodeLinear](i.r) - if i.x < ze(r.len): - i.p = ze(r.keys[i.x]) - result = r.vals[i.x] - inc(i.x) - else: assert(false) - - proc nexti(i: var TRadixIter): int = - result = -1 - case i.r.kind - of rnLeafBits: - var r = cast[ptr TRadixNodeLeafBits](i.r) - # iterate over any bit: - for i in 0..high(r.b): - if x.b[i] != 0: # test all bits for zero - for j in 0..BitsPerUnit-1: - if testBit(x.b[i], j): - visit(prefix or i*BitsPerUnit+j) - of rnLeafLinear: - var r = cast[ptr TRadixNodeLeafLinear](i.r) - if i.x < ze(r.len): - result = ze(r.keys[i.x]) - inc(i.x) - - iterator elements(r: PRadixNode): ByteAddress {.inline.} = - var - a, b, c, d: TRadixIter - init(a, r) - while true: - var x = nextr(a) - if x != nil: - init(b, x) - while true: - var y = nextr(b) - if y != nil: - init(c, y) - while true: - var z = nextr(c) - if z != nil: - init(d, z) - while true: - var q = nexti(d) - if q != -1: - yield a.p shl 24 or b.p shl 16 or c.p shl 8 or q diff --git a/tests/misc/trawstr.nim b/tests/misc/trawstr.nim index 55e508acc..aa41071d5 100644 --- a/tests/misc/trawstr.nim +++ b/tests/misc/trawstr.nim @@ -1,12 +1,10 @@ discard """ + errormsg: "closing \" expected" file: "trawstr.nim" line: 10 - errormsg: "closing \" expected" """ # Test the new raw strings: const xxx = r"This is a raw string!" yyy = "This not\" #ERROR - - diff --git a/tests/misc/treadln.nim b/tests/misc/treadln.nim index 1edbea992..b716c4711 100644 --- a/tests/misc/treadln.nim +++ b/tests/misc/treadln.nim @@ -1,3 +1,11 @@ + +discard """ +output: ''' +test the improved readline handling that does not care whether its +Macintosh, Unix or Windows text format. +''' +""" + # test the improved readline handling that does not care whether its # Macintosh, Unix or Windows text format. @@ -5,8 +13,9 @@ var inp: File line: string -if open(inp, "readme.txt"): +if open(inp, "tests/misc/treadln.nim"): while not endOfFile(inp): line = readLine(inp) - echo("#" & line & "#") + if line.len >= 2 and line[0] == '#' and line[1] == ' ': + echo line[2..^1] close(inp) diff --git a/tests/misc/treadx.nim b/tests/misc/treadx.nim deleted file mode 100644 index e68b8933d..000000000 --- a/tests/misc/treadx.nim +++ /dev/null @@ -1,13 +0,0 @@ - -when not defined(windows): - import posix - - var inp = "" - var buf: array[0..10, char] - while true: - var r = read(0, addr(buf), sizeof(buf)-1) - add inp, $cstring(addr buf) - if r != sizeof(buf)-1: break - - echo inp - #dafkladskölklödsaf ölksdakölfölksfklwe4iojr389wr 89uweokf sdlkf jweklr jweflksdj fioewjfsdlfsd diff --git a/tests/misc/treservedcidentsasfields.nim b/tests/misc/treservedcidentsasfields.nim new file mode 100644 index 000000000..a9a954651 --- /dev/null +++ b/tests/misc/treservedcidentsasfields.nim @@ -0,0 +1,39 @@ +discard """ + targets: "c cpp" +""" + +import macros + +macro make_test_type(idents: varargs[untyped]): untyped = + result = nnkStmtList.newTree() + + var ident_defs: seq[NimNode] = @[] + for i in idents: + ident_defs.add newIdentDefs(i, ident("int")) + + result.add newTree(nnkTypeSection, + newTree(nnkTypeDef, + ident("TestType"), + newEmptyNode(), + newTree(nnkObjectTy, + newEmptyNode(), + newEmptyNode(), + newTree(nnkRecList, + ident_defs + ) + ) + ) + ) + +make_test_type( + auto, bool, catch, char, class, compl, const_cast, default, delete, double, + dynamic_cast, explicit, extern, false, float, friend, goto, int, long, + mutable, namespace, new, operator, private, protected, public, register, + reinterpret_cast, restrict, short, signed, sizeof, static_cast, struct, switch, + this, throw, true, typedef, typeid, typeof, typename, union, packed, unsigned, + virtual, void, volatile, wchar_t, alignas, alignof, constexpr, decltype, nullptr, + noexcept, thread_local, static_assert, char16_t, char32_t +) + +# Make sure the type makes it to codegen. +var test_instance: TestType diff --git a/tests/misc/tshadow_magic_type.nim b/tests/misc/tshadow_magic_type.nim index 03c83079e..3176a4596 100644 --- a/tests/misc/tshadow_magic_type.nim +++ b/tests/misc/tshadow_magic_type.nim @@ -1,3 +1,10 @@ +discard """ +output: ''' +mylist +''' +""" + + type TListItemType* = enum RedisNil, RedisString @@ -15,10 +22,10 @@ proc seq*() = proc lrange*(key: string): TRedisList = var foo: TListItem - foo.kind = RedisNil + foo.kind = RedisString + foo.str = key result = @[foo] -when isMainModule: - var p = lrange("mylist") - for i in items(p): - echo(i.str) +var p = lrange("mylist") +for i in items(p): + echo(i.str) diff --git a/tests/misc/tsimtych.nim b/tests/misc/tsimtych.nim index 037172bd5..74a6ad4c0 100644 --- a/tests/misc/tsimtych.nim +++ b/tests/misc/tsimtych.nim @@ -1,12 +1,10 @@ discard """ + errormsg: "type mismatch: got <bool> but expected \'string\'" file: "tsimtych.nim" line: 10 - errormsg: "type mismatch: got <bool> but expected \'string\'" """ # Test 2 # Simple type checking var a: string a = false #ERROR - - diff --git a/tests/misc/tsizeof.nim b/tests/misc/tsizeof.nim index ecdd44fca..f60c7fa00 100644 --- a/tests/misc/tsizeof.nim +++ b/tests/misc/tsizeof.nim @@ -10,14 +10,16 @@ type TMyArray2 = array[1..3, int32] TMyArray3 = array[TMyEnum, float64] +var failed = false + const mysize1 = sizeof(TMyArray1) mysize2 = sizeof(TMyArray2) mysize3 = sizeof(TMyArray3) -assert mysize1 == 3 -assert mysize2 == 12 -assert mysize3 == 32 +doAssert mysize1 == 3 +doAssert mysize2 == 12 +doAssert mysize3 == 32 import macros, typetraits @@ -38,6 +40,7 @@ macro testSizeAlignOf(args: varargs[untyped]): untyped = if nim_align != c_align: msg.add " align(get, expected): " & $nim_align & " != " & $c_align echo msg + failed = true macro testOffsetOf(a,b1,b2: untyped): untyped = @@ -48,7 +51,8 @@ macro testOffsetOf(a,b1,b2: untyped): untyped = c_offset = c_offsetof(`a`,`b1`) nim_offset = offsetof(`a`,`b2`) if c_offset != nim_offset: - echo `typeName`, ".", `member`, " offset: ", c_offset, " != ", nim_offset + echo `typeName`, ".", `member`, " offsetError, C: ", c_offset, " nim: ", nim_offset + failed = true template testOffsetOf(a,b: untyped): untyped = testOffsetOf(a,b,b) @@ -100,21 +104,16 @@ macro testAlign(arg:untyped):untyped = let nimAlign = alignof(`arg`) if cAlign != nimAlign: echo `prefix`, cAlign, " != ", nimAlign + failed = true -testAlign(pointer) -testAlign(int) -testAlign(uint) -testAlign(int8) -testAlign(int16) -testAlign(int32) -testAlign(int64) -testAlign(uint8) -testAlign(uint16) -testAlign(uint32) -testAlign(uint64) -testAlign(float) -testAlign(float32) -testAlign(float64) +macro testSize(arg:untyped):untyped = + let prefix = newLit(arg.lineinfo & " sizeof " & arg.repr & " ") + result = quote do: + let cSize = c_sizeof(`arg`) + let nimSize = sizeof(`arg`) + if cSize != nimSize: + echo `prefix`, cSize, " != ", nimSize + failed = true type MyEnum {.pure.} = enum @@ -142,14 +141,6 @@ type ValueA ValueB -testAlign(MyEnum) -testAlign(OtherEnum) -testAlign(Enum1) -testAlign(Enum2) -testAlign(Enum4) -testAlign(Enum8) - - template testinstance(body: untyped): untyped = block: {.pragma: objectconfig.} @@ -159,6 +150,32 @@ template testinstance(body: untyped): untyped = {.pragma: objectconfig, packed.} body + +proc testPrimitiveTypes(): void = + testAlign(pointer) + testAlign(int) + testAlign(uint) + testAlign(int8) + testAlign(int16) + testAlign(int32) + testAlign(int64) + testAlign(uint8) + testAlign(uint16) + testAlign(uint32) + testAlign(uint64) + testAlign(float) + testAlign(float32) + testAlign(float64) + + testAlign(MyEnum) + testAlign(OtherEnum) + testAlign(Enum1) + testAlign(Enum2) + testAlign(Enum4) + testAlign(Enum8) + +testPrimitiveTypes() + testinstance: type @@ -274,8 +291,6 @@ testinstance: const trivialSize = sizeof(TrivialType) # needs to be able to evaluate at compile time - testAlign(SimpleAlignment) - proc main(): void = var t : TrivialType var a : SimpleAlignment @@ -286,6 +301,7 @@ testinstance: var f : PaddingAfterBranch var g : RecursiveStuff var ro : RootObj + var e1: Enum1 e2: Enum2 @@ -295,8 +311,20 @@ testinstance: eoa: EnumObjectA eob: EnumObjectB + + testAlign(SimpleAlignment) + testSizeAlignOf(t,a,b,c,d,e,f,g,ro, e1, e2, e4, e8, eoa, eob) + when not defined(cpp): + type + WithBitsize {.objectconfig.} = object + bitfieldA {.bitsize: 16.}: uint32 + bitfieldB {.bitsize: 16.}: uint32 + + var wbs: WithBitsize + testSize(wbs) + testOffsetOf(TrivialType, x) testOffsetOf(TrivialType, y) testOffsetOf(TrivialType, z) @@ -304,6 +332,7 @@ testinstance: testOffsetOf(SimpleAlignment, a) testOffsetOf(SimpleAlignment, b) testOffsetOf(SimpleAlignment, c) + testOffsetOf(AlignAtEnd, a) testOffsetOf(AlignAtEnd, b) testOffsetOf(AlignAtEnd, c) @@ -322,11 +351,11 @@ testinstance: testOffsetOf(Foobar, c) - testOffsetOf(Bazing, a) - - testOffsetOf(InheritanceA, a) - testOffsetOf(InheritanceB, b) - testOffsetOf(InheritanceC, c) + when not defined(cpp): + testOffsetOf(Bazing, a) + testOffsetOf(InheritanceA, a) + testOffsetOf(InheritanceB, b) + testOffsetOf(InheritanceC, c) testOffsetOf(EnumObjectA, a) testOffsetOf(EnumObjectA, b) @@ -350,5 +379,22 @@ testinstance: main() +{.emit: """/*TYPESECTION*/ +typedef struct{ + float a; float b; +} Foo; +""".} + +type + Foo {.importc.} = object + + Bar = object + b: byte + foo: Foo + +assert sizeof(Bar) == 12 -echo "OK" +if failed: + quit("FAIL") +else: + echo "OK" diff --git a/tests/misc/tsizeof2.nim b/tests/misc/tsizeof2.nim index 67379871d..130f28e21 100644 --- a/tests/misc/tsizeof2.nim +++ b/tests/misc/tsizeof2.nim @@ -9,3 +9,9 @@ type const i = sizeof(MyStruct) echo i + +# bug #9868 +proc foo(a: SomeInteger): array[sizeof(a), byte] = + discard + +discard foo(1) diff --git a/tests/misc/tslices.nim b/tests/misc/tslices.nim index 388a46509..d063c5ebf 100644 --- a/tests/misc/tslices.nim +++ b/tests/misc/tslices.nim @@ -1,6 +1,6 @@ discard """ - file: "tslices.nim" - output: '''456456 +output: ''' +456456 456456 456456 Zugr5nd @@ -56,4 +56,3 @@ echo mystr var s = "abcdef" s[1 .. ^2] = "xyz" assert s == "axyzf" - diff --git a/tests/misc/tsortdev.nim b/tests/misc/tsortdev.nim index f360d9646..0b2a4f3e8 100644 --- a/tests/misc/tsortdev.nim +++ b/tests/misc/tsortdev.nim @@ -1,5 +1,5 @@ discard """ - output: "done" + output: "done tsortdev" """ import algorithm, strutils @@ -55,5 +55,4 @@ proc main() = for i in 0..1_000: main() -echo "done" - +echo "done tsortdev" diff --git a/tests/misc/tstrace.nim b/tests/misc/tstrace.nim index 23590d958..00af0af69 100644 --- a/tests/misc/tstrace.nim +++ b/tests/misc/tstrace.nim @@ -1,3 +1,23 @@ +discard """ +exitcode: 1 +output: ''' +Traceback (most recent call last) +tstrace.nim(36) tstrace +tstrace.nim(28) recTest +tstrace.nim(28) recTest +tstrace.nim(28) recTest +tstrace.nim(28) recTest +tstrace.nim(28) recTest +tstrace.nim(28) recTest +tstrace.nim(28) recTest +tstrace.nim(28) recTest +tstrace.nim(28) recTest +tstrace.nim(28) recTest +tstrace.nim(31) recTest +SIGSEGV: Illegal storage access. (Attempt to read from nil?) +''' +""" + # Test the new stacktraces (great for debugging!) {.push stack_trace: on.} diff --git a/tests/misc/tstrange.nim b/tests/misc/tstrange.nim index fee0f44e4..82a82d267 100644 --- a/tests/misc/tstrange.nim +++ b/tests/misc/tstrange.nim @@ -1,8 +1,9 @@ discard """ - file: "tstrange.nim" - output: '''hallo40 +output: ''' +hallo40 1 -2''' +2 +''' """ # test for extremely strange bug @@ -25,4 +26,3 @@ write(stdout, ack(5, 4)) let h=3 for x in 0.. <h.int: echo x - diff --git a/tests/misc/tstrdist.nim b/tests/misc/tstrdist.nim index 3e1939e73..53ace2fae 100644 --- a/tests/misc/tstrdist.nim +++ b/tests/misc/tstrdist.nim @@ -23,4 +23,4 @@ proc editDistance(a, b: string): int = c[(i-1)*n + (j-1)] = min(x,min(y,z)) return c[n*m] -write(stdout, editDistance("abc", "abd")) +doAssert editDistance("abc", "abd") == 3 diff --git a/tests/misc/tunsigned64mod.nim b/tests/misc/tunsigned64mod.nim index 9c9e01c45..ca3286df3 100644 --- a/tests/misc/tunsigned64mod.nim +++ b/tests/misc/tunsigned64mod.nim @@ -12,13 +12,13 @@ let t4 = (v2 mod 2'u64).uint64 # works # bug #2550 var x: uint # doesn't work -echo x mod 2 == 0 +doAssert x mod 2 == 0 var y: uint64 # doesn't work -echo y mod 2 == 0 +doAssert y mod 2 == 0 var z: uint32 # works -echo z mod 2 == 0 +doAssert z mod 2 == 0 var a: int # works -echo a mod 2 == 0 +doAssert a mod 2 == 0 diff --git a/tests/misc/tvarious.nim b/tests/misc/tvarious.nim index 8124b3fc7..191107a87 100644 --- a/tests/misc/tvarious.nim +++ b/tests/misc/tvarious.nim @@ -1,3 +1,7 @@ +discard """ +action: compile +""" + # Test various aspects # bug #572 diff --git a/tests/misc/tvarious1.nim b/tests/misc/tvarious1.nim index 595c77919..9c0b541db 100644 --- a/tests/misc/tvarious1.nim +++ b/tests/misc/tvarious1.nim @@ -1,6 +1,6 @@ discard """ - file: "tlenopenarray.nim" - output: '''1 +output: ''' +1 0 Whopie 12 diff --git a/tests/misc/tvarnums.nim b/tests/misc/tvarnums.nim index 5daa2c4b8..39269b4c0 100644 --- a/tests/misc/tvarnums.nim +++ b/tests/misc/tvarnums.nim @@ -1,5 +1,4 @@ discard """ - file: "tvarnums.nim" output: "Success!" """ # Test variable length binary integers @@ -138,5 +137,3 @@ tm(low(int32)) tm(high(int32)) writeLine(stdout, "Success!") #OUT Success! - - |