diff options
Diffstat (limited to 'tests/stdlib')
-rw-r--r-- | tests/stdlib/nre/captures.nim | 2 | ||||
-rw-r--r-- | tests/stdlib/talgorithm.nim | 2 | ||||
-rw-r--r-- | tests/stdlib/tcritbits.nim | 2 | ||||
-rw-r--r-- | tests/stdlib/tformat.nim | 12 | ||||
-rw-r--r-- | tests/stdlib/tio.nim | 14 | ||||
-rw-r--r-- | tests/stdlib/tlists.nim | 12 | ||||
-rw-r--r-- | tests/stdlib/tmarshal.nim | 2 | ||||
-rw-r--r-- | tests/stdlib/tmath.nim | 6 | ||||
-rw-r--r-- | tests/stdlib/tmath2.nim | 170 | ||||
-rw-r--r-- | tests/stdlib/tos.nim | 4 | ||||
-rw-r--r-- | tests/stdlib/tosprocterminate.nim | 2 | ||||
-rw-r--r-- | tests/stdlib/tparscfg.nim | 4 | ||||
-rw-r--r-- | tests/stdlib/tquit.nim | 12 | ||||
-rw-r--r-- | tests/stdlib/tregex.nim | 40 | ||||
-rw-r--r-- | tests/stdlib/treguse.nim | 42 | ||||
-rw-r--r-- | tests/stdlib/trepr.nim | 2 | ||||
-rw-r--r-- | tests/stdlib/trepr2.nim | 64 | ||||
-rw-r--r-- | tests/stdlib/tsplit.nim | 2 | ||||
-rw-r--r-- | tests/stdlib/tstrset.nim | 6 | ||||
-rw-r--r-- | tests/stdlib/tstrtabs.nim | 2 | ||||
-rw-r--r-- | tests/stdlib/ttime.nim | 12 | ||||
-rw-r--r-- | tests/stdlib/twalker.nim | 26 |
22 files changed, 220 insertions, 220 deletions
diff --git a/tests/stdlib/nre/captures.nim b/tests/stdlib/nre/captures.nim index 4f3f15444..19c344a8d 100644 --- a/tests/stdlib/nre/captures.nim +++ b/tests/stdlib/nre/captures.nim @@ -3,7 +3,7 @@ include nre suite "captures": test "map capture names to numbers": - check(getNameToNumberTable(re("(?<v1>1(?<v2>2(?<v3>3))(?'v4'4))()")) == + check(getNameToNumberTable(re("(?<v1>1(?<v2>2(?<v3>3))(?'v4'4))()")) == { "v1" : 0, "v2" : 1, "v3" : 2, "v4" : 3 }.toTable()) test "capture bounds are correct": diff --git a/tests/stdlib/talgorithm.nim b/tests/stdlib/talgorithm.nim index 3ca425fbc..f200e54c5 100644 --- a/tests/stdlib/talgorithm.nim +++ b/tests/stdlib/talgorithm.nim @@ -8,4 +8,4 @@ doAssert product(@[@[1,2], @[3,4], @[5,6]]) == @[@[2,4,6],@[1,4,6],@[2,3,6],@[1, doAssert product(@[@[1,2], @[]]) == newSeq[seq[int]](), "two elements, but one empty" doAssert lowerBound([1,2,4], 3, system.cmp[int]) == 2 doAssert lowerBound([1,2,2,3], 4, system.cmp[int]) == 4 -doAssert lowerBound([1,2,3,10], 11) == 4 \ No newline at end of file +doAssert lowerBound([1,2,3,10], 11) == 4 diff --git a/tests/stdlib/tcritbits.nim b/tests/stdlib/tcritbits.nim index fb447b80b..8280ec881 100644 --- a/tests/stdlib/tcritbits.nim +++ b/tests/stdlib/tcritbits.nim @@ -22,7 +22,7 @@ when isMainModule: for w in r.items: echo w - + for w in r.itemsWithPrefix("de"): echo w diff --git a/tests/stdlib/tformat.nim b/tests/stdlib/tformat.nim index 92c0c16f5..160ab0fd5 100644 --- a/tests/stdlib/tformat.nim +++ b/tests/stdlib/tformat.nim @@ -2,11 +2,11 @@ discard """ file: "tformat.nim" output: "Hi Andreas! How do you feel, Rumpf?" """ -# Tests the new format proc (including the & and &= operators) - -import strutils - -echo("Hi $1! How do you feel, $2?\n" % ["Andreas", "Rumpf"]) -#OUT Hi Andreas! How do you feel, Rumpf? +# Tests the new format proc (including the & and &= operators) + +import strutils + +echo("Hi $1! How do you feel, $2?\n" % ["Andreas", "Rumpf"]) +#OUT Hi Andreas! How do you feel, Rumpf? diff --git a/tests/stdlib/tio.nim b/tests/stdlib/tio.nim index dcb6bd54f..ebf2d70f3 100644 --- a/tests/stdlib/tio.nim +++ b/tests/stdlib/tio.nim @@ -1,7 +1,7 @@ -# test the file-IO - -proc main() = - for line in lines("thello.nim"): - writeLine(stdout, line) - -main() +# test the file-IO + +proc main() = + for line in lines("thello.nim"): + writeLine(stdout, line) + +main() diff --git a/tests/stdlib/tlists.nim b/tests/stdlib/tlists.nim index 7d5379945..4caa05c90 100644 --- a/tests/stdlib/tlists.nim +++ b/tests/stdlib/tlists.nim @@ -11,14 +11,14 @@ block SinglyLinkedListTest1: var L: TSinglyLinkedList[int] for d in items(data): L.prepend(d) assert($L == "[6, 5, 4, 3, 2, 1]") - + assert(4 in L) block SinglyLinkedListTest2: var L: TSinglyLinkedList[string] for d in items(data): L.prepend($d) assert($L == "[6, 5, 4, 3, 2, 1]") - + assert("4" in L) @@ -28,7 +28,7 @@ block DoublyLinkedListTest1: for d in items(data): L.append(d) L.remove(L.find(1)) assert($L == "[6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6]") - + assert(4 in L) block SinglyLinkedRingTest1: @@ -39,7 +39,7 @@ block SinglyLinkedRingTest1: assert($L == "[4, 4]") assert(4 in L) - + block DoublyLinkedRingTest1: var L: TDoublyLinkedRing[int] @@ -49,7 +49,7 @@ block DoublyLinkedRingTest1: assert($L == "[4, 4]") assert(4 in L) - + L.append(3) L.append(5) assert($L == "[4, 4, 3, 5]") @@ -60,7 +60,7 @@ block DoublyLinkedRingTest1: L.remove(L.find(4)) assert($L == "[]") assert(4 notin L) - + echo "true" diff --git a/tests/stdlib/tmarshal.nim b/tests/stdlib/tmarshal.nim index a778d2f77..4c0c10360 100644 --- a/tests/stdlib/tmarshal.nim +++ b/tests/stdlib/tmarshal.nim @@ -25,7 +25,7 @@ type help: string else: discard - + PNode = ref TNode TNode = object next, prev: PNode diff --git a/tests/stdlib/tmath.nim b/tests/stdlib/tmath.nim index fc9486093..1ac9c8092 100644 --- a/tests/stdlib/tmath.nim +++ b/tests/stdlib/tmath.nim @@ -23,13 +23,13 @@ suite "random int": rand = random(100..1000) check rand < 1000 check rand >= 100 - test "randomize() again gives new numbers": + test "randomize() again gives new numbers": randomize() var rand1 = random(1000000) randomize() var rand2 = random(1000000) check rand1 != rand2 - + suite "random float": test "there might be some randomness": @@ -52,7 +52,7 @@ suite "random float": rand = random(100.0..1000.0) check rand < 1000.0 check rand >= 100.0 - test "randomize() again gives new numbers": + test "randomize() again gives new numbers": randomize() var rand1:float = random(1000000.0) randomize() diff --git a/tests/stdlib/tmath2.nim b/tests/stdlib/tmath2.nim index 88d96c80a..84a49efa9 100644 --- a/tests/stdlib/tmath2.nim +++ b/tests/stdlib/tmath2.nim @@ -1,85 +1,85 @@ -# tests for the interpreter - -proc loops(a: var int) = - discard - #var - # b: int - #b = glob - #while b != 0: - # b = b + 1 - #a = b - -proc mymax(a, b: int): int = - #loops(result) - result = a - if b > a: result = b - -proc test(a, b: int) = - var - x, y: int - x = 0 - y = 7 - if x == a + b * 3 - 7 or - x == 8 or - x == y and y > -56 and y < 699: - y = 0 - elif y == 78 and x == 0: - y = 1 - elif y == 0 and x == 0: - y = 2 - else: - y = 3 - -type - TTokType = enum - tkNil, tkType, tkConst, tkVar, tkSymbol, tkIf, - tkWhile, tkFor, tkLoop, tkCase, tkLabel, tkGoto - -proc testCase(t: TTokType): int = - case t - of tkNil, tkType, tkConst: result = 0 - of tkVar: result = 1 - of tkSymbol: result = 2 - of tkIf..tkFor: result = 3 - of tkLoop: result = 56 - else: result = -1 - test(0, 9) # test the call - -proc TestLoops() = - var - i, j: int - - while i >= 0: - if i mod 3 == 0: - break - i = i + 1 - while j == 13: - j = 13 - break - break - - while true: - break - - -var - glob: int - a: array [0..5, int] - -proc main() = - #glob = 0 - #loops( glob ) - var - res: int - s: string - #write(stdout, mymax(23, 45)) - write(stdout, "Hallo! Wie heisst du? ") - s = readLine(stdin) - # test the case statement - case s - of "Andreas": write(stdout, "Du bist mein Meister!\n") - 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") - -main() +# tests for the interpreter + +proc loops(a: var int) = + discard + #var + # b: int + #b = glob + #while b != 0: + # b = b + 1 + #a = b + +proc mymax(a, b: int): int = + #loops(result) + result = a + if b > a: result = b + +proc test(a, b: int) = + var + x, y: int + x = 0 + y = 7 + if x == a + b * 3 - 7 or + x == 8 or + x == y and y > -56 and y < 699: + y = 0 + elif y == 78 and x == 0: + y = 1 + elif y == 0 and x == 0: + y = 2 + else: + y = 3 + +type + TTokType = enum + tkNil, tkType, tkConst, tkVar, tkSymbol, tkIf, + tkWhile, tkFor, tkLoop, tkCase, tkLabel, tkGoto + +proc testCase(t: TTokType): int = + case t + of tkNil, tkType, tkConst: result = 0 + of tkVar: result = 1 + of tkSymbol: result = 2 + of tkIf..tkFor: result = 3 + of tkLoop: result = 56 + else: result = -1 + test(0, 9) # test the call + +proc TestLoops() = + var + i, j: int + + while i >= 0: + if i mod 3 == 0: + break + i = i + 1 + while j == 13: + j = 13 + break + break + + while true: + break + + +var + glob: int + a: array [0..5, int] + +proc main() = + #glob = 0 + #loops( glob ) + var + res: int + s: string + #write(stdout, mymax(23, 45)) + write(stdout, "Hallo! Wie heisst du? ") + s = readLine(stdin) + # test the case statement + case s + of "Andreas": write(stdout, "Du bist mein Meister!\n") + 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") + +main() diff --git a/tests/stdlib/tos.nim b/tests/stdlib/tos.nim index ebe577b00..cae388792 100644 --- a/tests/stdlib/tos.nim +++ b/tests/stdlib/tos.nim @@ -2,9 +2,9 @@ import os -proc walkDirTree(root: string) = +proc walkDirTree(root: string) = for k, f in walkDir(root): - case k + case k of pcFile, pcLinkToFile: echo(f) of pcDir: walkDirTree(f) of pcLinkToDir: discard diff --git a/tests/stdlib/tosprocterminate.nim b/tests/stdlib/tosprocterminate.nim index fd044414c..7fc6c5d85 100644 --- a/tests/stdlib/tosprocterminate.nim +++ b/tests/stdlib/tosprocterminate.nim @@ -14,7 +14,7 @@ var TimeToWait = 5000 while process.running() and TimeToWait > 0: sleep(100) TimeToWait = TimeToWait - 100 - + if process.running(): echo("FAILED") else: diff --git a/tests/stdlib/tparscfg.nim b/tests/stdlib/tparscfg.nim index 618ecadd6..4c11ccf61 100644 --- a/tests/stdlib/tparscfg.nim +++ b/tests/stdlib/tparscfg.nim @@ -1,7 +1,7 @@ import os, parsecfg, strutils, streams - + var f = newFileStream(paramStr(1), fmRead) if f != nil: var p: TCfgParser @@ -9,7 +9,7 @@ if f != nil: while true: var e = next(p) case e.kind - of cfgEof: + of cfgEof: echo("EOF!") break of cfgSectionStart: ## a ``[section]`` has been parsed diff --git a/tests/stdlib/tquit.nim b/tests/stdlib/tquit.nim index d4dc1522d..d18b468c8 100644 --- a/tests/stdlib/tquit.nim +++ b/tests/stdlib/tquit.nim @@ -1,6 +1,6 @@ -# Test the new beforeQuit variable: - -proc myExit() {.noconv.} = - write(stdout, "just exiting...\n") - -addQuitProc(myExit) +# Test the new beforeQuit variable: + +proc myExit() {.noconv.} = + write(stdout, "just exiting...\n") + +addQuitProc(myExit) diff --git a/tests/stdlib/tregex.nim b/tests/stdlib/tregex.nim index bb4695f02..ae6714de1 100644 --- a/tests/stdlib/tregex.nim +++ b/tests/stdlib/tregex.nim @@ -2,30 +2,30 @@ discard """ file: "tregex.nim" output: "key: keyAYes!" """ -# Test the new regular expression module -# which is based on the PCRE library +# Test the new regular expression module +# which is based on the PCRE library when defined(powerpc64): # cheat as our powerpc test machine has no PCRE installed: echo "key: keyAYes!" -else: - import - re - - if "keyA = valueA" =~ re"\s*(\w+)\s*\=\s*(\w+)": - write(stdout, "key: ", matches[0]) - elif "# comment!" =~ re.re"\s*(\#.*)": - # test re.re"" syntax - echo("comment: ", matches[0]) - else: - echo("Bug!") - - if "Username".match(re"[A-Za-z]+"): - echo("Yes!") - else: - echo("Bug!") - - #OUT key: keyAYes! +else: + import + re + + if "keyA = valueA" =~ re"\s*(\w+)\s*\=\s*(\w+)": + write(stdout, "key: ", matches[0]) + elif "# comment!" =~ re.re"\s*(\#.*)": + # test re.re"" syntax + echo("comment: ", matches[0]) + else: + echo("Bug!") + + if "Username".match(re"[A-Za-z]+"): + echo("Yes!") + else: + echo("Bug!") + + #OUT key: keyAYes! diff --git a/tests/stdlib/treguse.nim b/tests/stdlib/treguse.nim index a610ad725..3d09eb731 100644 --- a/tests/stdlib/treguse.nim +++ b/tests/stdlib/treguse.nim @@ -2,26 +2,26 @@ discard """ file: "treguse.nim" output: "055this should be the casehugh" """ -# Test the register usage of the virtual machine and -# the blocks in var statements - -proc main(a, b: int) = - var x = 0 - write(stdout, x) - if x == 0: - var y = 55 - write(stdout, y) - write(stdout, "this should be the case") - var input = "<no input>" - if input == "Andreas": - write(stdout, "wow") - else: - write(stdout, "hugh") - else: - var z = 66 - write(stdout, z) # "bug!") - -main(45, 1000) -#OUT 055this should be the casehugh +# Test the register usage of the virtual machine and +# the blocks in var statements + +proc main(a, b: int) = + var x = 0 + write(stdout, x) + if x == 0: + var y = 55 + write(stdout, y) + write(stdout, "this should be the case") + var input = "<no input>" + if input == "Andreas": + write(stdout, "wow") + else: + write(stdout, "hugh") + else: + var z = 66 + write(stdout, z) # "bug!") + +main(45, 1000) +#OUT 055this should be the casehugh diff --git a/tests/stdlib/trepr.nim b/tests/stdlib/trepr.nim index 8d1353173..18fe7e054 100644 --- a/tests/stdlib/trepr.nim +++ b/tests/stdlib/trepr.nim @@ -6,7 +6,7 @@ discard """ type TEnum = enum a, b - + var val = {a, b} stdout.write(repr(val)) stdout.writeLine(repr({'a'..'z', 'A'..'Z'})) diff --git a/tests/stdlib/trepr2.nim b/tests/stdlib/trepr2.nim index b7c2bd152..a92024851 100644 --- a/tests/stdlib/trepr2.nim +++ b/tests/stdlib/trepr2.nim @@ -1,32 +1,32 @@ -# 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] - e: TEnum - -var - p: TPoint - q: ref TPoint - s: seq[ref TPoint] - -p.x = 0 -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] - -writeLine(stdout, repr(p)) -writeLine(stdout, repr(q)) -writeLine(stdout, repr(s)) -writeLine(stdout, repr(en4)) +# 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] + e: TEnum + +var + p: TPoint + q: ref TPoint + s: seq[ref TPoint] + +p.x = 0 +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] + +writeLine(stdout, repr(p)) +writeLine(stdout, repr(q)) +writeLine(stdout, repr(s)) +writeLine(stdout, repr(en4)) diff --git a/tests/stdlib/tsplit.nim b/tests/stdlib/tsplit.nim index 25bad33e2..5a1cd2f5f 100644 --- a/tests/stdlib/tsplit.nim +++ b/tests/stdlib/tsplit.nim @@ -13,7 +13,7 @@ if s == "#abc#xy#z": echo "true" else: echo "false" - + #OUT true diff --git a/tests/stdlib/tstrset.nim b/tests/stdlib/tstrset.nim index 9cdb5ed35..15024c3f1 100644 --- a/tests/stdlib/tstrset.nim +++ b/tests/stdlib/tstrset.nim @@ -8,7 +8,7 @@ type TRadixNodeLinear = object of TRadixNode len: int8 keys: array [0..31, char] - vals: array [0..31, PRadixNode] + vals: array [0..31, PRadixNode] TRadixNodeFull = object of TRadixNode b: array [char, PRadixNode] TRadixNodeLeaf = object of TRadixNode @@ -16,7 +16,7 @@ type PRadixNodeLinear = ref TRadixNodeLinear PRadixNodeFull = ref TRadixNodeFull PRadixNodeLeaf = ref TRadixNodeLeaf - + proc search(r: PRadixNode, s: string): PRadixNode = var r = r var i = 0 @@ -52,7 +52,7 @@ proc contains*(r: PRadixNode, s: string): bool = proc testOrincl*(r: var PRadixNode, s: string): bool = nil - + proc incl*(r: var PRadixNode, s: string) = discard testOrIncl(r, s) proc excl*(r: var PRadixNode, s: string) = diff --git a/tests/stdlib/tstrtabs.nim b/tests/stdlib/tstrtabs.nim index 8404a6c88..a248cc3b2 100644 --- a/tests/stdlib/tstrtabs.nim +++ b/tests/stdlib/tstrtabs.nim @@ -4,7 +4,7 @@ var tab = newStringTable({"key1": "val1", "key2": "val2"}, modeStyleInsensitive) for i in 0..80: tab["key_" & $i] = "value" & $i - + for key, val in pairs(tab): writeLine(stdout, key, ": ", val) writeLine(stdout, "length of table ", $tab.len) diff --git a/tests/stdlib/ttime.nim b/tests/stdlib/ttime.nim index bad818816..859f0abdd 100644 --- a/tests/stdlib/ttime.nim +++ b/tests/stdlib/ttime.nim @@ -1,6 +1,6 @@ -# test the new time module - -import - times - -write(stdout, $getTime()) +# test the new time module + +import + times + +write(stdout, $getTime()) diff --git a/tests/stdlib/twalker.nim b/tests/stdlib/twalker.nim index aad0fa786..91c97df01 100644 --- a/tests/stdlib/twalker.nim +++ b/tests/stdlib/twalker.nim @@ -1,13 +1,13 @@ -# iterate over all files with a given filter: - -import - "../../lib/pure/os.nim", ../../ lib / pure / times - -proc main(filter: string) = - for filename in walkFiles(filter): - writeLine(stdout, filename) - - for key, val in envPairs(): - writeLine(stdout, key & '=' & val) - -main("*.nim") +# iterate over all files with a given filter: + +import + "../../lib/pure/os.nim", ../../ lib / pure / times + +proc main(filter: string) = + for filename in walkFiles(filter): + writeLine(stdout, filename) + + for key, val in envPairs(): + writeLine(stdout, key & '=' & val) + +main("*.nim") |