diff options
author | Miran <narimiran@users.noreply.github.com> | 2018-10-19 11:43:35 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-10-19 11:43:35 +0200 |
commit | 9fb212cfdf2555cbebc8b8c453aa45c151534dfb (patch) | |
tree | 14844bf30c588668e3faa0a95e55628af4334d53 | |
parent | 3b1ade03507029ae96dc15190d453e2d71c9cf2b (diff) | |
download | Nim-9fb212cfdf2555cbebc8b8c453aa45c151534dfb.tar.gz |
merge stdlib tests (#9439)
28 files changed, 458 insertions, 522 deletions
diff --git a/tests/stdlib/t9394.nim b/tests/stdlib/t9394.nim deleted file mode 100644 index 3c0123eb5..000000000 --- a/tests/stdlib/t9394.nim +++ /dev/null @@ -1,7 +0,0 @@ -import terminal, colors - -let codeFg = ansiForegroundColorCode(colAliceBlue) -let codeBg = ansiBackgroundColorCode(colAliceBlue) - -doAssert codeFg == "\27[38;2;240;248;255m" -doAssert codeBg == "\27[48;2;240;248;255m" diff --git a/tests/stdlib/tbug5382.nim b/tests/stdlib/tbug5382.nim deleted file mode 100644 index c86656d32..000000000 --- a/tests/stdlib/tbug5382.nim +++ /dev/null @@ -1,11 +0,0 @@ -discard """ - output: ''' -02 -''' -""" -import re - -let regexp = re"^\/([0-9]{2})\.html$" -var matches: array[1, string] -discard "/02.html".find(regexp, matches) -echo matches[0] diff --git a/tests/stdlib/tcount.nim b/tests/stdlib/tcount.nim deleted file mode 100644 index ce1d14b6c..000000000 --- a/tests/stdlib/tcount.nim +++ /dev/null @@ -1,29 +0,0 @@ -discard """ - output: '''1 -2 -3 -4 -5 -done''' -""" - -# bug #1845, #2224 - -var arr = [3,2,1,5,4] - -# bubble sort -for i in low(arr)..high(arr): - for j in i+1..high(arr): # Error: unhandled exception: value out of range: 5 [RangeError] - if arr[i] > arr[j]: - let tmp = arr[i] - arr[i] = arr[j] - arr[j] = tmp - -for i in low(arr)..high(arr): - echo arr[i] - -# check this terminates: -for x in countdown('\255', '\0'): - discard - -echo "done" diff --git a/tests/stdlib/tcputime.nim b/tests/stdlib/tcputime.nim index 2fc46ee64..b0cc19c6c 100644 --- a/tests/stdlib/tcputime.nim +++ b/tests/stdlib/tcputime.nim @@ -1,13 +1,11 @@ - import times, os var e = epochTime() var c = cpuTime() -os.sleep(1500) +os.sleep(1000) e = epochTime() - e c = cpuTime() - c echo "epochTime: ", e, " cpuTime: ", c - diff --git a/tests/stdlib/tcritbits.nim b/tests/stdlib/tcritbits.nim deleted file mode 100644 index 8280ec881..000000000 --- a/tests/stdlib/tcritbits.nim +++ /dev/null @@ -1,28 +0,0 @@ -discard """ - output: '''abc -def -definition -prefix -xyz -def -definition''' -""" - -import critbits - -when isMainModule: - var r: TCritBitTree[void] - r.incl "abc" - r.incl "xyz" - r.incl "def" - r.incl "definition" - r.incl "prefix" - doAssert r.contains"def" - #r.del "def" - - for w in r.items: - echo w - - for w in r.itemsWithPrefix("de"): - echo w - diff --git a/tests/stdlib/techo.nim b/tests/stdlib/techo.nim deleted file mode 100644 index 9cef9205f..000000000 --- a/tests/stdlib/techo.nim +++ /dev/null @@ -1,3 +0,0 @@ -# Simplest Nim program - -echo "Hello, World!" diff --git a/tests/stdlib/tencoding.nim b/tests/stdlib/tencoding.nim deleted file mode 100644 index d6ff7ab32..000000000 --- a/tests/stdlib/tencoding.nim +++ /dev/null @@ -1,21 +0,0 @@ -discard """ - output: '''OK''' -""" - -#bug #8468 - -import encodings, strutils - -when defined(windows): - var utf16to8 = open(destEncoding = "utf-16", srcEncoding = "utf-8") - var s = "some string" - var c = utf16to8.convert(s) - - var z = newStringOfCap(s.len * 2) - for x in s: - z.add x - z.add chr(0) - - doAssert z == c - -echo "OK" diff --git a/tests/stdlib/testequivalence.nim b/tests/stdlib/testequivalence.nim deleted file mode 100644 index 7acaad340..000000000 --- a/tests/stdlib/testequivalence.nim +++ /dev/null @@ -1,14 +0,0 @@ -discard """ - output: '''''' -""" -import sets - -doAssert(toSet(@[1,2,3]) <= toSet(@[1,2,3,4]), "equivalent or subset") -doAssert(toSet(@[1,2,3]) <= toSet(@[1,2,3]), "equivalent or subset") -doAssert((not(toSet(@[1,2,3]) <= toSet(@[1,2]))), "equivalent or subset") -doAssert(toSet(@[1,2,3]) <= toSet(@[1,2,3,4]), "strict subset") -doAssert((not(toSet(@[1,2,3]) < toSet(@[1,2,3]))), "strict subset") -doAssert((not(toSet(@[1,2,3]) < toSet(@[1,2]))), "strict subset") -doAssert((not(toSet(@[1,2,3]) == toSet(@[1,2,3,4]))), "==") -doAssert(toSet(@[1,2,3]) == toSet(@[1,2,3]), "==") -doAssert((not(toSet(@[1,2,3]) == toSet(@[1,2]))), "==") diff --git a/tests/stdlib/tformat.nim b/tests/stdlib/tformat.nim deleted file mode 100644 index 160ab0fd5..000000000 --- a/tests/stdlib/tformat.nim +++ /dev/null @@ -1,12 +0,0 @@ -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? - - diff --git a/tests/stdlib/thtmlparser.nim b/tests/stdlib/thtmlparser.nim new file mode 100644 index 000000000..d59e8b302 --- /dev/null +++ b/tests/stdlib/thtmlparser.nim @@ -0,0 +1,80 @@ +discard """ + output: ''' +@[] +true +''' +""" +import htmlparser +import xmltree +import strutils +from streams import newStringStream + + +block t2813: + const + html = """ + <html> + <head> + <title>Test</title> + </head> + <body> + <table> + <thead> + <tr><td>A</td></tr> + <tr><td>B</td></tr> + </thead> + <tbody> + <tr><td></td>A<td></td></tr> + <tr><td></td>B<td></td></tr> + <tr><td></td>C<td></td></tr> + </tbody> + <tfoot> + <tr><td>A</td></tr> + </tfoot> + </table> + </body> + </html> + """ + var errors: seq[string] = @[] + let tree = parseHtml(newStringStream(html), "test.html", errors) + echo errors # Errors: </thead> expected,... + + var len = tree.findAll("tr").len # len = 6 + var rows: seq[XmlNode] = @[] + for n in tree.findAll("table"): + n.findAll("tr", rows) # len = 2 + break + assert tree.findAll("tr").len == rows.len + + +block t2814: + ## builds the two cases below and test that + ## ``//[dd,li]`` has "<p>that</p>" as children + ## + ## <dl> + ## <dt>this</dt> + ## <dd> + ## <p>that</p> + ## </dd> + ## </dl> + + ## + ## <ul> + ## <li> + ## <p>that</p> + ## </li> + ## </ul> + for ltype in [["dl","dd"], ["ul","li"]]: + let desc_item = if ltype[0]=="dl": "<dt>this</dt>" else: "" + let item = "$1<$2><p>that</p></$2>" % [desc_item, ltype[1]] + let list = """ <$1> + $2 + </$1> """ % [ltype[0], item] + + var errors : seq[string] = @[] + let parseH = parseHtml(newStringStream(list),"statichtml", errors =errors) + + if $parseH.findAll(ltype[1])[0].child("p") != "<p>that</p>": + echo "case " & ltype[0] & " failed !" + quit(2) + echo "true" diff --git a/tests/stdlib/thtmlparser2813.nim b/tests/stdlib/thtmlparser2813.nim deleted file mode 100644 index 4b04bc3f0..000000000 --- a/tests/stdlib/thtmlparser2813.nim +++ /dev/null @@ -1,45 +0,0 @@ -discard """ - output: "@[]" -""" -import htmlparser -import xmltree -from streams import newStringStream - -const - html = """ - <html> - <head> - <title>Test</title> - </head> - <body> - <table> - <thead> - <tr><td>A</td></tr> - <tr><td>B</td></tr> - </thead> - <tbody> - <tr><td></td>A<td></td></tr> - <tr><td></td>B<td></td></tr> - <tr><td></td>C<td></td></tr> - </tbody> - <tfoot> - <tr><td>A</td></tr> - </tfoot> - </table> - </body> - </html> - """ -var errors: seq[string] = @[] - -let tree = parseHtml(newStringStream(html), "test.html", errors) - -echo errors # Errors: </thead> expected,... - -var len = tree.findAll("tr").len # len = 6 - -var rows: seq[XmlNode] = @[] -for n in tree.findAll("table"): - n.findAll("tr", rows) # len = 2 - break - -assert tree.findAll("tr").len == rows.len diff --git a/tests/stdlib/thtmlparser2814.nim b/tests/stdlib/thtmlparser2814.nim deleted file mode 100644 index 968d390f1..000000000 --- a/tests/stdlib/thtmlparser2814.nim +++ /dev/null @@ -1,44 +0,0 @@ -discard """ - output: true -""" -import htmlparser -import xmltree -import strutils -from streams import newStringStream - - -## builds the two cases below and test that -## ``//[dd,li]`` has "<p>that</p>" as children -## -## <dl> -## <dt>this</dt> -## <dd> -## <p>that</p> -## </dd> -## </dl> - -## -## <ul> -## <li> -## <p>that</p> -## </li> -## </ul> - - -for ltype in [["dl","dd"], ["ul","li"]]: - let desc_item = if ltype[0]=="dl": "<dt>this</dt>" else: "" - let item = "$1<$2><p>that</p></$2>" % [desc_item, ltype[1]] - let list = """ <$1> - $2 -</$1> """ % [ltype[0], item] - - var errors : seq[string] = @[] - - let parseH = parseHtml(newStringStream(list),"statichtml", errors =errors) - - if $parseH.findAll(ltype[1])[0].child("p") != "<p>that</p>": - echo "case " & ltype[0] & " failed !" - quit(2) - - -echo "true" diff --git a/tests/stdlib/tio.nim b/tests/stdlib/tio.nim deleted file mode 100644 index b1057dee2..000000000 --- a/tests/stdlib/tio.nim +++ /dev/null @@ -1,49 +0,0 @@ -discard """ - output: '''9 -b = true -123456789 -Second readLine raised an exception -123456789 -1 -2aaaaaaaa -3bbbbbbb -''' -""" -# bug #5349 -import os - -# test the file-IO - -const fn = "file9char.txt" - -writeFile(fn, "123456789") - -var f = open(fn) -echo getFileSize(f) - -var line = newString(10) -try: - let b = readLine(f, line) - echo "b = ", b -except: - echo "First readLine raised an exception" - -echo line - -try: - line = readLine(f) - let b = readLine(f, line) - echo "b = ", b -except: - echo "Second readLine raised an exception" - -echo line -f.close() - -removeFile(fn) - -# bug #8961 -writeFile("test.txt", "1\C\L2aaaaaaaa\C\L3bbbbbbb") - -for line in lines("test.txt"): - echo line diff --git a/tests/stdlib/tissues.nim b/tests/stdlib/tissues.nim new file mode 100644 index 000000000..6d886a553 --- /dev/null +++ b/tests/stdlib/tissues.nim @@ -0,0 +1,105 @@ +discard """ +output: ''' +02 +1 +2 +3 +4 +5 +9 +b = true +123456789 +Second readLine raised an exception +123456789 +1 +2aaaaaaaa +3bbbbbbb +''' +""" + +import terminal, colors, re, encodings, strutils, os + + +block t9394: + let codeFg = ansiForegroundColorCode(colAliceBlue) + let codeBg = ansiBackgroundColorCode(colAliceBlue) + + doAssert codeFg == "\27[38;2;240;248;255m" + doAssert codeBg == "\27[48;2;240;248;255m" + + + +block t5382: + let regexp = re"^\/([0-9]{2})\.html$" + var matches: array[1, string] + discard "/02.html".find(regexp, matches) + echo matches[0] + + + +block tcount: + # bug #1845, #2224 + var arr = [3,2,1,5,4] + + # bubble sort + for i in low(arr)..high(arr): + for j in i+1..high(arr): # Error: unhandled exception: value out of range: 5 [RangeError] + if arr[i] > arr[j]: + let tmp = arr[i] + arr[i] = arr[j] + arr[j] = tmp + + for i in low(arr)..high(arr): + echo arr[i] + + # check this terminates: + for x in countdown('\255', '\0'): + discard + + + +block t8468: + when defined(windows): + var utf16to8 = open(destEncoding = "utf-16", srcEncoding = "utf-8") + var s = "some string" + var c = utf16to8.convert(s) + + var z = newStringOfCap(s.len * 2) + for x in s: + z.add x + z.add chr(0) + + doAssert z == c + + + +block t5349: + const fn = "file9char.txt" + writeFile(fn, "123456789") + + var f = system.open(fn) + echo getFileSize(f) + + var line = newString(10) + try: + let b = readLine(f, line) + echo "b = ", b + except: + echo "First readLine raised an exception" + echo line + + try: + line = readLine(f) + let b = readLine(f, line) + echo "b = ", b + except: + echo "Second readLine raised an exception" + echo line + f.close() + + removeFile(fn) + # bug #8961 + writeFile("test.txt", "1\C\L2aaaaaaaa\C\L3bbbbbbb") + + for line in lines("test.txt"): + echo line diff --git a/tests/stdlib/tnilecho.nim b/tests/stdlib/tnilecho.nim deleted file mode 100644 index ec8d71dab..000000000 --- a/tests/stdlib/tnilecho.nim +++ /dev/null @@ -1,6 +0,0 @@ -discard """ - output: "" -""" - -var x = @["1", "", "3"] -doAssert $x == """@["1", "", "3"]""" diff --git a/tests/stdlib/torderedtable.nim b/tests/stdlib/torderedtable.nim deleted file mode 100644 index 91a916930..000000000 --- a/tests/stdlib/torderedtable.nim +++ /dev/null @@ -1,18 +0,0 @@ -import tables, random -var t = initOrderedTable[int,string]() - -# this tests issue #5917 -var data = newSeq[int]() -for i in 0..<1000: - var x = random(1000) - if x notin t: data.add(x) - t[x] = "meh" - -# this checks that keys are re-inserted -# in order when table is enlarged. -var i = 0 -for k, v in t: - doAssert(k == data[i]) - doAssert(v == "meh") - inc(i) - diff --git a/tests/stdlib/tpermutations.nim b/tests/stdlib/tpermutations.nim deleted file mode 100644 index a6e07ded6..000000000 --- a/tests/stdlib/tpermutations.nim +++ /dev/null @@ -1,19 +0,0 @@ -discard """ - output: '''@[0, 2, 1] -@[1, 0, 2] -@[1, 2, 0] -@[2, 0, 1] -@[2, 1, 0] -@[2, 0, 1] -@[1, 2, 0] -@[1, 0, 2] -@[0, 2, 1] -@[0, 1, 2]''' -""" -import algorithm - -var v = @[0, 1, 2] -while v.nextPermutation(): - echo v -while v.prevPermutation(): - echo v diff --git a/tests/stdlib/treguse.nim b/tests/stdlib/treguse.nim deleted file mode 100644 index 3d09eb731..000000000 --- a/tests/stdlib/treguse.nim +++ /dev/null @@ -1,27 +0,0 @@ -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 - - diff --git a/tests/stdlib/treloop.nim b/tests/stdlib/treloop.nim deleted file mode 100644 index b4221525d..000000000 --- a/tests/stdlib/treloop.nim +++ /dev/null @@ -1,9 +0,0 @@ -discard """ - output: '''@["(", "+", " 1", " 2", ")"]''' -""" - -import re - -let str = "(+ 1 2)" -var tokenRE = re"""[\s,]*(~@|[\[\]{}()'`~^@]|"(?:\\.|[^\\"])*"|;.*|[^\s\[\]{}('"`,;)]*)""" -echo str.findAll(tokenRE) diff --git a/tests/stdlib/tropes.nim b/tests/stdlib/tropes.nim deleted file mode 100644 index 59239a600..000000000 --- a/tests/stdlib/tropes.nim +++ /dev/null @@ -1,36 +0,0 @@ -discard """ - file: "tropes.nim" - output: '''0 -3 - -123 -3 -6 -123 -123456 -2 -3''' -""" -import ropes - -var - r1 = rope("") - r2 = rope("123") - -echo r1.len -echo r2.len - -echo r1 -echo r2 - -r1.add("123") -r2.add("456") - -echo r1.len -echo r2.len - -echo r1 -echo r2 - -echo r1[1] -echo r2[2] \ No newline at end of file diff --git a/tests/stdlib/tsegfaults.nim b/tests/stdlib/tsegfaults.nim deleted file mode 100644 index 1d8508c52..000000000 --- a/tests/stdlib/tsegfaults.nim +++ /dev/null @@ -1,29 +0,0 @@ -discard """ - output: '''caught a crash! -caught a crash! -caught a crash! -caught a crash! -caught a crash! -caught a crash! -caught a crash! -caught a crash! -caught a crash! -caught a crash! -caught a crash!''' -""" - -import segfaults - -proc main = - try: - var x: ptr int - echo x[] - try: - raise newException(ValueError, "not a crash") - except ValueError: - discard - except NilAccessError: - echo "caught a crash!" - -for i in 0..10: - main() diff --git a/tests/stdlib/tsinglylinkedring.nim b/tests/stdlib/tsinglylinkedring.nim deleted file mode 100644 index 93f0c69cd..000000000 --- a/tests/stdlib/tsinglylinkedring.nim +++ /dev/null @@ -1,29 +0,0 @@ -discard """ - output: '''[5] -[4, 5] -[3, 4, 5] -[2, 3, 4, 5] -[2, 3, 4, 5, 6] -[2, 3, 4, 5, 6, 7] -[2, 3, 4, 5, 6, 7, 8] -[1, 2, 3, 4, 5, 6, 7, 8]''' -""" -import lists - -var r = initSinglyLinkedRing[int]() -r.prepend(5) -echo r -r.prepend(4) -echo r -r.prepend(3) -echo r -r.prepend(2) -echo r -r.append(6) -echo r -r.append(7) -echo r -r.append(8) -echo r -r.prepend(1) -echo r diff --git a/tests/stdlib/tsplit.nim b/tests/stdlib/tsplit.nim deleted file mode 100644 index 44da58aca..000000000 --- a/tests/stdlib/tsplit.nim +++ /dev/null @@ -1,20 +0,0 @@ -discard """ - file: "tsplit.nim" - output: "true" -""" -import strutils - -var s = "" -for w in split("|abc|xy|z", {'|'}): - s.add("#") - s.add(w) - -if s == "##abc#xy#z": - echo "true" -else: - echo "false" - -#OUT true - - - diff --git a/tests/stdlib/tsplit2.nim b/tests/stdlib/tsplit2.nim deleted file mode 100644 index 7fd9dda74..000000000 --- a/tests/stdlib/tsplit2.nim +++ /dev/null @@ -1,19 +0,0 @@ -discard """ - file: "tsplit2.nim" - output: "true" -""" -import strutils - -var s = "" -for w in split("|abc|xy|z", {'|'}): - s.add("#") - s.add(w) - -try: - discard "hello".split("") - echo "false" -except AssertionError: - echo "true" - -#OUT true - diff --git a/tests/stdlib/tstreams.nim b/tests/stdlib/tstreams.nim index 640565a27..16dbc0e1b 100644 --- a/tests/stdlib/tstreams.nim +++ b/tests/stdlib/tstreams.nim @@ -1,7 +1,27 @@ import streams -var outp = newFileStream(stdout) -var inp = newFileStream(stdin) -write(outp, "Hello! What is your name?") -var line = readLine(inp) -write(outp, "Nice name: " & line) + +block tstreams: + var outp = newFileStream(stdout) + var inp = newFileStream(stdin) + write(outp, "Hello! What is your name?") + var line = readLine(inp) + write(outp, "Nice name: " & line) + + +block tstreams2: + var + fs = newFileStream("amissingfile.txt") + line = "" + echo "fs is: ",repr(fs) + if not isNil(fs): + while fs.readLine(line): + echo line + fs.close() + + +block tstreams3: + try: + var fs = openFileStream("shouldneverexist.txt") + except IoError: + echo "threw exception" diff --git a/tests/stdlib/tvarious.nim b/tests/stdlib/tvarious.nim new file mode 100644 index 000000000..7abc9a391 --- /dev/null +++ b/tests/stdlib/tvarious.nim @@ -0,0 +1,247 @@ +discard """ +output: ''' +abc +def +definition +prefix +xyz +def +definition +Hi Andreas! How do you feel, Rumpf? + +@[0, 2, 1] +@[1, 0, 2] +@[1, 2, 0] +@[2, 0, 1] +@[2, 1, 0] +@[2, 0, 1] +@[1, 2, 0] +@[1, 0, 2] +@[0, 2, 1] +@[0, 1, 2] +055this should be the casehugh@["(", "+", " 1", " 2", ")"] +caught a crash! +caught a crash! +caught a crash! +caught a crash! +caught a crash! +caught a crash! +[5] +[4, 5] +[3, 4, 5] +[2, 3, 4, 5] +[2, 3, 4, 5, 6] +[1, 2, 3, 4, 5, 6] +true +<h1><a href="http://force7.de/nim">Nim</a></h1> +''' +""" + +import + critbits, sets, strutils, tables, random, algorithm, re, ropes, segfaults, + lists, parsesql, streams, os, htmlgen, xmltree, strtabs + + +block tcritbits: + var r: CritBitTree[void] + r.incl "abc" + r.incl "xyz" + r.incl "def" + r.incl "definition" + r.incl "prefix" + doAssert r.contains"def" + #r.del "def" + + for w in r.items: + echo w + for w in r.itemsWithPrefix("de"): + echo w + + + +block testequivalence: + doAssert(toSet(@[1,2,3]) <= toSet(@[1,2,3,4]), "equivalent or subset") + doAssert(toSet(@[1,2,3]) <= toSet(@[1,2,3]), "equivalent or subset") + doAssert((not(toSet(@[1,2,3]) <= toSet(@[1,2]))), "equivalent or subset") + doAssert(toSet(@[1,2,3]) <= toSet(@[1,2,3,4]), "strict subset") + doAssert((not(toSet(@[1,2,3]) < toSet(@[1,2,3]))), "strict subset") + doAssert((not(toSet(@[1,2,3]) < toSet(@[1,2]))), "strict subset") + doAssert((not(toSet(@[1,2,3]) == toSet(@[1,2,3,4]))), "==") + doAssert(toSet(@[1,2,3]) == toSet(@[1,2,3]), "==") + doAssert((not(toSet(@[1,2,3]) == toSet(@[1,2]))), "==") + + + +block tformat: + echo("Hi $1! How do you feel, $2?\n" % ["Andreas", "Rumpf"]) + + + +block tnilecho: + var x = @["1", "", "3"] + doAssert $x == """@["1", "", "3"]""" + + + +block torderedtable: + var t = initOrderedTable[int,string]() + + # this tests issue #5917 + var data = newSeq[int]() + for i in 0..<1000: + var x = rand(1000) + if x notin t: data.add(x) + t[x] = "meh" + + # this checks that keys are re-inserted + # in order when table is enlarged. + var i = 0 + for k, v in t: + doAssert(k == data[i]) + doAssert(v == "meh") + inc(i) + + + +block tpermutations: + var v = @[0, 1, 2] + while v.nextPermutation(): + echo v + while v.prevPermutation(): + echo v + + + +block treguse: + 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) + + + +block treloop: + let str = "(+ 1 2)" + var tokenRE = re"""[\s,]*(~@|[\[\]{}()'`~^@]|"(?:\\.|[^\\"])*"|;.*|[^\s\[\]{}('"`,;)]*)""" + echo str.findAll(tokenRE) + + + +block tropes: + var + r1 = rope("") + r2 = rope("123") + doAssert r1.len == 0 + doAssert r2.len == 3 + doAssert $r1 == "" + doAssert $r2 == "123" + + r1.add("123") + r2.add("456") + doAssert r1.len == 3 + doAssert r2.len == 6 + doAssert $r1 == "123" + doAssert $r2 == "123456" + doAssert $r1[1] == "2" + doAssert $r2[2] == "3" + + + +block tsegfaults: + proc main = + try: + var x: ptr int + echo x[] + try: + raise newException(ValueError, "not a crash") + except ValueError: + discard + except NilAccessError: + echo "caught a crash!" + for i in 0..5: + main() + + + +block tsinglylinkedring: + var r = initSinglyLinkedRing[int]() + r.prepend(5) + echo r + r.prepend(4) + echo r + r.prepend(3) + echo r + r.prepend(2) + echo r + r.append(6) + echo r + r.prepend(1) + echo r + + + +block tsplit: + var s = "" + for w in split("|abc|xy|z", {'|'}): + s.add("#") + s.add(w) + + doAssert s == "##abc#xy#z" + + + +block tsplit2: + var s = "" + for w in split("|abc|xy|z", {'|'}): + s.add("#") + s.add(w) + + try: + discard "hello".split("") + echo "false" + except AssertionError: + echo "true" + + + +block tsqlparser: + # Just check that we can parse 'somesql' and render it without crashes. + var tree = parseSql(newFileStream(getAppDir() / "somesql.sql"), "somesql") + discard renderSql(tree) + + + +block txmlgen: + var nim = "Nim" + echo h1(a(href="http://force7.de/nim", nim)) + + + +block txmltree: + var x = <>a(href="nim.de", newText("www.nim-test.de")) + + doAssert($x == "<a href=\"nim.de\">www.nim-test.de</a>") + doAssert(newText("foo").innerText == "foo") + doAssert(newEntity("bar").innerText == "bar") + doAssert(newComment("baz").innerText == "") + + let y = newXmlTree("x", [ + newText("foo"), + newXmlTree("y", [ + newText("bar") + ]) + ]) + doAssert(y.innerText == "foobar") diff --git a/tests/stdlib/txmlgen.nim b/tests/stdlib/txmlgen.nim deleted file mode 100644 index fa1dffe56..000000000 --- a/tests/stdlib/txmlgen.nim +++ /dev/null @@ -1,12 +0,0 @@ -discard """ - file: "txmlgen.nim" - output: "<h1><a href=\"http://force7.de/nim\">Nim</a></h1>" -""" -import htmlgen - -var nim = "Nim" -echo h1(a(href="http://force7.de/nim", nim)) - - - - diff --git a/tests/stdlib/txmltree.nim b/tests/stdlib/txmltree.nim deleted file mode 100644 index a849859e3..000000000 --- a/tests/stdlib/txmltree.nim +++ /dev/null @@ -1,27 +0,0 @@ -discard """ - file: "txmltree.nim" - output: '''true -true -true -true -true -''' -""" - -import xmltree, strtabs - -var x = <>a(href="nim.de", newText("www.nim-test.de")) - -echo($x == "<a href=\"nim.de\">www.nim-test.de</a>") - -echo(newText("foo").innerText == "foo") -echo(newEntity("bar").innerText == "bar") -echo(newComment("baz").innerText == "") - -let y = newXmlTree("x", [ - newText("foo"), - newXmlTree("y", [ - newText("bar") - ]) -]) -echo(y.innerText == "foobar") |