diff options
Diffstat (limited to 'tests')
42 files changed, 206 insertions, 212 deletions
diff --git a/tests/gcbench.nim b/tests/gcbench.nim index 4c94fe360..72daad210 100644 --- a/tests/gcbench.nim +++ b/tests/gcbench.nim @@ -148,8 +148,7 @@ proc main() = # Create long-lived array, filling half of it echo(" Creating a long-lived array of " & $kArraySize & " doubles") - myarray = [] - setlength(myarray, kArraySize) + newSeq(myarray, kArraySize) for i in 0..kArraySize div 2 -1: myarray[i] = 1.0 / toFloat(i) diff --git a/tests/gctest.nim b/tests/gctest.nim index 60845033c..2f8b97b38 100644 --- a/tests/gctest.nim +++ b/tests/gctest.nim @@ -38,13 +38,13 @@ proc newCaseNode(data: string): PCaseNode = result.data = data else: result.kind = nkWhole - result.unused = ["", "abc", "abdc"] + result.unused = @["", "abc", "abdc"] flip = 1 - flip proc newCaseNode(a, b: PCaseNode): PCaseNode = new(result) result.kind = nkList - result.sons = [a, b] + result.sons = @[a, b] proc caseTree(lvl: int = 0): PCaseNode = if lvl == 3: result = newCaseNode("data item") @@ -53,6 +53,7 @@ proc caseTree(lvl: int = 0): PCaseNode = proc finalizeBNode(n: TBNode) = writeln(stdout, n.data) proc finalizeNode(n: PNode) = assert(n != nil) + write(stdout, "finalizing: ") if isNil(n.data): writeln(stdout, "nil!") else: writeln(stdout, n.data) @@ -101,17 +102,17 @@ proc unsureNew(result: var PNode) = new(result, finalizeNode) result.data = $id new(result.le, finalizeNode) - result.le.data = $id & ".1" + result.le.data = $id & ".a" new(result.ri, finalizeNode) - result.ri.data = $id & ".2" + result.ri.data = $id & ".b" inc(id) proc setSons(n: var TBNode) = - n.sons = [] # free memory of the sons - n.t.data = [] + n.sons = @[] # free memory of the sons + n.t.data = @[] var m: seq[string] - m = [] + m = @[] setLen(m, len(n.t.data) * 2) for i in 0..high(m): m[i] = "..." @@ -120,16 +121,17 @@ proc setSons(n: var TBNode) = proc buildBTree(father: var TBNode) = father.data = "father" father.other = nil - father.sons = [] + father.sons = @[] for i in 1..10: + write(stdout, "next iteration!\n") var n: TBNode n.other = returnTree() n.data = "B node: " & $i - if i mod 1 == 0: n.sons = [] # nil and [] need to be handled correctly! + if i mod 2 == 0: n.sons = @[] # nil and [] need to be handled correctly! add father.sons, n father.t.counter = 0 father.t.max = 3 - father.t.data = ["ha", "lets", "stress", "it"] + father.t.data = @["ha", "lets", "stress", "it"] setSons(father) proc main() = @@ -148,7 +150,7 @@ proc main() = t2 = buildTree() printTree(t2) write(stdout, "now test sequences of strings:") - var s: seq[string] = [] + var s: seq[string] = @[] for i in 1..100: add s, "hohoho" # test reallocation writeln(stdout, s[89]) @@ -157,15 +159,22 @@ proc main() = #main() #GC_disable() -writeln(stdout, repr(caseTree())) - var father: TBNode -buildBTree(father) -write(stdout, repr(father)) + s: string +s = "" +s = "" +writeln(stdout, repr(caseTree())) +father.t.data = @["ha", "lets", "stress", "it"] +father.t.data = @["ha", "lets", "stress", "it"] var t = buildTree() write(stdout, repr(t^)) +buildBTree(father) +write(stdout, repr(father)) write(stdout, "starting main...\n") main() write(stdout, "finished\n") +GC_fullCollect() +GC_fullCollect() +write(stdout, GC_getStatistics()) diff --git a/tests/mambsym1.nim b/tests/mambsym1.nim index 1f7b43b02..cf8ac5242 100644 --- a/tests/mambsym1.nim +++ b/tests/mambsym1.nim @@ -2,6 +2,7 @@ import mambsym2 # import TExport type TExport* = enum x, y, z + TOtherEnum* = enum mDec, mInc, mAssign proc ha() = var diff --git a/tests/mambsym2.nim b/tests/mambsym2.nim index a30009f36..eac8de6ba 100644 --- a/tests/mambsym2.nim +++ b/tests/mambsym2.nim @@ -1,2 +1,3 @@ type - TExport* = enum x, y, z # exactly the same type! + TExport* = enum a, b, c + diff --git a/tests/tambsym.nim b/tests/tambsym.nim index e2032e563..7708930df 100644 --- a/tests/tambsym.nim +++ b/tests/tambsym.nim @@ -4,3 +4,5 @@ import mambsym1, mambsym2 var v: TExport #ERROR_MSG ambigious identifier + +v = y diff --git a/tests/tarray.nim b/tests/tarray.nim index 5eca2cfa1..252cbd991 100644 --- a/tests/tarray.nim +++ b/tests/tarray.nim @@ -7,14 +7,14 @@ type proc sum(a: TMyarray): int = result = 0 var i = 0 - while i < length(a): + while i < len(a): inc(result, a[i]) inc(i) proc sum(a: openarray[int]): int = result = 0 var i = 0 - while i < length(a): + while i < len(a): inc(result, a[i]) inc(i) diff --git a/tests/tarrindx.nim b/tests/tarrindx.nim index caacff22b..13919cc2c 100644 --- a/tests/tarrindx.nim +++ b/tests/tarrindx.nim @@ -6,8 +6,8 @@ proc putEnv(key, val: string) = # documentation) var env: ptr array[0..500000, char] - env = alloc(length(key) + length(val) + 2) - for i in 0..length(key)-1: env[i] = key[i] - env[length(key)] = '=' - for i in 0..length(val)-1: - env[length(key)+1+i] = val[i] + env = cast[ptr array[0..500000, char]](alloc(len(key) + len(val) + 2)) + for i in 0..len(key)-1: env[i] = key[i] + env[len(key)] = '=' + for i in 0..len(val)-1: + env[len(key)+1+i] = val[i] diff --git a/tests/tassign.nim b/tests/tassign.nim index d5f846502..f51c20783 100644 --- a/tests/tassign.nim +++ b/tests/tassign.nim @@ -14,14 +14,14 @@ proc test() = a.x = 1 a.y = 2 a.s = "Hallo!" - a.seq = ["abc", "def", "ghi", "jkl"] - a.arr = [] + a.seq = @["abc", "def", "ghi", "jkl"] + a.arr = @[] setLen(a.arr, 4) - a.arr[0] = [] - a.arr[1] = [] + a.arr[0] = @[] + a.arr[1] = @[] b = a # perform a deep copy here! - b.seq = ["xyz", "huch", "was", "soll"] + b.seq = @["xyz", "huch", "was", "soll"] writeln(stdout, len(a.seq)) writeln(stdout, a.seq[3]) writeln(stdout, len(b.seq)) diff --git a/tests/tblock1.nim b/tests/tblock1.nim index 729bfd3e7..0bea7ae7f 100644 --- a/tests/tblock1.nim +++ b/tests/tblock1.nim @@ -3,9 +3,8 @@ proc main = block endLess: - break endLess write(stdout, "Muaahh!\N") - + break endLess break ha #ERROR diff --git a/tests/tconstr1.nim b/tests/tconstr1.nim index 994e55b86..488170350 100644 --- a/tests/tconstr1.nim +++ b/tests/tconstr1.nim @@ -5,23 +5,19 @@ type s: string, x, y: int, z: float, - chars: set[Char] - ] + chars: set[Char]] proc testSem = var things: array [0..1, TComplexRecord] = [ - (chars: {'a', 'b', 'c'}, s: "hi", x: 69, y: 45, z: 0.0), - (chars: {'a', 'b', 'c'}, s: "hi", x: 69, y: 45, z: 1.0) - ] + (s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}), + (s: "hi", x: 69, y: 45, z: 1.0, chars: {'a', 'b', 'c'})] write(stdout, things[0].x) const - things: array [0..] of TComplexRecord = [ - (chars: {'a', 'b', 'c'}, s: "hi", x: 69, y: 45, z: 0.0), - (chars: {'a', 'b', 'c'}, s: "hi", x: 69, y: 45) #ERROR - ] + things: array [0..1, TComplexRecord] = [ + (s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}), + (s: "hi", x: 69, y: 45, z: 1.0)] #ERROR otherThings = [ # the same - (chars: {'a', 'b', 'c'}, s: "hi", x: 69, y: 45, z: 0.0), - (chars: {'a', 'b', 'c'}, s: "hi", x: 69, y: 45) - ] + (s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}), + (s: "hi", x: 69, y: 45, z: 1.0, chars: {'a'})] diff --git a/tests/tconstr2.nim b/tests/tconstr2.nim index 4c27bd833..7687a416c 100644 --- a/tests/tconstr2.nim +++ b/tests/tconstr2.nim @@ -5,16 +5,15 @@ type s: string, x, y: int, z: float, - chars: set[char], - ] + chars: set[char]] const - things: array [0.., TComplexRecord] = [ - (chars: {'a', 'b', 'c'}, s: "hi", x: 69, y: 45, z: 0.0), - (chars: {'a', 'b', 'c'}, s: "hi", x: 69, z: 0.3, y: 45)] + things: array [0..1, TComplexRecord] = [ + (s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}), + (s: "hi", x: 69, y: 45, z: 1.0, chars: {})] otherThings = [ # the same - (chars: {'a', 'b', 'c'}, s: "hi", x: 69, y: 45, z: 0.0), - (z: 0.0, chars: {'a', 'b', 'c'}, s: "hi", x: 69, y: 45)] + (s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}), + (s: "hi", x: 69, y: 45, z: 1.0, chars: {'a'})] write(stdout, things[0].x) #OUT 69 diff --git a/tests/tforwty2.nim b/tests/tforwty2.nim index 32f86f135..5d15e112a 100644 --- a/tests/tforwty2.nim +++ b/tests/tforwty2.nim @@ -3,28 +3,20 @@ {.push dynlib: "SDL.dll", callconv: cdecl.} -when defined(windows): - type - PSDL_semaphore = ptr TSDL_semaphore - TSDL_semaphore {.final.} = object - id: uint32 - count: UInt32 - -elif defined(linux): - type - PSDL_semaphore = ptr TSDL_semaphore - TSDL_semaphore {.final.} = object - sem: Pointer #PSem_t; - when not defined(USE_NAMED_SEMAPHORES): - sem_data: int - when defined(BROKEN_SEMGETVALUE): - # This is a little hack for MacOS X - - # It's not thread-safe, but it's better than nothing - sem_value: cint +type + PSDL_semaphore = ptr TSDL_semaphore + TSDL_semaphore {.final.} = object + sem: Pointer #PSem_t; + when not defined(USE_NAMED_SEMAPHORES): + sem_data: int + when defined(BROKEN_SEMGETVALUE): + # This is a little hack for MacOS X - + # It's not thread-safe, but it's better than nothing + sem_value: cint type PSDL_Sem = ptr TSDL_Sem TSDL_Sem = TSDL_Semaphore -proc SDL_CreateSemaphore(initial_value: UInt32): PSDL_Sem - {.import: "SDL_CreateSemaphore".} +proc SDL_CreateSemaphore(initial_value: Int32): PSDL_Sem {. + importc: "SDL_CreateSemaphore".} diff --git a/tests/thallo.nim b/tests/thallo.nim index b804dba1e..47d56724b 100644 --- a/tests/thallo.nim +++ b/tests/thallo.nim @@ -42,7 +42,7 @@ var `name` = readLine(stdin) echo("Hi " & thallo.name & "!\n") debug(name) -var testseq: seq[string] = [ "a", "b", "c", "d"] +var testseq: seq[string] = @[ "a", "b", "c", "d", "e"] echo(repr(testseq)) var dummy = "hallo" diff --git a/tests/tillrec.nim b/tests/tillrec.nim index eba04a96a..21ce19889 100644 --- a/tests/tillrec.nim +++ b/tests/tillrec.nim @@ -5,8 +5,6 @@ type x: int kids: seq[TLegal] - TIllegal {.final.} = object + TIllegal {.final.} = object #ERROR_MSG illegal recursion in type 'TIllegal' y: Int x: array[0..3, TIllegal] - #ERROR_MSG illegal recursion in type 'TIllegal' - diff --git a/tests/tinvwhen.nim b/tests/tinvwhen.nim index aa528a22e..8dc8cbf50 100644 --- a/tests/tinvwhen.nim +++ b/tests/tinvwhen.nim @@ -1,8 +1,8 @@ # This was parsed even though it should not! -proc chdir(path: CString): cint {.import: "chdir", header: "dirHeader".} +proc chdir(path: CString): cint {.importc: "chdir", header: "dirHeader".} proc getcwd(buf: CString, buflen: cint): CString - when defined(unix): {.import: "getcwd", header: "<unistd.h>".} #ERROR - elif defined(windows): {.import: "getcwd", header: "<direct.h>"} + when defined(unix): {.importc: "getcwd", header: "<unistd.h>".} #ERROR_MSG invalid indentation + elif defined(windows): {.importc: "getcwd", header: "<direct.h>"} else: {.error: "os library not ported to your OS. Please help!".} diff --git a/tests/titer.nim b/tests/titer.nim index 536e2f60d..3f71ba8d9 100644 --- a/tests/titer.nim +++ b/tests/titer.nim @@ -1,15 +1,13 @@ # Test the new iterators -iterator xrange(fromm, to: int, step = 1): (a: int) = - a = fromm +iterator xrange(fromm, to: int, step = 1): int = + var a = fromm while a <= to: yield a inc(a, step) -iterator interval[T](a, b: T): (x: T) - -iterator interval[T](a, b: T): (x: T) = - x = a +iterator interval[T](a, b: T): T = + var x = a while x <= b: yield x inc(x) diff --git a/tests/tlastmod.nim b/tests/tlastmod.nim index b84147c62..75b047fc8 100644 --- a/tests/tlastmod.nim +++ b/tests/tlastmod.nim @@ -1,16 +1,18 @@ # test the new LastModificationTime() proc import - os, times + os, times, strutils proc main() = var a, b: TTime a = getLastModificationTime(ParamStr(1)) b = getLastModificationTime(ParamStr(2)) + writeln(stdout, $a) + writeln(stdout, $b) if a < b: - Write(stdout, "b is newer than a\n") + Write(stdout, "$2 is newer than $1\n" % [ParamStr(1), ParamStr(2)]) else: - Write(stdout, "a is newer than b\n") + Write(stdout, "$1 is newer than $2\n" % [ParamStr(1), ParamStr(2)]) main() diff --git a/tests/tmath.nim b/tests/tmath.nim index 5a10cafb3..6a1dae54d 100644 --- a/tests/tmath.nim +++ b/tests/tmath.nim @@ -1,6 +1,6 @@ # tests for the interpreter -proc loops(a: out int) = +proc loops(a: var int) = nil #var # b: int @@ -81,9 +81,5 @@ proc main() = of "Rumpf": write(stdout, "Du bist in der Familie meines Meisters!\n") else: write(stdout, "ich kenne dich nicht!\n") write(stdout, "Du heisst " & s & "\n") -# [[ -proc main2() = - main() main() -#]] diff --git a/tests/tnoop.nim b/tests/tnoop.nim index 3a19579ab..6fe53da1c 100644 --- a/tests/tnoop.nim +++ b/tests/tnoop.nim @@ -3,4 +3,4 @@ var a: int -a() #ERROR +a() #ERROR_MSG expression cannot be called diff --git a/tests/tobject2.nim b/tests/tobject2.nim index e8e932422..8f69a6bac 100644 --- a/tests/tobject2.nim +++ b/tests/tobject2.nim @@ -7,7 +7,7 @@ type TPoint3d = object of TPoint2d z: int # added a field -proc getPoint(var p: TPoint2d) = +proc getPoint( p: var TPoint2d) = {.breakpoint.} writeln(stdout, p.x) diff --git a/tests/tobjects.nim b/tests/tobjects.nim index 633c9d6af..8305e2838 100644 --- a/tests/tobjects.nim +++ b/tests/tobjects.nim @@ -2,13 +2,14 @@ type TBase = object x, y: int + TSubclassKind = enum ka, kb, kc, kd, ke, kf TSubclass = object of TBase - c: int - case c - of 0, 1, 2, 3: + case c: TSubclassKind + of ka, kb, kc, kd: a, b: int - of 4: + of ke: d, e, f: char + else: nil n: bool var @@ -21,25 +22,21 @@ var case i of 500..999: write(stdout, "ha!\n") -of 1000..3000, 12: write(stdout, "ganz schön groß\n") +of 1000..3000, 12: write(stdout, "ganz schön groß\n") of 1, 2, 3: write(stdout, "1 2 oder 3\n") else: write(stdout, "sollte nicht passieren\n") -case r -of 0.0, 0.125..0.4444: write(stdout, "kleiner als 0.5\n") -else: write(stdout, "weiß nicht\n") - case readLine(stdin) of "Rumpf": write(stdout, "Hallo Meister!\n") of "Andreas": write(stdout, "Hallo Meister!\n") else: write(stdout, "Nicht mein Meister!\n") global = global + 1 -write(stdout, "Hallo wie heißt du? \n") +write(stdout, "Hallo wie heißt du? \n") s = readLine(stdin) i = 0 -while i < length(s): +while i < len(s): if s[i] == 'c': write(stdout, "'c' in deinem Namen gefunden\n") i = i + 1 -write(stdout, "Du heißt " & s) +write(stdout, "Du heißt " & s) diff --git a/tests/toptions.nim b/tests/toptions.nim index 2d15dd348..95bb5cfbc 100644 --- a/tests/toptions.nim +++ b/tests/toptions.nim @@ -2,13 +2,6 @@ # Used command line arguments: # -m -q -o bootstrap\options.mor options.pas # -# -# The Morpork Compiler -# (c) Copyright 2004 Andreas Rumpf -# -# See the file "copying.txt", included in this -# distribution, for details about the copyright. -# type # please make sure we have under 32 options (improves code efficiency!) @@ -26,4 +19,4 @@ var gOptions: TOptionset = {optRefcGC, optRangeCheck, optBoundsCheck, optOverflowCheck, optAssert, optWarns, optHints, optLineDir, optStackTrace} compilerArgs: int - gExitcode: uint8 + gExitcode: int8 diff --git a/tests/toverl.nim b/tests/toverl.nim index 1a571ce12..94f251cac 100644 --- a/tests/toverl.nim +++ b/tests/toverl.nim @@ -1,7 +1,6 @@ # Test for overloading type - TNone {.export: "_NONE", final.} = object + TNone {.exportc: "_NONE", final.} = object -proc - TNone(a, b: int) = nil #ERROR_MSG attempt to redefine 'TNone' +proc TNone(a, b: int) = nil #ERROR_MSG attempt to redefine 'TNone' diff --git a/tests/toverlop.nim b/tests/toverlop.nim index 037da24ee..f11275644 100644 --- a/tests/toverlop.nim +++ b/tests/toverlop.nim @@ -1,6 +1,6 @@ # Test operator overloading -proc % (a, b: int): int = +proc `%` (a, b: int): int = return a mod b var x, y: int diff --git a/tests/toverwr.nim b/tests/toverwr.nim index c3652d168..f2b42df15 100644 --- a/tests/toverwr.nim +++ b/tests/toverwr.nim @@ -1,6 +1,6 @@ # Test the overloading resolution in connection with a qualifier -proc write(t: tTextFile, s: string) = +proc write(t: TFile, s: string) = nil # a nop system.write(stdout, "hallo") diff --git a/tests/tparscfg.nim b/tests/tparscfg.nim index 33347285c..618ecadd6 100644 --- a/tests/tparscfg.nim +++ b/tests/tparscfg.nim @@ -1,11 +1,11 @@ import - os, parsecfg, strutils + os, parsecfg, strutils, streams -var - p: TCfgParser - -if open(p, paramStr(1)): +var f = newFileStream(paramStr(1), fmRead) +if f != nil: + var p: TCfgParser + open(p, f, paramStr(1)) while true: var e = next(p) case e.kind diff --git a/tests/tprintf.nim b/tests/tprintf.nim index 65427d463..14687a937 100644 --- a/tests/tprintf.nim +++ b/tests/tprintf.nim @@ -1,6 +1,6 @@ # Test a printf proc -proc printf(file: TTextFile, args: openarray[string]) = +proc printf(file: TFile, args: openarray[string]) = var i = 0 while i < args.len: write(file, args[i]) diff --git a/tests/tradix.nim b/tests/tradix.nim index 208f9ae9d..e7ca210e4 100644 --- a/tests/tradix.nim +++ b/tests/tradix.nim @@ -31,7 +31,7 @@ proc searchInner(r: PRadixNode, a: int): PRadixNode = case r.kind of rnLinear: var x = cast[ptr TRadixNodeLinear](r) - for i in 0..x.len-1: + for i in 0..ze(x.len)-1: if ze(x.keys[i]) == a: return x.vals[i] of rnFull: var x = cast[ptr TRadixNodeFull](r) @@ -59,7 +59,7 @@ proc searchLeaf(r: PRadixNode, a: int): bool = return testBit(x.b[a /% BitsPerUnit], a) of rnLeafLinear: var x = cast[ptr TRadixNodeLeafLinear](r) - for i in 0..x.len-1: + for i in 0..ze(x.len)-1: if ze(x.keys[i]) == a: return true else: assert(false) @@ -103,7 +103,7 @@ proc addLeaf(r: var PRadixNode, a: int): bool = # a linear node: var x = cast[ptr TRadixNodeLinear](alloc(sizeof(TRadixNodeLinear))) x.kind = rnLeafLinear - x.len = 1 + x.len = 1'i8 x.keys[0] = toU8(a) r = x return false # not already in set @@ -123,7 +123,7 @@ proc addLeaf(r: var PRadixNode, a: int): bool = # transform into a full node: var y = cast[ptr TRadixNodeLeafBits](alloc0(sizeof(TRadixNodeLeafBits))) y.kind = rnLeafBits - for i in 0..x.len-1: + for i in 0..ze(x.len)-1: var u = ze(x.keys[i]) setBit(y.b[u /% BitsPerUnit], u) setBit(y.b[a /% BitsPerUnit], a) @@ -139,7 +139,7 @@ proc addInner(r: var PRadixNode, a: int, d: int): bool = # a linear node: var x = cast[ptr TRadixNodeLinear](alloc(sizeof(TRadixNodeLinear))) x.kind = rnLinear - x.len = 1 + x.len = 1'i8 x.keys[0] = toU8(k) r = x return addInner(x.vals[0], a, d-8) diff --git a/tests/treadln.nim b/tests/treadln.nim index 473eb1eaa..7703d5a56 100644 --- a/tests/treadln.nim +++ b/tests/treadln.nim @@ -2,7 +2,7 @@ # Macintosh, Unix or Windows text format. var - inp: tTextFile + inp: TFile line: string if openFile(inp, "readme.txt"): diff --git a/tests/tregex.nim b/tests/tregex.nim index 48798aa4f..aa32ca847 100644 --- a/tests/tregex.nim +++ b/tests/tregex.nim @@ -4,7 +4,7 @@ import regexprs -if "Username" =~ "[A-Za-z]+": +if "Username".match("[A-Za-z]+"): echo("Yes!") else: echo("Bug!") diff --git a/tests/trepr.nim b/tests/trepr.nim index ec3731332..4a56842f6 100644 --- a/tests/trepr.nim +++ b/tests/trepr.nim @@ -1,12 +1,13 @@ # test the new "repr" built-in proc type + TEnum = enum + en1, en2, en3, en4, en5, en6 + TPoint {.final.} = object x, y, z: int s: array [0..1, string] - - TEnum = enum - en1, en2, en3, en4, en5, en6 + e: TEnum var p: TPoint @@ -18,14 +19,14 @@ p.y = 13 p.z = 45 p.s[0] = "abc" p.s[1] = "xyz" +p.e = en6 new(q) q^ = p -s = [q, q, q, q] +s = @[q, q, q, q] writeln(stdout, repr(p)) writeln(stdout, repr(q)) writeln(stdout, repr(s)) -writeln(stdout, repr(nil)) writeln(stdout, repr(en4)) diff --git a/tests/tseqcon.nim b/tests/tseqcon.nim index f5d0346ae..935da86b5 100644 --- a/tests/tseqcon.nim +++ b/tests/tseqcon.nim @@ -1,4 +1,7 @@ -# Test the &= operator for sequences and strings +# Test the add proc for sequences and strings + +const + nestedFixed = true type TRec {.final.} = object @@ -8,36 +11,35 @@ type TRecSeq = seq[TRec] proc test() = - var seq, b: seq[string] - seq = [] - add(seq, "Hi") - add(seq, "there, ") - add(seq, "what's your name?") + var s, b: seq[string] + s = @[] + add(s, "Hi") + add(s, "there, ") + add(s, "what's your name?") - b = seq # deep copying here! + b = s # deep copying here! b[0][1] = 'a' - for i in 0 .. length(seq)-1: - write(stdout, seq[i]) - for i in 0 .. length(b)-1: + for i in 0 .. len(s)-1: + write(stdout, s[i]) + for i in 0 .. len(b)-1: write(stdout, b[i]) -when defined(nestedFixed): +when nestedFixed: proc nested() = var - seq: seq[seq[string]] + s: seq[seq[string]] for i in 0..10_000: # test if the garbage collector # now works with sequences - seq = [ - ["A", "B", "C", "D"], - ["E", "F", "G", "H"], - ["I", "J", "K", "L"], - ["M", "N", "O", "P"] - ] + s = @[ + @["A", "B", "C", "D"], + @["E", "F", "G", "H"], + @["I", "J", "K", "L"], + @["M", "N", "O", "P"]] test() -when defined(nestedFixed): +when nestedFixed: nested() #OUT Hithere, what's your name?Hathere, what's your name? diff --git a/tests/tstatret.nim b/tests/tstatret.nim index e5403d98b..ac93ac532 100644 --- a/tests/tstatret.nim +++ b/tests/tstatret.nim @@ -1,5 +1,5 @@ # no statement after return proc main() = return - nil #ERROR + echo("huch?") #ERROR_MSG statement not allowed after diff --git a/tests/tstmtexp.nim b/tests/tstmtexp.nim index f50cce01b..f4d83e83f 100644 --- a/tests/tstmtexp.nim +++ b/tests/tstmtexp.nim @@ -1,3 +1,3 @@ # Test 3 -true #ERROR_MSG statement has no effect +1+4 #ERROR_MSG value returned by statement has to be discarded diff --git a/tests/tstrdesc.nim b/tests/tstrdesc.nim index d25579ee2..1c2e85b4b 100644 --- a/tests/tstrdesc.nim +++ b/tests/tstrdesc.nim @@ -9,6 +9,6 @@ type data: array [0..0, char] # for the '\0' character var - emptyString {.export: "emptyString".}: TStringDesc + emptyString {.exportc: "emptyString".}: TStringDesc diff --git a/tests/tstrdist.nim b/tests/tstrdist.nim index 482e363ef..3e1939e73 100644 --- a/tests/tstrdist.nim +++ b/tests/tstrdist.nim @@ -1,26 +1,26 @@ -# compute the edit distance between two strings - -proc editDistance(a, b: string): int = - var c: seq[int] = [] - var - n = a.len - m = b.len - setLength(c, (n+1)*(m+1)) - for i in 0..n: - c[i*n] = i # [i,0] - for j in 0..m: - c[j] = j # [0,j] - - for i in 1..n: - for j in 1..m: - var x = c[(i-1)*n + j]+1 - var y = c[i*n + j-1]+1 - var z: int - if a[i-1] == b[j-1]: - z = c[(i-1)*n + j-1] - else: - z = c[(i-1)*n + j-1]+1 - c[(i-1)*n + (j-1)] = min(x,min(y,z)) - return c[n*m] - -write(stdout, editDistance("abc", "abd")) +# compute the edit distance between two strings + +proc editDistance(a, b: string): int = + var + c: seq[int] + n = a.len + m = b.len + newSeq(c, (n+1)*(m+1)) + for i in 0..n: + c[i*n] = i # [i,0] + for j in 0..m: + c[j] = j # [0,j] + + for i in 1..n: + for j in 1..m: + var x = c[(i-1)*n + j]+1 + var y = c[i*n + j-1]+1 + var z: int + if a[i-1] == b[j-1]: + z = c[(i-1)*n + j-1] + else: + z = c[(i-1)*n + j-1]+1 + c[(i-1)*n + (j-1)] = min(x,min(y,z)) + return c[n*m] + +write(stdout, editDistance("abc", "abd")) diff --git a/tests/tstrset.nim b/tests/tstrset.nim index 76900bf63..e19ccee4d 100644 --- a/tests/tstrset.nim +++ b/tests/tstrset.nim @@ -2,7 +2,7 @@ type TRadixNodeKind = enum rnLinear, rnFull, rnLeaf - PRadixNode = ptr TRadixNode + PRadixNode = ref TRadixNode TRadixNode = object kind: TRadixNodeKind TRadixNodeLinear = object of TRadixNode @@ -24,7 +24,7 @@ proc search(r: PRadixNode, s: string): PRadixNode = case r.kind of rnLinear: var x = PRadixNodeLinear(r) - for j in 0..x.len-1: + for j in 0..ze(x.len)-1: if x.keys[j] == s[i]: if s[i] == '\0': return r r = x.vals[j] @@ -56,21 +56,19 @@ proc testOrincl*(r: var PRadixNode, s: string): bool = proc incl*(r: var PRadixNode, s: string) = discard testOrIncl(r, s) proc excl*(r: var PRadixNode, s: string) = - x = search(r, s) + var x = search(r, s) if x == nil: return case x.kind of rnLeaf: PRadixNodeLeaf(x).s = "" of rnFull: PRadixNodeFull(x).b['\0'] = nil of rnLinear: var x = PRadixNodeLinear(x) - for i in 0..x.len-1: + for i in 0..ze(x.len)-1: if x.keys[i] == '\0': - swap(x.keys[i], x.keys[x.len-1]) + swap(x.keys[i], x.keys[ze(x.len)-1]) dec(x.len) break var root: PRadixNode - - diff --git a/tests/tstrutil.nim b/tests/tstrutil.nim index 985656f2f..0468dfa0c 100644 --- a/tests/tstrutil.nim +++ b/tests/tstrutil.nim @@ -11,6 +11,14 @@ proc main() = for p in split("/home/a1:xyz:/usr/bin", {':'}): write(stdout, p) - + +assert(editDistance("prefix__hallo_suffix", "prefix__hallo_suffix") == 0) +assert(editDistance("prefix__hallo_suffix", "prefix__hallo_suffi1") == 1) +assert(editDistance("prefix__hallo_suffix", "prefix__HALLO_suffix") == 5) +assert(editDistance("prefix__hallo_suffix", "prefix__ha_suffix") == 3) +assert(editDistance("prefix__hallo_suffix", "prefix") == 14) +assert(editDistance("prefix__hallo_suffix", "suffix") == 14) +assert(editDistance("prefix__hallo_suffix", "prefix__hao_suffix") == 2) + main() #OUT ha/home/a1xyz/usr/bin diff --git a/tests/ttime.nim b/tests/ttime.nim index 783032bc9..bad818816 100644 --- a/tests/ttime.nim +++ b/tests/ttime.nim @@ -3,4 +3,4 @@ import times -write(stdout, TimeToString(getTime()) ) +write(stdout, $getTime()) diff --git a/tests/tvardecl.nim b/tests/tvardecl.nim index 48473ff9d..496601e3a 100644 --- a/tests/tvardecl.nim +++ b/tests/tvardecl.nim @@ -3,4 +3,7 @@ var x = 0 s = "Hallo" - a, b: int = 0 #ERROR + a, b: int = 4 + +write(stdout, a) +write(stdout, b) #OUT 44 diff --git a/tests/tvarnums.nim b/tests/tvarnums.nim index f57eeef41..5079e0e16 100644 --- a/tests/tvarnums.nim +++ b/tests/tvarnums.nim @@ -6,7 +6,7 @@ import type TBuffer = array [0..10, int8] -proc toVarNum(x: int32, b: out TBuffer) = +proc toVarNum(x: int32, b: var TBuffer) = # encoding: first bit indicates end of number (0 if at end) # second bit of the first byte denotes the sign (1 --> negative) var a = x @@ -18,15 +18,15 @@ proc toVarNum(x: int32, b: out TBuffer) = # anyway a = abs(x) # first 6 bits: - b[0] = toU8(ord(a >% 63) shl 7 or (ord(x < 0) shl 6) or (a and 63)) - a = a shr 6 # skip first 6 bits + b[0] = toU8(ord(a >% 63'i32) shl 7 or (ord(x < 0'i32) shl 6) or (int(a) and 63)) + a = a shr 6'i32 # skip first 6 bits var i = 1 - while a != 0: - b[i] = toU8(ord(a >% 127) shl 7 or (a and 127)) + while a != 0'i32: + b[i] = toU8(ord(a >% 127'i32) shl 7 or (int(a) and 127)) inc(i) - a = a shr 7 + a = a shr 7'i32 -proc toVarNum64(x: int64, b: out TBuffer) = +proc toVarNum64(x: int64, b: var TBuffer) = # encoding: first bit indicates end of number (0 if at end) # second bit of the first byte denotes the sign (1 --> negative) var a = x @@ -38,20 +38,20 @@ proc toVarNum64(x: int64, b: out TBuffer) = # anyway a = abs(x) # first 6 bits: - b[0] = toU8(ord(a >% 63) shl 7 or (ord(x < 0) shl 6) or int(a and 63)) + b[0] = toU8(ord(a >% 63'i64) shl 7 or (ord(x < 0'i64) shl 6) or int(a and 63)) a = a shr 6 # skip first 6 bits var i = 1 - while a != 0: - b[i] = toU8(ord(a >% 127) shl 7 or int(a and 127)) + while a != 0'i64: + b[i] = toU8(ord(a >% 127'i64) shl 7 or int(a and 127)) inc(i) a = a shr 7 proc toNum64(b: TBuffer): int64 = # treat first byte different: - result = ze(b[0]) and 63 + result = ze64(b[0]) and 63 var i = 0 - Shift: int64 = 6 + Shift = 6'i64 while (ze(b[i]) and 128) != 0: inc(i) result = result or ((ze64(b[i]) and 127) shl Shift) @@ -69,17 +69,17 @@ proc toNum(b: TBuffer): int32 = Shift = 6 while (ze(b[i]) and 128) != 0: inc(i) - result = result or ((ze(b[i]) and 127) shl Shift) + result = result or int32((ze(b[i]) and 127) shl Shift) inc(Shift, 7) if (ze(b[0]) and (1 shl 6)) != 0: # sign bit set? - result = not result +% 1 + result = not int(result) +% 1 # this is the same as ``- result`` # but gives no overflow error for low(int) proc toBinary(x: int64): string = result = newString(64) for i in 0..63: - result[63-i] = chr((int32(x shr i) and 1) + ord('0')) + result[63-i] = chr((int(x shr i) and 1) + ord('0')) proc t64(i: int64) = var @@ -133,4 +133,4 @@ tm(100_000) tm(low(int32)) tm(high(int32)) -writeln(stdout, "Success!") +writeln(stdout, "Success!") #OUT Success! diff --git a/tests/typredef.nim b/tests/typredef.nim index 2dd5e0446..a77d91f40 100644 --- a/tests/typredef.nim +++ b/tests/typredef.nim @@ -1,2 +1,3 @@ type - Uint8 = Uint8 + Uint8 = Uint8 #ERROR_MSG illegal recursion in type 'Uint8' + |