diff options
Diffstat (limited to 'tests/stdlib')
53 files changed, 466 insertions, 199 deletions
diff --git a/tests/stdlib/nre/captures.nim b/tests/stdlib/nre/captures.nim index 31de71154..bd5e83ecc 100644 --- a/tests/stdlib/nre/captures.nim +++ b/tests/stdlib/nre/captures.nim @@ -9,16 +9,16 @@ suite "captures": test "capture bounds are correct": let ex1 = re("([0-9])") check("1 23".find(ex1).matchBounds == 0 .. 0) - check("1 23".find(ex1).captureBounds[0].get == 0 .. 0) + check("1 23".find(ex1).captureBounds[0] == 0 .. 0) check("1 23".find(ex1, 1).matchBounds == 2 .. 2) check("1 23".find(ex1, 3).matchBounds == 3 .. 3) let ex2 = re("()()()()()()()()()()([0-9])") - check("824".find(ex2).captureBounds[0].get == 0 .. -1) - check("824".find(ex2).captureBounds[10].get == 0 .. 0) + check("824".find(ex2).captureBounds[0] == 0 .. -1) + check("824".find(ex2).captureBounds[10] == 0 .. 0) let ex3 = re("([0-9]+)") - check("824".find(ex3).captureBounds[0].get == 0 .. 2) + check("824".find(ex3).captureBounds[0] == 0 .. 2) test "named captures": let ex1 = "foobar".find(re("(?<foo>foo)(?<bar>bar)")) @@ -26,13 +26,19 @@ suite "captures": check(ex1.captures["bar"] == "bar") let ex2 = "foo".find(re("(?<foo>foo)(?<bar>bar)?")) + check("foo" in ex2.captureBounds) check(ex2.captures["foo"] == "foo") - check(ex2.captures["bar"] == "") + check(not ("bar" in ex2.captures)) + expect KeyError: + discard ex2.captures["bar"] test "named capture bounds": let ex1 = "foo".find(re("(?<foo>foo)(?<bar>bar)?")) - check(ex1.captureBounds["foo"] == some(0..2)) - check(ex1.captureBounds["bar"] == none(Slice[int])) + check("foo" in ex1.captureBounds) + check(ex1.captureBounds["foo"] == 0..2) + check(not ("bar" in ex1.captures)) + expect KeyError: + discard ex1.captures["bar"] test "capture count": let ex1 = re("(?<foo>foo)(?<bar>bar)?") @@ -41,19 +47,18 @@ suite "captures": test "named capture table": let ex1 = "foo".find(re("(?<foo>foo)(?<bar>bar)?")) - check(ex1.captures.toTable == {"foo" : "foo", "bar" : ""}.toTable()) - check(ex1.captureBounds.toTable == {"foo" : some(0..2), "bar" : none(Slice[int])}.toTable()) - check(ex1.captures.toTable("") == {"foo" : "foo", "bar" : ""}.toTable()) + check(ex1.captures.toTable == {"foo" : "foo"}.toTable()) + check(ex1.captureBounds.toTable == {"foo" : 0..2}.toTable()) let ex2 = "foobar".find(re("(?<foo>foo)(?<bar>bar)?")) check(ex2.captures.toTable == {"foo" : "foo", "bar" : "bar"}.toTable()) test "capture sequence": let ex1 = "foo".find(re("(?<foo>foo)(?<bar>bar)?")) - check(ex1.captures.toSeq == @["foo", ""]) + check(ex1.captures.toSeq == @[some("foo"), none(string)]) check(ex1.captureBounds.toSeq == @[some(0..2), none(Slice[int])]) - check(ex1.captures.toSeq("") == @["foo", ""]) + check(ex1.captures.toSeq(some("")) == @[some("foo"), some("")]) let ex2 = "foobar".find(re("(?<foo>foo)(?<bar>bar)?")) - check(ex2.captures.toSeq == @["foo", "bar"]) + check(ex2.captures.toSeq == @[some("foo"), some("bar")]) diff --git a/tests/stdlib/nre/match.nim b/tests/stdlib/nre/match.nim index 38ee5214b..06b69fd04 100644 --- a/tests/stdlib/nre/match.nim +++ b/tests/stdlib/nre/match.nim @@ -10,9 +10,9 @@ suite "match": check("abc".match(re"(\w)").captures[0] == "a") check("abc".match(re"(?<letter>\w)").captures["letter"] == "a") check("abc".match(re"(\w)\w").captures[-1] == "ab") - check("abc".match(re"(\w)").captureBounds[0].get == 0 .. 0) - check("abc".match(re"").captureBounds[-1].get == 0 .. -1) - check("abc".match(re"abc").captureBounds[-1].get == 0 .. 2) + check("abc".match(re"(\w)").captureBounds[0] == 0 .. 0) + check("abc".match(re"").captureBounds[-1] == 0 .. -1) + check("abc".match(re"abc").captureBounds[-1] == 0 .. 2) test "match test cases": check("123".match(re"").matchBounds == 0 .. -1) diff --git a/tests/stdlib/nre/replace.nim b/tests/stdlib/nre/replace.nim index b762271a2..812a7f384 100644 --- a/tests/stdlib/nre/replace.nim +++ b/tests/stdlib/nre/replace.nim @@ -16,5 +16,7 @@ suite "replace": check("123".replace(re"(?<foo>\d)(\d)", "${foo}$#$#") == "1123") test "replacing missing captures should throw instead of segfaulting": - discard "ab".replace(re"(a)|(b)", "$1$2") - discard "b".replace(re"(a)?(b)", "$1$2") + expect IndexError: discard "ab".replace(re"(a)|(b)", "$1$2") + expect IndexError: discard "b".replace(re"(a)?(b)", "$1$2") + expect KeyError: discard "b".replace(re"(a)?", "${foo}") + expect KeyError: discard "b".replace(re"(?<foo>a)?", "${foo}") diff --git a/tests/stdlib/osproctest.nim b/tests/stdlib/osproctest.nim new file mode 100644 index 000000000..8c4fba9ba --- /dev/null +++ b/tests/stdlib/osproctest.nim @@ -0,0 +1,8 @@ +# This is test program for the osproc module. + +import os + +echo getCurrentDir() + +for i in 1..paramCount(): + echo paramStr(i) diff --git a/tests/stdlib/somesql.sql b/tests/stdlib/somesql.sql index 285f93cec..74afcbab0 100644 --- a/tests/stdlib/somesql.sql +++ b/tests/stdlib/somesql.sql @@ -295,4 +295,4 @@ create table anon207( anon209 varchar(30) not null, anon204 varchar(30) default null, anon70 int not null references anon40(anon41)); - +select * from anon207 where anon41 in (1, 2, 3); diff --git a/tests/stdlib/t8925.nim b/tests/stdlib/t8925.nim index d3dc1ea86..dbf55fd88 100644 --- a/tests/stdlib/t8925.nim +++ b/tests/stdlib/t8925.nim @@ -1,6 +1,6 @@ discard """ - file: "strscans.nim" errormsg: "type mismatch between pattern '$i' (position: 1) and HourRange var 'hour'" + file: "strscans.nim" """ import strscans diff --git a/tests/stdlib/tbitops.nim b/tests/stdlib/tbitops.nim index 8301256c4..d8c6da1d4 100644 --- a/tests/stdlib/tbitops.nim +++ b/tests/stdlib/tbitops.nim @@ -1,5 +1,4 @@ discard """ - file: "tbitops.nim" output: "OK" """ import bitops diff --git a/tests/stdlib/tbitops2.nim b/tests/stdlib/tbitops2.nim index 31952316c..e8c7318be 100644 --- a/tests/stdlib/tbitops2.nim +++ b/tests/stdlib/tbitops2.nim @@ -1,5 +1,4 @@ discard """ - file: "tbitops.nim" output: "OK" """ import bitops diff --git a/tests/stdlib/tcgi.nim b/tests/stdlib/tcgi.nim new file mode 100644 index 000000000..bc177125e --- /dev/null +++ b/tests/stdlib/tcgi.nim @@ -0,0 +1,17 @@ +import unittest +import cgi, strtabs + +suite "Test cgi module": + const queryString = "foo=bar&фу=бар&checked=✓&list=1,2,3&with_space=text%20with%20space" + + test "test query parsing with readData": + let parsedQuery = readData(queryString) + + check parsedQuery["foo"] == "bar" + check parsedQuery["фу"] == "бар" + check parsedQuery["checked"] == "✓" + check parsedQuery["list"] == "1,2,3" + check parsedQuery["with_space"] == "text with space" + + expect KeyError: + discard parsedQuery["not_existing_key"] diff --git a/tests/stdlib/tcputime.nim b/tests/stdlib/tcputime.nim deleted file mode 100644 index b0cc19c6c..000000000 --- a/tests/stdlib/tcputime.nim +++ /dev/null @@ -1,11 +0,0 @@ -import times, os - -var e = epochTime() -var c = cpuTime() - -os.sleep(1000) - -e = epochTime() - e -c = cpuTime() - c - -echo "epochTime: ", e, " cpuTime: ", c diff --git a/tests/stdlib/thashes.nim b/tests/stdlib/thashes.nim index c442b43fb..2cd1e4e47 100644 --- a/tests/stdlib/thashes.nim +++ b/tests/stdlib/thashes.nim @@ -1,5 +1,14 @@ -import unittest -import hashes + +discard """ +output: ''' +[Suite] hashes + +[Suite] hashing + +''' +""" + +import unittest, hashes suite "hashes": suite "hashing": diff --git a/tests/stdlib/thtmlparser.nim b/tests/stdlib/thtmlparser.nim index d59e8b302..0457585d0 100644 --- a/tests/stdlib/thtmlparser.nim +++ b/tests/stdlib/thtmlparser.nim @@ -78,3 +78,61 @@ block t2814: echo "case " & ltype[0] & " failed !" quit(2) echo "true" + +block t6154: + let foo = """ + <!DOCTYPE html> + <html> + <head> + <title> foobar </title> + </head> + <body> + <p class=foo id=bar></p> + <p something=	foo	bar²></p> + <p something= 	foo	bar² foo =bloo></p> + <p class="foo2" id="bar2"></p> + <p wrong= ></p> + <p data-foo data-bar="correct!" enabled ></p> + <p quux whatever></p> + </body> + </html> + """ + + var errors: seq[string] = @[] + let html = parseHtml(newStringStream(foo), "statichtml", errors=errors) + doAssert "statichtml(11, 18) Error: attribute value expected" in errors + let ps = html.findAll("p") + doAssert ps.len == 7 + + doAssert ps[0].attrsLen == 2 + doAssert ps[0].attr("class") == "foo" + doAssert ps[0].attr("id") == "bar" + doassert ps[0].len == 0 + + doAssert ps[1].attrsLen == 1 + doAssert ps[1].attr("something") == "\tfoo\tbar²" + doassert ps[1].len == 0 + + doAssert ps[2].attrsLen == 2 + doAssert ps[2].attr("something") == "\tfoo\tbar²" + doAssert ps[2].attr("foo") == "bloo" + doassert ps[2].len == 0 + + doAssert ps[3].attrsLen == 2 + doAssert ps[3].attr("class") == "foo2" + doAssert ps[3].attr("id") == "bar2" + doassert ps[3].len == 0 + + doAssert ps[4].attrsLen == 1 + doAssert ps[4].attr("wrong") == "" + + doAssert ps[5].attrsLen == 3 + doAssert ps[5].attr("data-foo") == "" + doAssert ps[5].attr("data-bar") == "correct!" + doAssert ps[5].attr("enabled") == "" + doassert ps[5].len == 0 + + doAssert ps[6].attrsLen == 2 + doAssert ps[6].attr("quux") == "" + doAssert ps[6].attr("whatever") == "" + doassert ps[6].len == 0 diff --git a/tests/stdlib/thttpcore.nim b/tests/stdlib/thttpcore.nim index 9f99df93a..889c734c5 100644 --- a/tests/stdlib/thttpcore.nim +++ b/tests/stdlib/thttpcore.nim @@ -1,3 +1,6 @@ +discard """ +output: "[Suite] httpcore" +""" import unittest diff --git a/tests/stdlib/tjsonexternproc.nim b/tests/stdlib/tjsonexternproc.nim index ec90e580d..1091d72cd 100644 --- a/tests/stdlib/tjsonexternproc.nim +++ b/tests/stdlib/tjsonexternproc.nim @@ -1,5 +1,11 @@ +discard """ +output: ''' +{"data":[1]} +''' +""" + # Test case for https://github.com/nim-lang/Nim/issues/6385 import mjsonexternproc # import json -foo(1) \ No newline at end of file +foo(1) diff --git a/tests/stdlib/tjsonmacro.nim b/tests/stdlib/tjsonmacro.nim index bf0bb3ea7..33332447b 100644 --- a/tests/stdlib/tjsonmacro.nim +++ b/tests/stdlib/tjsonmacro.nim @@ -1,10 +1,9 @@ discard """ - file: "tjsonmacro.nim" output: "" """ import json, strutils, options, tables -when isMainModule: +when true: # Tests inspired by own use case (with some additional tests). # This should succeed. type diff --git a/tests/stdlib/tjsonmacro_reject.nim b/tests/stdlib/tjsonmacro_reject.nim index 00506449f..ada365d7d 100644 --- a/tests/stdlib/tjsonmacro_reject.nim +++ b/tests/stdlib/tjsonmacro_reject.nim @@ -1,7 +1,7 @@ discard """ + errormsg: "Use a named tuple instead of: (string, float)" file: "tjsonmacro_reject.nim" line: 11 - errormsg: "Use a named tuple instead of: (string, float)" """ import json @@ -15,4 +15,4 @@ let j = """ {"engine": {"name": "V8", "capacity": 5.5}, model: "Skyline"} """ let parsed = parseJson(j) -echo(to(parsed, Car)) \ No newline at end of file +echo(to(parsed, Car)) diff --git a/tests/stdlib/tjsonmacro_reject2.nim b/tests/stdlib/tjsonmacro_reject2.nim index b01153553..e13dad307 100644 --- a/tests/stdlib/tjsonmacro_reject2.nim +++ b/tests/stdlib/tjsonmacro_reject2.nim @@ -1,7 +1,7 @@ discard """ + errormsg: "The `to` macro does not support ref objects with cycles." file: "tjsonmacro_reject2.nim" line: 10 - errormsg: "The `to` macro does not support ref objects with cycles." """ import json @@ -18,4 +18,4 @@ let data = """ """ let dataParsed = parseJson(data) -let dataDeser = to(dataParsed, Cycle) \ No newline at end of file +let dataDeser = to(dataParsed, Cycle) diff --git a/tests/stdlib/tjsontestsuite.nim b/tests/stdlib/tjsontestsuite.nim index 06f783a73..db31963fd 100644 --- a/tests/stdlib/tjsontestsuite.nim +++ b/tests/stdlib/tjsontestsuite.nim @@ -1,3 +1,7 @@ +discard """ +disabled: true +""" + ## JSON tests based on https://github.com/nst/JSONTestSuite import unittest, diff --git a/tests/stdlib/tlists.nim b/tests/stdlib/tlists.nim index 37e73c53f..a288af781 100644 --- a/tests/stdlib/tlists.nim +++ b/tests/stdlib/tlists.nim @@ -8,14 +8,15 @@ const data = [1, 2, 3, 4, 5, 6] block SinglyLinkedListTest1: - var L: TSinglyLinkedList[int] + var L: SinglyLinkedList[int] for d in items(data): L.prepend(d) - assert($L == "[6, 5, 4, 3, 2, 1]") + for d in items(data): L.append(d) + assert($L == "[6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6]") assert(4 in L) block SinglyLinkedListTest2: - var L: TSinglyLinkedList[string] + var L: SinglyLinkedList[string] for d in items(data): L.prepend($d) assert($L == """["6", "5", "4", "3", "2", "1"]""") @@ -23,7 +24,7 @@ block SinglyLinkedListTest2: block DoublyLinkedListTest1: - var L: TDoublyLinkedList[int] + var L: DoublyLinkedList[int] for d in items(data): L.prepend(d) for d in items(data): L.append(d) L.remove(L.find(1)) @@ -32,7 +33,7 @@ block DoublyLinkedListTest1: assert(4 in L) block SinglyLinkedRingTest1: - var L: TSinglyLinkedRing[int] + var L: SinglyLinkedRing[int] L.prepend(4) assert($L == "[4]") L.prepend(4) @@ -42,7 +43,7 @@ block SinglyLinkedRingTest1: block DoublyLinkedRingTest1: - var L: TDoublyLinkedRing[int] + var L: DoublyLinkedRing[int] L.prepend(4) assert($L == "[4]") L.prepend(4) diff --git a/tests/stdlib/tmath2.nim b/tests/stdlib/tmath2.nim deleted file mode 100644 index eb0506f5f..000000000 --- a/tests/stdlib/tmath2.nim +++ /dev/null @@ -1,85 +0,0 @@ -# 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/tmemfiles1.nim b/tests/stdlib/tmemfiles1.nim index 8b66dfcc1..21a65369f 100644 --- a/tests/stdlib/tmemfiles1.nim +++ b/tests/stdlib/tmemfiles1.nim @@ -1,6 +1,3 @@ -discard """ - file: "tmemfiles1.nim" -""" import memfiles, os var mm: MemFile @@ -8,5 +5,5 @@ var # Create a new file mm = memfiles.open(fn, mode = fmReadWrite, newFileSize = 20) mm.close() -mm.close() +# mm.close() if fileExists(fn): removeFile(fn) diff --git a/tests/stdlib/tmemlines.nim b/tests/stdlib/tmemlines.nim index 19821ea26..98e03b5bb 100644 --- a/tests/stdlib/tmemlines.nim +++ b/tests/stdlib/tmemlines.nim @@ -1,5 +1,9 @@ +discard """ +outputsub: "" +""" + import memfiles -var inp = memfiles.open("readme.txt") +var inp = memfiles.open("tests/stdlib/tmemlines.nim") for line in lines(inp): echo("#" & line & "#") close(inp) diff --git a/tests/stdlib/tmemlinesBuf.nim b/tests/stdlib/tmemlinesBuf.nim index 21edc2322..97ad751ee 100644 --- a/tests/stdlib/tmemlinesBuf.nim +++ b/tests/stdlib/tmemlinesBuf.nim @@ -1,6 +1,15 @@ +discard """ +output: "15" +disabled: "appveyor" +""" + import memfiles -var inp = memfiles.open("readme.txt") +var inp = memfiles.open("tests/stdlib/tmemlinesBuf.nim") var buffer: TaintedString = "" +var lineCount = 0 for line in lines(inp, buffer): - echo("#" & line & "#") + lineCount += 1 + close(inp) + +echo lineCount diff --git a/tests/stdlib/tmemmapstreams.nim b/tests/stdlib/tmemmapstreams.nim index 243574f1a..dd011d777 100644 --- a/tests/stdlib/tmemmapstreams.nim +++ b/tests/stdlib/tmemmapstreams.nim @@ -1,6 +1,6 @@ discard """ - file: "tmemmapstreams.nim" - output: '''Created size: 10 +output: ''' +Created size: 10 Position after writing: 5 Position after writing one char: 6 Peeked data: Hello diff --git a/tests/stdlib/tmemslices.nim b/tests/stdlib/tmemslices.nim index 951807cc4..c0d6d3960 100644 --- a/tests/stdlib/tmemslices.nim +++ b/tests/stdlib/tmemslices.nim @@ -1,5 +1,11 @@ +discard """ +outputsub: "rlwuiadtrnzb" +""" + +# chatever the sub pattern it will find itself + import memfiles -var inp = memfiles.open("readme.txt") +var inp = memfiles.open("tests/stdlib/tmemslices.nim") for mem in memSlices(inp): if mem.size > 3: echo("#" & $mem & "#") diff --git a/tests/stdlib/tnativesockets.nim b/tests/stdlib/tnativesockets.nim deleted file mode 100644 index c683647bc..000000000 --- a/tests/stdlib/tnativesockets.nim +++ /dev/null @@ -1,8 +0,0 @@ -import nativesockets, unittest - -suite "nativesockets": - test "getHostname": - let hostname = getHostname() - check hostname.len > 0 - check hostname.len < 64 - diff --git a/tests/stdlib/tnet.nim b/tests/stdlib/tnet.nim index 009561272..2dd22796c 100644 --- a/tests/stdlib/tnet.nim +++ b/tests/stdlib/tnet.nim @@ -1,3 +1,7 @@ +discard """ +outputsub: "" +""" + import net, nativesockets import unittest diff --git a/tests/stdlib/tos.nim b/tests/stdlib/tos.nim index c10f7036b..467f64fff 100644 --- a/tests/stdlib/tos.nim +++ b/tests/stdlib/tos.nim @@ -170,6 +170,25 @@ block modificationTime: echo getLastModificationTime("a") == tm removeFile("a") +block walkDirRec: + createDir("walkdir_test/a/b") + open("walkdir_test/a/b/file_1", fmWrite).close() + open("walkdir_test/a/file_2", fmWrite).close() + + for p in walkDirRec("walkdir_test"): + doAssert p.fileExists + doAssert p.startsWith("walkdir_test") + + var s: seq[string] + for p in walkDirRec("walkdir_test", {pcFile}, {pcDir}, relative=true): + s.add(p) + + doAssert s.len == 2 + doAssert "a" / "b" / "file_1" in s + doAssert "a" / "file_2" in s + + removeDir("walkdir_test") + block normalizedPath: when defined(posix): block relative: diff --git a/tests/stdlib/tospaths.nim b/tests/stdlib/tospaths.nim index 9e2a5605c..bee9bab76 100644 --- a/tests/stdlib/tospaths.nim +++ b/tests/stdlib/tospaths.nim @@ -1,5 +1,4 @@ discard """ - file: "tospaths.nim" output: "" """ # test the ospaths module diff --git a/tests/stdlib/tosproc.nim b/tests/stdlib/tosproc.nim new file mode 100644 index 000000000..9d57d4574 --- /dev/null +++ b/tests/stdlib/tosproc.nim @@ -0,0 +1,23 @@ +discard """ + output: "" +""" +# test the osproc module + +import os, osproc + +block execProcessTest: + let dir = parentDir(currentSourcePath()) + let (outp, err) = execCmdEx("nim c " & quoteShell(dir / "osproctest.nim")) + doAssert err == 0 + let exePath = dir / addFileExt("osproctest", ExeExt) + let outStr1 = execProcess(exePath, workingDir=dir, args=["foo", "b A r"], options={}) + doAssert outStr1 == dir & "\nfoo\nb A r\n" + + const testDir = "t e st" + createDir(testDir) + doAssert dirExists(testDir) + let outStr2 = execProcess(exePath, workingDir=testDir, args=["x yz"], options={}) + doAssert outStr2 == absolutePath(testDir) & "\nx yz\n" + + removeDir(testDir) + removeFile(exePath) diff --git a/tests/stdlib/tosprocterminate.nim b/tests/stdlib/tosprocterminate.nim index 7fc6c5d85..a46d91d68 100644 --- a/tests/stdlib/tosprocterminate.nim +++ b/tests/stdlib/tosprocterminate.nim @@ -1,3 +1,7 @@ +discard """ +outputsub: "SUCCESS" +""" + import os, osproc when defined(Windows): diff --git a/tests/stdlib/tparsesql.nim b/tests/stdlib/tparsesql.nim index 126020ed6..8cf8fa848 100644 --- a/tests/stdlib/tparsesql.nim +++ b/tests/stdlib/tparsesql.nim @@ -1,7 +1,3 @@ -discard """ - file: "tparsesql.nim" -""" - import parsesql doAssert $parseSQL("SELECT foo FROM table;") == "select foo from table;" diff --git a/tests/stdlib/tparsopt.nim b/tests/stdlib/tparsopt.nim index 848fba2da..948bc8d5f 100644 --- a/tests/stdlib/tparsopt.nim +++ b/tests/stdlib/tparsopt.nim @@ -1,4 +1,10 @@ -# Test the new parseopt module +discard """ +disabled: true +""" + +# this file has a type in the name, and it does not really test +# parseopt module, because tester has no support to set arguments. Test the +# new parseopt module. Therefore it is disabled. import parseopt diff --git a/tests/stdlib/tposix.nim b/tests/stdlib/tposix.nim index 229035d22..14f1fd6e2 100644 --- a/tests/stdlib/tposix.nim +++ b/tests/stdlib/tposix.nim @@ -1,3 +1,7 @@ +discard """ +outputsub: "" +""" + # Test Posix interface when not defined(windows): @@ -5,7 +9,7 @@ when not defined(windows): import posix var - u: Tutsname + u: Utsname discard uname(u) @@ -13,4 +17,3 @@ when not defined(windows): writeLine(stdout, u.nodename) writeLine(stdout, u.release) writeLine(stdout, u.machine) - diff --git a/tests/stdlib/tquit.nim b/tests/stdlib/tquit.nim index d18b468c8..1f9283ec4 100644 --- a/tests/stdlib/tquit.nim +++ b/tests/stdlib/tquit.nim @@ -1,3 +1,10 @@ +discard """ +output: ''' +just exiting... +''' +joinable: false +""" + # Test the new beforeQuit variable: proc myExit() {.noconv.} = diff --git a/tests/stdlib/tregex.nim b/tests/stdlib/tregex.nim index ae6714de1..21f4e6743 100644 --- a/tests/stdlib/tregex.nim +++ b/tests/stdlib/tregex.nim @@ -1,5 +1,4 @@ discard """ - file: "tregex.nim" output: "key: keyAYes!" """ # Test the new regular expression module @@ -27,5 +26,3 @@ else: echo("Bug!") #OUT key: keyAYes! - - diff --git a/tests/stdlib/trepr.nim b/tests/stdlib/trepr.nim index 18fe7e054..33cb581ef 100644 --- a/tests/stdlib/trepr.nim +++ b/tests/stdlib/trepr.nim @@ -1,5 +1,4 @@ discard """ - file: "trepr.nim" output: "{a, b}{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}" """ @@ -26,4 +25,3 @@ when false: # "a", "b", "c", "d", "e" #] #echo(repr(testseq)) - diff --git a/tests/stdlib/trepr2.nim b/tests/stdlib/trepr2.nim index 300df565d..89379da96 100644 --- a/tests/stdlib/trepr2.nim +++ b/tests/stdlib/trepr2.nim @@ -1,3 +1,8 @@ +discard """ +outputsub: "" +""" + +# output not testable because repr prints pointer adresses # test the new "repr" built-in proc type diff --git a/tests/stdlib/trstgen.nim b/tests/stdlib/trstgen.nim index c702ccc2a..fd89f68af 100644 --- a/tests/stdlib/trstgen.nim +++ b/tests/stdlib/trstgen.nim @@ -1,3 +1,7 @@ +discard """ +outputsub: "" +""" + # tests for rstgen module. import ../../lib/packages/docutils/rstgen @@ -27,7 +31,7 @@ suite "YAML syntax highlighting": <span class="Punctuation">?</span> <span class="StringLit">key</span> <span class="Punctuation">:</span> <span class="StringLit">value</span> <span class="Keyword">...</span></pre>""" - + test "Block scalars": let input = """.. code-block:: yaml a literal block scalar: | @@ -55,7 +59,7 @@ suite "YAML syntax highlighting": <span class="StringLit">another literal block scalar</span><span class="Punctuation">:</span> <span class="Command">|+</span> <span class="Comment"># comment after header</span><span class="LongStringLit"> allowed, since more indented than parent</span></pre>""" - + test "Directives": let input = """.. code-block:: yaml %YAML 1.2 @@ -97,7 +101,7 @@ suite "YAML syntax highlighting": <span class="StringLit">more numbers</span><span class="Punctuation">:</span> <span class="Punctuation">[</span><span class="DecNumber">-783</span><span class="Punctuation">,</span> <span class="FloatNumber">11e78</span><span class="Punctuation">]</span><span class="Punctuation">,</span> <span class="StringLit">not numbers</span><span class="Punctuation">:</span> <span class="Punctuation">[</span> <span class="StringLit">42e</span><span class="Punctuation">,</span> <span class="StringLit">0023</span><span class="Punctuation">,</span> <span class="StringLit">+32.37</span><span class="Punctuation">,</span> <span class="StringLit">8 ball</span><span class="Punctuation">]</span> <span class="Punctuation">}</span></pre>""" - + test "Anchors, Aliases, Tags": let input = """.. code-block:: yaml --- !!map @@ -136,4 +140,4 @@ suite "YAML syntax highlighting": <span class="DecNumber">-3</span> <span class="DecNumber">-4</span> <span class="StringLit">example.com/not/a#comment</span><span class="Punctuation">:</span> - <span class="StringLit">?not a map key</span></pre>""" \ No newline at end of file + <span class="StringLit">?not a map key</span></pre>""" diff --git a/tests/stdlib/tsortcall.nim b/tests/stdlib/tsortcall.nim index 45b98805f..242e3fe4c 100644 --- a/tests/stdlib/tsortcall.nim +++ b/tests/stdlib/tsortcall.nim @@ -1,3 +1,7 @@ +discard """ +outputsub: "" +""" + import algorithm import unittest @@ -40,7 +44,7 @@ suite "test sort, sorted, and isSorted procs": test "test the shortcut versions with descending sort order": check(not unSortedIntSeq.isSorted(SortOrder.Descending)) check sorted(unSortedIntSeq, SortOrder.Descending) == reversed sortedIntSeq - check sorted(unSortedIntSeq).isSorted(SortOrder.Descending) + check sorted(unSortedIntSeq).isSorted(SortOrder.Ascending) unSortedIntSeq.sort(SortOrder.Descending) check unSortedIntSeq == reversed sortedIntSeq diff --git a/tests/stdlib/tsqlparser.nim b/tests/stdlib/tsqlparser.nim index 4a7b2f7d7..11ee22e2b 100644 --- a/tests/stdlib/tsqlparser.nim +++ b/tests/stdlib/tsqlparser.nim @@ -6,7 +6,7 @@ discard """ import parsesql, streams, os -var tree = parseSql(newFileStream(getAppDir() / "somesql.sql"), "somesql") +var tree = parseSql(newFileStream(parentDir(currentSourcePath) / "somesql.sql"), "somesql") discard renderSql(tree) echo "true" diff --git a/tests/stdlib/tissues.nim b/tests/stdlib/tstdlib_issues.nim index b5a1c8206..b5a1c8206 100644 --- a/tests/stdlib/tissues.nim +++ b/tests/stdlib/tstdlib_issues.nim diff --git a/tests/stdlib/tvarious.nim b/tests/stdlib/tstdlib_various.nim index 7abc9a391..d1723df78 100644 --- a/tests/stdlib/tvarious.nim +++ b/tests/stdlib/tstdlib_various.nim @@ -219,7 +219,7 @@ block tsplit2: block tsqlparser: # Just check that we can parse 'somesql' and render it without crashes. - var tree = parseSql(newFileStream(getAppDir() / "somesql.sql"), "somesql") + var tree = parseSql(newFileStream( parentDir(currentSourcePath) / "somesql.sql"), "somesql") discard renderSql(tree) diff --git a/tests/stdlib/tstreams.nim b/tests/stdlib/tstreams.nim index 16dbc0e1b..559824d85 100644 --- a/tests/stdlib/tstreams.nim +++ b/tests/stdlib/tstreams.nim @@ -1,12 +1,25 @@ +discard """ +input: "Arne" +output: ''' +Hello! What is your name? +Nice name: Arne +fs is: nil + +threw exception +''' +disabled: "windows" +""" + + import streams block tstreams: var outp = newFileStream(stdout) var inp = newFileStream(stdin) - write(outp, "Hello! What is your name?") + writeLine(outp, "Hello! What is your name?") var line = readLine(inp) - write(outp, "Nice name: " & line) + writeLine(outp, "Nice name: " & line) block tstreams2: diff --git a/tests/stdlib/tstreams2.nim b/tests/stdlib/tstreams2.nim index 90102d8e3..70f0bac32 100644 --- a/tests/stdlib/tstreams2.nim +++ b/tests/stdlib/tstreams2.nim @@ -1,5 +1,4 @@ discard """ - file: "tstreams2.nim" output: '''fs is: nil''' """ import streams diff --git a/tests/stdlib/tstreams3.nim b/tests/stdlib/tstreams3.nim index b2c9170e3..e3b395e05 100644 --- a/tests/stdlib/tstreams3.nim +++ b/tests/stdlib/tstreams3.nim @@ -1,5 +1,4 @@ discard """ - file: "tstreams3.nim" output: "threw exception" """ import streams diff --git a/tests/stdlib/tstring.nim b/tests/stdlib/tstring.nim index 660746150..852ff4fb7 100644 --- a/tests/stdlib/tstring.nim +++ b/tests/stdlib/tstring.nim @@ -1,5 +1,4 @@ discard """ - file: "tstring.nim" output: "OK" """ const characters = "abcdefghijklmnopqrstuvwxyz" diff --git a/tests/stdlib/tstrscans.nim b/tests/stdlib/tstrscans.nim new file mode 100644 index 000000000..08fc14e45 --- /dev/null +++ b/tests/stdlib/tstrscans.nim @@ -0,0 +1,86 @@ +discard """ + output: "" +""" + +import strscans + +block ParsePasswd: + proc parsePasswd(content: string): seq[string] = + result = @[] + var idx = 0 + while true: + var entry = "" + if scanp(content, idx, +(~{'\L', '\0'} -> entry.add($_)), '\L'): + result.add entry + else: + break + + const etc_passwd = """root:x:0:0:root:/root:/bin/bash +daemon:x:1:1:daemon:/usr/sbin:/bin/sh +bin:x:2:2:bin:/bin:/bin/sh +sys:x:3:3:sys:/dev:/bin/sh +nobody:x:65534:65534:nobody:/nonexistent:/bin/sh +messagebus:x:103:107::/var/run/dbus:/bin/false +""" + + const parsed_etc_passwd = @[ + "root:x:0:0:root:/root:/bin/bash", + "daemon:x:1:1:daemon:/usr/sbin:/bin/sh", + "bin:x:2:2:bin:/bin:/bin/sh", + "sys:x:3:3:sys:/dev:/bin/sh", + "nobody:x:65534:65534:nobody:/nonexistent:/bin/sh", + "messagebus:x:103:107::/var/run/dbus:/bin/false", + ] + doAssert etc_passwd.parsePasswd == parsed_etc_passwd + +block LastNot: + var idx : int + + idx = 0 + doAssert scanp("foo", idx, 'f', 'o', ~'a') + + idx = 0 + doAssert scanp("foo", idx, 'f', 'o', ~'o') == false + + idx = 0 + doAssert scanp("foox", idx, 'f', 'o', ~'o') == false + + idx = 0 + doAssert scanp("foox", idx, 'f', 'o', ~'a') + +block LastOptional: + var idx = 0 + doAssert scanp("foo", idx, 'f', 'o', 'o', ?'o') + +block Tuple: + var idx = 0 + doAssert scanp("foo", idx, ('f', 'o', 'o')) + +block NotWithOptional: + var idx : int + + idx = 0 + doAssert scanp("bc", idx, ~(?'b', 'c')) == false + + idx = 0 + doAssert scanp("c", idx, ~(?'b', 'c')) == false + + idx = 0 + doAssert scanp("b", idx, ~(?'b', 'c')) + +block NotEmpty: + var idx = 0 + doAssert scanp("", idx, ~()) == false + +block EmptyTuple: + var idx = 0 + doAssert scanp("ab", idx, 'a', (), 'b') + +block Arrow: + let text = "foo;bar;baz;" + var idx = 0 + var res = "" + doAssert scanp(text, idx, +(~{';','\0'} -> (discard $_)), ';') + doAssert scanp(text, idx, +(~{';','\0'} -> (discard $_)), ';') + doAssert scanp(text, idx, +(~{';','\0'} -> (discard $_)), ';') + doAssert scanp(text, idx, +(~{';','\0'} -> (discard $_)), ';') == false diff --git a/tests/stdlib/tstrtabs.nim b/tests/stdlib/tstrtabs.nim index a248cc3b2..18ed57167 100644 --- a/tests/stdlib/tstrtabs.nim +++ b/tests/stdlib/tstrtabs.nim @@ -1,3 +1,92 @@ +discard """ +sortoutput: true +output: ''' +key1: value1 +key2: value2 +key_0: value0 +key_10: value10 +key_11: value11 +key_12: value12 +key_13: value13 +key_14: value14 +key_15: value15 +key_16: value16 +key_17: value17 +key_18: value18 +key_19: value19 +key_20: value20 +key_21: value21 +key_22: value22 +key_23: value23 +key_24: value24 +key_25: value25 +key_26: value26 +key_27: value27 +key_28: value28 +key_29: value29 +key_30: value30 +key_31: value31 +key_32: value32 +key_33: value33 +key_34: value34 +key_35: value35 +key_36: value36 +key_37: value37 +key_38: value38 +key_39: value39 +key_3: value3 +key_40: value40 +key_41: value41 +key_42: value42 +key_43: value43 +key_44: value44 +key_45: value45 +key_46: value46 +key_47: value47 +key_48: value48 +key_49: value49 +key_4: value4 +key_50: value50 +key_51: value51 +key_52: value52 +key_53: value53 +key_54: value54 +key_55: value55 +key_56: value56 +key_57: value57 +key_58: value58 +key_59: value59 +key_5: value5 +key_60: value60 +key_61: value61 +key_62: value62 +key_63: value63 +key_64: value64 +key_65: value65 +key_66: value66 +key_67: value67 +key_68: value68 +key_69: value69 +key_6: value6 +key_70: value70 +key_71: value71 +key_72: value72 +key_73: value73 +key_74: value74 +key_75: value75 +key_76: value76 +key_77: value77 +key_78: value78 +key_79: value79 +key_7: value7 +key_80: value80 +key_8: value8 +key_9: value9 +length of table 81 +value1 = value2 +''' +""" + import strtabs var tab = newStringTable({"key1": "val1", "key2": "val2"}, @@ -9,4 +98,4 @@ for key, val in pairs(tab): writeLine(stdout, key, ": ", val) writeLine(stdout, "length of table ", $tab.len) -writeLine(stdout, `%`("$key1 = $key2; ${PATH}", tab, {useEnvironment})) +writeLine(stdout, `%`("$key1 = $key2", tab, {useEnvironment})) diff --git a/tests/stdlib/tstrutil.nim b/tests/stdlib/tstrutil.nim index 64b8f8ecc..fffa85bd1 100644 --- a/tests/stdlib/tstrutil.nim +++ b/tests/stdlib/tstrutil.nim @@ -1,5 +1,4 @@ discard """ - file: "tstrutil.nim" output: "ha/home/a1xyz/usr/bin" """ # test the new strutils module diff --git a/tests/stdlib/tsugar.nim b/tests/stdlib/tsugar.nim index a870bf6fe..111ca96a4 100644 --- a/tests/stdlib/tsugar.nim +++ b/tests/stdlib/tsugar.nim @@ -1,5 +1,4 @@ discard """ - file: "tsugar.nim" output: "" """ import sugar diff --git a/tests/stdlib/ttimes.nim b/tests/stdlib/ttimes.nim index 660c9325f..ed87b15ac 100644 --- a/tests/stdlib/ttimes.nim +++ b/tests/stdlib/ttimes.nim @@ -1,8 +1,5 @@ discard """ - file: "ttimes.nim" target: "c js" - output: '''[Suite] ttimes -''' """ import times, strutils, unittest @@ -84,6 +81,15 @@ template runTimezoneTests() = # formatting timezone as 'Z' for UTC parseTest("2001-01-12T22:04:05Z", "yyyy-MM-dd'T'HH:mm:ss" & tzFormat, "2001-01-12T22:04:05Z", 11) + # timezone offset formats + parseTest("2001-01-12T15:04:05 +7", "yyyy-MM-dd'T'HH:mm:ss z", + "2001-01-12T08:04:05Z", 11) + parseTest("2001-01-12T15:04:05 +07", "yyyy-MM-dd'T'HH:mm:ss zz", + "2001-01-12T08:04:05Z", 11) + parseTest("2001-01-12T15:04:05 +07:00", "yyyy-MM-dd'T'HH:mm:ss zzz", + "2001-01-12T08:04:05Z", 11) + parseTest("2001-01-12T15:04:05 +07:30:59", "yyyy-MM-dd'T'HH:mm:ss zzzz", + "2001-01-12T07:33:06Z", 11) # Kitchen = "3:04PM" parseTestTimeOnly("3:04PM", "h:mmtt", "15:04:00") @@ -116,7 +122,7 @@ suite "ttimes": when defined(linux) or defined(macosx): let tz_dir = getEnv("TZDIR", "/usr/share/zoneinfo") const f = "yyyy-MM-dd HH:mm zzz" - + let orig_tz = getEnv("TZ") var tz_cnt = 0 for tz_fn in walkFiles(tz_dir & "/**/*"): @@ -143,7 +149,7 @@ suite "ttimes": check initDateTime(29, mOct, 2017, 01, 00, 00).isDst check initDateTime(29, mOct, 2017, 03, 01, 00).format(f) == "2017-10-29 03:01 +01:00" check (not initDateTime(29, mOct, 2017, 03, 01, 00).isDst) - + check initDateTime(21, mOct, 2017, 01, 00, 00).format(f) == "2017-10-21 01:00 +02:00" test "issue #6520": @@ -161,10 +167,10 @@ suite "ttimes": check diff == initDuration(seconds = 2208986872) test "issue #6465": - putEnv("TZ", "Europe/Stockholm") + putEnv("TZ", "Europe/Stockholm") let dt = parse("2017-03-25 12:00", "yyyy-MM-dd hh:mm") check $(dt + initTimeInterval(days = 1)) == "2017-03-26T12:00:00+02:00" - check $(dt + initDuration(days = 1)) == "2017-03-26T13:00:00+02:00" + check $(dt + initDuration(days = 1)) == "2017-03-26T13:00:00+02:00" test "datetime before epoch": check $fromUnix(-2147483648).utc == "1901-12-13T20:45:52Z" diff --git a/tests/stdlib/twalker.nim b/tests/stdlib/twalker.nim deleted file mode 100644 index 91c97df01..000000000 --- a/tests/stdlib/twalker.nim +++ /dev/null @@ -1,13 +0,0 @@ -# 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") |