summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/js/tstdlib_imports.nim71
-rw-r--r--tests/js/tstdlib_various.nim194
-rw-r--r--tests/js/tstreams.nim22
-rw-r--r--tests/stdlib/thtmlparser.nim4
-rw-r--r--tests/stdlib/tparscfg.nim61
-rw-r--r--tests/stdlib/tparsesql.nim3
-rw-r--r--tests/stdlib/tpegs.nim1
-rw-r--r--tests/stdlib/tstdlib_various.nim25
-rw-r--r--tests/test_nimscript.nims88
9 files changed, 408 insertions, 61 deletions
diff --git a/tests/js/tstdlib_imports.nim b/tests/js/tstdlib_imports.nim
new file mode 100644
index 000000000..7611b7dcb
--- /dev/null
+++ b/tests/js/tstdlib_imports.nim
@@ -0,0 +1,71 @@
+discard """
+  action: compile
+"""
+
+{.warning[UnusedImport]: off.}
+
+import std/[
+  # Core:
+  bitops, typetraits, lenientops, macros, volatile, typeinfo,
+  # fails: endians, rlocks
+  # works but shouldn't: cpuinfo, locks
+
+  # Algorithms:
+  algorithm, sequtils,
+  
+  # Collections:
+  critbits, deques, heapqueue, intsets, lists, options, sets,
+  sharedlist, tables,
+  # fails: sharedtables
+
+  # Strings:
+  cstrutils, editdistance, wordwrap, parseutils, ropes,
+  pegs, punycode, strformat, strmisc, strscans, strtabs,
+  strutils, unicode, unidecode,
+  # fails: encodings
+
+  # Time handling:
+  monotimes, times,
+
+  # Generic operator system services:
+  os, streams,
+  # fails: distros, dynlib, marshal, memfiles, osproc, terminal
+
+  # Math libraries:
+  complex, math, mersenne, random, rationals, stats, sums,
+  # works but shouldn't: fenv
+
+  # Internet protocols:
+  cookies, httpcore, mimetypes, uri,
+  # fails: asyncdispatch, asyncfile, asyncftpclient, asynchttpserver,
+  # asyncnet, cgi, httpclient, nativesockets, net, selectors, smtp
+  # works but shouldn't test: asyncstreams, asyncfutures
+  
+  # Threading:
+  # fails: threadpool
+
+  # Parsers:
+  htmlparser, json, lexbase, parsecfg, parsecsv, parsesql, parsexml,
+  # fails: parseopt
+
+  # XML processing:
+  xmltree, xmlparser,
+
+  # Generators:
+  htmlgen,
+
+  # Hashing:
+  base64, hashes,
+  # fails: md5, oids, sha1
+
+  # Miscellaneous:
+  colors, logging, sugar, unittest, varints,
+  # fails: browsers, coro
+  # works but shouldn't: segfaults
+
+  # Modules for JS backend:
+  asyncjs, dom, jsconsole, jscore, jsffi,
+
+  # Unlisted in lib.html:
+  decls, compilesettings, with, wrapnils
+]
diff --git a/tests/js/tstdlib_various.nim b/tests/js/tstdlib_various.nim
new file mode 100644
index 000000000..d19f40c39
--- /dev/null
+++ b/tests/js/tstdlib_various.nim
@@ -0,0 +1,194 @@
+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]
+[5]
+[4, 5]
+[3, 4, 5]
+[2, 3, 4, 5]
+[2, 3, 4, 5, 6]
+[1, 2, 3, 4, 5, 6]
+'''
+"""
+
+import
+  critbits, cstrutils, sets, strutils, tables, random, algorithm, ropes,
+  lists, 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(toHashSet(@[1,2,3]) <= toHashSet(@[1,2,3,4]), "equivalent or subset")
+  doAssert(toHashSet(@[1,2,3]) <= toHashSet(@[1,2,3]), "equivalent or subset")
+  doAssert((not(toHashSet(@[1,2,3]) <= toHashSet(@[1,2]))), "equivalent or subset")
+  doAssert(toHashSet(@[1,2,3]) <= toHashSet(@[1,2,3,4]), "strict subset")
+  doAssert((not(toHashSet(@[1,2,3]) < toHashSet(@[1,2,3]))), "strict subset")
+  doAssert((not(toHashSet(@[1,2,3]) < toHashSet(@[1,2]))), "strict subset")
+  doAssert((not(toHashSet(@[1,2,3]) == toHashSet(@[1,2,3,4]))), "==")
+  doAssert(toHashSet(@[1,2,3]) == toHashSet(@[1,2,3]), "==")
+  doAssert((not(toHashSet(@[1,2,3]) == toHashSet(@[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 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 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)
+
+  var errored = false
+  try:
+    discard "hello".split("")
+  except AssertionError:
+    errored = true
+  doAssert errored
+
+block txmlgen:
+  var nim = "Nim"
+  doAssert h1(a(href="http://force7.de/nim", nim)) ==
+    "<h1><a href=\"http://force7.de/nim\">Nim</a></h1>"
+
+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")
+
+
+
+block tcstrutils:
+  let s = cstring "abcdef"
+  doAssert s.startsWith("a")
+  doAssert not s.startsWith("b")
+  doAssert s.endsWith("f")
+  doAssert not s.endsWith("a")
+
+  let a = cstring "abracadabra"
+  doAssert a.startsWith("abra")
+  doAssert not a.startsWith("bra")
+  doAssert a.endsWith("abra")
+  doAssert not a.endsWith("dab")
diff --git a/tests/js/tstreams.nim b/tests/js/tstreams.nim
new file mode 100644
index 000000000..43c26e01a
--- /dev/null
+++ b/tests/js/tstreams.nim
@@ -0,0 +1,22 @@
+discard """
+  output: '''
+I
+AM
+GROOT
+'''
+"""
+
+import streams
+
+var s = newStringStream("I\nAM\nGROOT")
+doAssert s.peekStr(1) == "I"
+doAssert s.peekChar() == 'I'
+for line in s.lines:
+  echo line
+s.close
+
+var s2 = newStringStream("abc")
+doAssert s2.readAll == "abc"
+s2.write("def")
+doAssert s2.data == "abcdef"
+s2.close
diff --git a/tests/stdlib/thtmlparser.nim b/tests/stdlib/thtmlparser.nim
index ccf2f6202..e7dcd50d5 100644
--- a/tests/stdlib/thtmlparser.nim
+++ b/tests/stdlib/thtmlparser.nim
@@ -1,6 +1,6 @@
 discard """
+  targets: "c js"
   output: '''
-@[]
 true
 https://example.com/test?format=jpg&name=orig##
 https://example.com/test?format=jpg&name=orig##text
@@ -40,7 +40,7 @@ block t2813:
     """
   var errors: seq[string] = @[]
   let tree = parseHtml(newStringStream(html), "test.html", errors)
-  echo errors # Errors: </thead> expected,...
+  doAssert errors.len == 0 # Errors: </thead> expected,...
 
   var len = tree.findAll("tr").len # len = 6
   var rows: seq[XmlNode] = @[]
diff --git a/tests/stdlib/tparscfg.nim b/tests/stdlib/tparscfg.nim
index fc735f3eb..ddb9b02b7 100644
--- a/tests/stdlib/tparscfg.nim
+++ b/tests/stdlib/tparscfg.nim
@@ -1,29 +1,5 @@
 discard """
-output: '''
-utf-8
-on
-hello
-lihf8515
-10214028
-lihaifeng@wxm.com
-===
-charset=utf-8
-[Package]
-name=hello
---threads:on
-[Author]
-name=lhf
-qq=10214028
-email="lihaifeng@wxm.com"
-===
-charset=utf-8
-[Package]
-name=hello
---threads:on
-[Author]
-name=lihf8515
-qq=10214028
-'''
+  targets: "c js"
 """
 import parsecfg, streams
 
@@ -46,24 +22,35 @@ var pname = dict2.getSectionValue("Package","name")
 var name = dict2.getSectionValue("Author","name")
 var qq = dict2.getSectionValue("Author","qq")
 var email = dict2.getSectionValue("Author","email")
-echo charset
-echo threads
-echo pname
-echo name
-echo qq
-echo email
-
-echo "==="
+doAssert charset == "utf-8"
+doAssert threads == "on"
+doAssert pname == "hello"
+doAssert name == "lihf8515"
+doAssert qq == "10214028"
+doAssert email == "lihaifeng@wxm.com"
 
 ## Modifying a configuration file.
 var dict3 = loadConfig(newStringStream(ss.data))
 dict3.setSectionKey("Author","name","lhf")
-write(stdout, $dict3)
-
-echo "==="
+doAssert $dict3 == """charset=utf-8
+[Package]
+name=hello
+--threads:on
+[Author]
+name=lhf
+qq=10214028
+email="lihaifeng@wxm.com"
+"""
 
 ## Deleting a section key in a configuration file.
 var dict4 = loadConfig(newStringStream(ss.data))
 dict4.delSectionKey("Author","email")
-write(stdout, $dict4)
+doAssert $dict4 == """charset=utf-8
+[Package]
+name=hello
+--threads:on
+[Author]
+name=lihf8515
+qq=10214028
+"""
 
diff --git a/tests/stdlib/tparsesql.nim b/tests/stdlib/tparsesql.nim
index 8cf8fa848..ba9e601a1 100644
--- a/tests/stdlib/tparsesql.nim
+++ b/tests/stdlib/tparsesql.nim
@@ -1,3 +1,6 @@
+discard """
+  targets: "c js"
+"""
 import parsesql
 
 doAssert $parseSQL("SELECT foo FROM table;") == "select foo from table;"
diff --git a/tests/stdlib/tpegs.nim b/tests/stdlib/tpegs.nim
index b07442dcb..2990a44a5 100644
--- a/tests/stdlib/tpegs.nim
+++ b/tests/stdlib/tpegs.nim
@@ -1,4 +1,5 @@
 discard """
+  targets: "c js"
   output: '''
 PEG AST traversal output
 ------------------------
diff --git a/tests/stdlib/tstdlib_various.nim b/tests/stdlib/tstdlib_various.nim
index d1723df78..6856fcd79 100644
--- a/tests/stdlib/tstdlib_various.nim
+++ b/tests/stdlib/tstdlib_various.nim
@@ -38,8 +38,8 @@ true
 """
 
 import
-  critbits, sets, strutils, tables, random, algorithm, re, ropes, segfaults,
-  lists, parsesql, streams, os, htmlgen, xmltree, strtabs
+  critbits, cstrutils, sets, strutils, tables, random, algorithm, re, ropes,
+  segfaults, lists, parsesql, streams, os, htmlgen, xmltree, strtabs
 
 
 block tcritbits:
@@ -245,3 +245,24 @@ block txmltree:
     ])
   ])
   doAssert(y.innerText == "foobar")
+
+
+block tcstrutils:
+  let s = cstring "abcdef"
+  doAssert s.startsWith("a")
+  doAssert not s.startsWith("b")
+  doAssert s.endsWith("f")
+  doAssert not s.endsWith("a")
+
+  let a = cstring "abracadabra"
+  doAssert a.startsWith("abra")
+  doAssert not a.startsWith("bra")
+  doAssert a.endsWith("abra")
+  doAssert not a.endsWith("dab")
+
+  doAssert cmpIgnoreCase(cstring "FooBar", "foobar") == 0
+  doAssert cmpIgnoreCase(cstring "bar", "Foo") < 0
+  doAssert cmpIgnoreCase(cstring "Foo5", "foo4") > 0
+
+  doAssert cmpIgnoreStyle(cstring "foo_bar", "FooBar") == 0
+  doAssert cmpIgnoreStyle(cstring "foo_bar_5", "FooBar4") > 0
diff --git a/tests/test_nimscript.nims b/tests/test_nimscript.nims
index 91b23efbf..0b454ad1c 100644
--- a/tests/test_nimscript.nims
+++ b/tests/test_nimscript.nims
@@ -1,26 +1,74 @@
 # This nimscript is used to test if the following modules can be imported
 # http://nim-lang.org/docs/nims.html
 
-import algorithm
-import base64
-import colors
-import hashes
-import lists
-import math
-# import marshal
-import options
-import os
-# import parsecfg
-# import parseopt
-import parseutils
-# import pegs
-import deques
-import sequtils
-import strutils
-import tables
-import unicode
-import uri
-import macros
+{.warning[UnusedImport]: off.}
+
+import std/[
+  # Core:
+  bitops, typetraits, lenientops, macros, volatile,
+  # fails: typeinfo, endians
+  # works but shouldn't: cpuinfo, rlocks, locks
+
+  # Algorithms:
+  algorithm, sequtils,
+  
+  # Collections:
+  critbits, deques, heapqueue, intsets, lists, options, sets,
+  sharedlist, tables,
+  # fails: sharedtables
+
+  # Strings:
+  editdistance, wordwrap, parseutils, ropes,
+  pegs, punycode, strformat, strmisc, strscans, strtabs,
+  strutils, unicode, unidecode,
+  # works but shouldn't: cstrutils, encodings
+
+  # Time handling:
+  # fails: monotimes, times
+  # but times.getTime() implemented for VM
+
+  # Generic operator system services:
+  os, streams,
+  # fails: distros, dynlib, marshal, memfiles, osproc, terminal
+
+  # Math libraries:
+  complex, math, mersenne, random, rationals, stats, sums,
+  # works but shouldn't: fenv
+
+  # Internet protocols:
+  httpcore, mimetypes, uri,
+  # fails: asyncdispatch, asyncfile, asyncftpclient, asynchttpserver,
+  # asyncnet, cgi, cookies, httpclient, nativesockets, net, selectors, smtp
+  # works but shouldn't test: asyncstreams, asyncfutures
+  
+  # Threading:
+  # fails: threadpool
+
+  # Parsers:
+  htmlparser, json, lexbase, parsecfg, parsecsv, parsesql, parsexml,
+  # fails: parseopt
+
+  # XML processing:
+  xmltree, xmlparser,
+
+  # Generators:
+  htmlgen,
+
+  # Hashing:
+  base64, hashes,
+  # fails: md5, oids, sha1
+
+  # Miscellaneous:
+  colors, sugar, varints,
+  # fails: browsers, coro, logging (times), segfaults, unittest (uses methods)
+
+  # Modules for JS backend:
+  # fails: asyncjs, dom, jsconsole, jscore, jsffi,
+
+  # Unlisted in lib.html:
+  decls, compilesettings, with, wrapnils
+]
+
 
 block:
   doAssert "./foo//./bar/".normalizedPath == "foo/bar".unixToNativePath