Merge pull request #2583 from BlaXpirit/test-stdlib

Test stdlib
This commit is contained in:
Andreas Rumpf 2015-04-21 15:36:37 +02:00
commit 4370163fdd
48 changed files with 152 additions and 100 deletions

View file

@ -205,7 +205,7 @@ proc setEncoding*(connection: TDbConn, encoding: string): bool {.
exec(connection, sql"PRAGMA encoding = ?", [encoding]) exec(connection, sql"PRAGMA encoding = ?", [encoding])
result = connection.getValue(sql"PRAGMA encoding") == encoding result = connection.getValue(sql"PRAGMA encoding") == encoding
when isMainModule: when not defined(testing) and isMainModule:
var db = open("db.sql", "", "", "") var db = open("db.sql", "", "", "")
exec(db, sql"create table tbl1(one varchar(10), two smallint)", []) exec(db, sql"create table tbl1(one varchar(10), two smallint)", [])
exec(db, sql"insert into tbl1 values('hello!',10)", []) exec(db, sql"insert into tbl1 values('hello!',10)", [])

View file

@ -499,7 +499,7 @@ template withEvents*(surf: PSurface, event: expr, actions: stmt): stmt {.
if sdl.init(sdl.INIT_VIDEO) < 0: raiseEGraphics() if sdl.init(sdl.INIT_VIDEO) < 0: raiseEGraphics()
if sdl_ttf.init() < 0: raiseEGraphics() if sdl_ttf.init() < 0: raiseEGraphics()
when isMainModule: when not defined(testing) and isMainModule:
var surf = newScreenSurface(800, 600) var surf = newScreenSurface(800, 600)
surf.fillSurface(colWhite) surf.fillSurface(colWhite)

View file

@ -82,7 +82,7 @@ proc close*(sock: TSecureSocket) =
ERR_print_errors_fp(stderr) ERR_print_errors_fp(stderr)
raiseOSError(osLastError()) raiseOSError(osLastError())
when isMainModule: when not defined(testing) and isMainModule:
var s: TSecureSocket var s: TSecureSocket
echo connect(s, "smtp.gmail.com", 465) echo connect(s, "smtp.gmail.com", 465)

View file

@ -1251,5 +1251,6 @@ proc rstToHtml*(s: string, options: TRstParseOptions,
when isMainModule: when isMainModule:
echo rstToHtml("*Hello* **world**!", {}, assert rstToHtml("*Hello* **world**!", {},
newStringTable(modeStyleInsensitive)) newStringTable(modeStyleInsensitive)) ==
"<em>Hello</em> <strong>world</strong>!"

View file

@ -221,7 +221,7 @@ proc spawn*[TIn](p: var TActorPool[TIn, void], input: TIn,
setupTask() setupTask()
schedule() schedule()
when isMainModule: when not defined(testing) and isMainModule:
var var
a: TActorPool[int, void] a: TActorPool[int, void]
createActorPool(a) createActorPool(a)

View file

@ -300,7 +300,7 @@ proc newAsyncFtpClient*(address: string, port = Port(21),
result.dsockConnected = false result.dsockConnected = false
result.csock = newAsyncSocket() result.csock = newAsyncSocket()
when isMainModule: when not defined(testing) and isMainModule:
var ftp = newAsyncFtpClient("example.com", user = "test", pass = "test") var ftp = newAsyncFtpClient("example.com", user = "test", pass = "test")
proc main(ftp: AsyncFtpClient) {.async.} = proc main(ftp: AsyncFtpClient) {.async.} =
await ftp.connect() await ftp.connect()

View file

@ -260,7 +260,7 @@ proc close*(server: AsyncHttpServer) =
## Terminates the async http server instance. ## Terminates the async http server instance.
server.socket.close() server.socket.close()
when isMainModule: when not defined(testing) and isMainModule:
proc main = proc main =
var server = newAsyncHttpServer() var server = newAsyncHttpServer()
proc cb(req: Request) {.async.} = proc cb(req: Request) {.async.} =

View file

@ -660,7 +660,7 @@ proc len*(disp: Dispatcher): int =
## Retrieves the amount of delegates in ``disp``. ## Retrieves the amount of delegates in ``disp``.
return disp.delegates.len return disp.delegates.len
when isMainModule: when not defined(testing) and isMainModule:
proc testConnect(s: AsyncSocket, no: int) = proc testConnect(s: AsyncSocket, no: int) =
echo("Connected! " & $no) echo("Connected! " & $no)

View file

@ -458,7 +458,7 @@ proc isClosed*(socket: AsyncSocket): bool =
## Determines whether the socket has been closed. ## Determines whether the socket has been closed.
return socket.closed return socket.closed
when isMainModule: when not defined(testing) and isMainModule:
type type
TestCases = enum TestCases = enum
HighClient, LowClient, LowServer HighClient, LowClient, LowServer

View file

@ -525,7 +525,7 @@ proc get*[K,V](table: var PConcTable[K,V], key: var K): V =
#Tests ---------------------------- #Tests ----------------------------
when isMainModule: when not defined(testing) and isMainModule:
import locks, times, mersenne import locks, times, mersenne
const const

View file

@ -286,18 +286,19 @@ proc `$`*[T](c: CritBitTree[T]): string =
result.add("}") result.add("}")
when isMainModule: when isMainModule:
import sequtils
var r: CritBitTree[void] var r: CritBitTree[void]
r.incl "abc" r.incl "abc"
r.incl "xyz" r.incl "xyz"
r.incl "def" r.incl "def"
r.incl "definition" r.incl "definition"
r.incl "prefix" r.incl "prefix"
doAssert r.contains"def" doAssert r.contains"def"
#r.del "def"
for w in r.items: r.excl "def"
echo w
for w in r.itemsWithPrefix("de"): assert toSeq(r.items) == @["abc", "definition", "prefix", "xyz"]
echo w
assert toSeq(r.itemsWithPrefix("de")) == @["definition"]

View file

@ -198,14 +198,21 @@ proc empty*(s: IntSet): bool {.inline, deprecated.} =
result = s.counter == 0 result = s.counter == 0
when isMainModule: when isMainModule:
import sequtils, algorithm
var x = initIntSet() var x = initIntSet()
x.incl(1) x.incl(1)
x.incl(2) x.incl(2)
x.incl(7) x.incl(7)
x.incl(1056) x.incl(1056)
for e in items(x): echo e
var y: TIntSet var xs = toSeq(items(x))
xs.sort(cmp[int])
assert xs == @[1, 2, 7, 1056]
var y: IntSet
assign(y, x) assign(y, x)
for e in items(y): echo e var ys = toSeq(items(y))
ys.sort(cmp[int])
assert ys == @[1, 2, 7, 1056]

View file

@ -492,9 +492,8 @@ when isMainModule:
block: # filter iterator test block: # filter iterator test
let numbers = @[1, 4, 5, 8, 9, 7, 4] let numbers = @[1, 4, 5, 8, 9, 7, 4]
for n in filter(numbers, proc (x: int): bool = x mod 2 == 0): assert toSeq(filter(numbers, proc (x: int): bool = x mod 2 == 0)) ==
echo($n) @[4, 8, 4]
# echoes 4, 8, 4 in separate lines
block: # keepIf test block: # keepIf test
var floats = @[13.0, 12.5, 5.8, 2.0, 6.1, 9.9, 10.1] var floats = @[13.0, 12.5, 5.8, 2.0, 6.1, 9.9, 10.1]
@ -616,4 +615,5 @@ when isMainModule:
#doAssert a.repeat(-1) == @[] # will not compile! #doAssert a.repeat(-1) == @[] # will not compile!
doAssert b.repeat(3) == @[] doAssert b.repeat(3) == @[]
when not defined(testing):
echo "Finished doc tests" echo "Finished doc tests"

View file

@ -970,6 +970,7 @@ when isMainModule and not defined(release):
if s <= i or mustRehash(s, i): if s <= i or mustRehash(s, i):
echo "performance issue: rightSize() will not elide enlarge() at ", i echo "performance issue: rightSize() will not elide enlarge() at ", i
when not defined(testing):
echo "Micro tests run successfully." echo "Micro tests run successfully."
testModule() testModule()

View file

@ -78,7 +78,7 @@ proc advice*(s: var ThreadPoolState): ThreadPoolAdvice =
result = doNothing result = doNothing
inc s.calls inc s.calls
when isMainModule: when not defined(testing) and isMainModule:
proc busyLoop() = proc busyLoop() =
while true: while true:
discard random(80) discard random(80)

View file

@ -56,6 +56,12 @@ proc setCookie*(key, value: string, expires: TimeInfo,
when isMainModule: when isMainModule:
var tim = Time(int(getTime()) + 76 * (60 * 60 * 24)) var tim = Time(int(getTime()) + 76 * (60 * 60 * 24))
echo(setCookie("test", "value", tim.getGMTime())) let cookie = setCookie("test", "value", tim.getGMTime())
when not defined(testing):
echo cookie
let start = "Set-Cookie: test=value; Expires="
assert cookie[0..start.high] == start
echo parseCookies("uid=1; kp=2") let table = parseCookies("uid=1; kp=2")
assert table["uid"] == "1"
assert table["kp"] == "2"

View file

@ -451,7 +451,7 @@ proc convert*(s: string, destEncoding = "UTF-8",
finally: finally:
close(c) close(c)
when isMainModule: when not defined(testing) and isMainModule:
let let
orig = "öäüß" orig = "öäüß"
cp1252 = convert(orig, "CP1252", "UTF-8") cp1252 = convert(orig, "CP1252", "UTF-8")

View file

@ -198,7 +198,7 @@ proc register*(d: Dispatcher, monitor: FSMonitor,
var deleg = toDelegate(monitor) var deleg = toDelegate(monitor)
d.register(deleg) d.register(deleg)
when isMainModule: when not defined(testing) and isMainModule:
proc main = proc main =
var disp = newDispatcher() var disp = newDispatcher()
var monitor = newMonitor() var monitor = newMonitor()

View file

@ -629,7 +629,7 @@ when isMainModule:
if not d.poll(): break if not d.poll(): break
main() main()
when isMainModule and false: when not defined(testing) and isMainModule:
var ftp = ftpClient("example.com", user = "foo", pass = "bar") var ftp = ftpClient("example.com", user = "foo", pass = "bar")
ftp.connect() ftp.connect()
echo ftp.pwd() echo ftp.pwd()

View file

@ -186,8 +186,19 @@ when isMainModule:
assert( z["first"]["one"] == 1) # retrieve from first inner table assert( z["first"]["one"] == 1) # retrieve from first inner table
assert( z["second"]["red"] == 10) # retrieve from second inner table assert( z["second"]["red"] == 10) # retrieve from second inner table
var output = ""
for k, v in pairs(z): for k, v in pairs(z):
echo( "$# ($#) ->" % [k,$len(v)] ) output.add( "$# ($#) ->\n" % [k,$len(v)] )
#for k2,v2 in pairs(v): for k2,v2 in pairs(v):
# echo( " $# <-> $#" % [k2,$v2] ) output.add( " $# <-> $#\n" % [k2,$v2] )
echo()
let expected = unindent """
first (3) ->
two <-> 2
three <-> 3
one <-> 1
second (2) ->
red <-> 10
blue <-> 20
"""
assert output == expected

View file

@ -483,7 +483,8 @@ macro `var`*(e: expr): expr {.immediate.} =
result = xmlCheckedTag(e, "var", commonAttr) result = xmlCheckedTag(e, "var", commonAttr)
when isMainModule: when isMainModule:
var nim = "Nim" let nim = "Nim"
echo h1(a(href="http://nim-lang.org", nim)) assert h1(a(href="http://nim-lang.org", nim)) ==
echo form(action="test", `accept-charset` = "Content-Type") """<h1><a href="http://nim-lang.org">Nim</a></h1>"""
assert form(action="test", `accept-charset` = "Content-Type") ==
"""<form action="test" accept-charset="Content-Type"></form>"""

View file

@ -593,7 +593,7 @@ proc loadHtml*(path: string): XmlNode =
var errors: seq[string] = @[] var errors: seq[string] = @[]
result = loadHtml(path, errors) result = loadHtml(path, errors)
when isMainModule: when not defined(testing) and isMainModule:
import os import os
var errors: seq[string] = @[] var errors: seq[string] = @[]

View file

@ -819,7 +819,7 @@ proc get*(client: AsyncHttpClient, url: string): Future[Response] {.async.} =
result = await client.request(redirectTo, httpGET) result = await client.request(redirectTo, httpGET)
lastUrl = redirectTo lastUrl = redirectTo
when isMainModule: when not defined(testing) and isMainModule:
when true: when true:
# Async # Async
proc main() {.async.} = proc main() {.async.} =

View file

@ -514,7 +514,7 @@ proc close*(h: PAsyncHTTPServer) =
## Closes the ``PAsyncHTTPServer``. ## Closes the ``PAsyncHTTPServer``.
h.asyncSocket.close() h.asyncSocket.close()
when isMainModule: when not defined(testing) and isMainModule:
var counter = 0 var counter = 0
var s: TServer var s: TServer

View file

@ -1153,8 +1153,11 @@ when false:
when isMainModule: when isMainModule:
#var node = parse("{ \"test\": null }") #var node = parse("{ \"test\": null }")
#echo(node.existsKey("test56")) #echo(node.existsKey("test56"))
var parsed = parseFile("tests/testdata/jsontest.json") var parsed = parseFile("tests/testdata/jsontest.json")
var parsed2 = parseFile("tests/testdata/jsontest2.json") var parsed2 = parseFile("tests/testdata/jsontest2.json")
when not defined(testing):
echo(parsed) echo(parsed)
echo() echo()
echo(pretty(parsed, 2)) echo(pretty(parsed, 2))
@ -1228,6 +1231,7 @@ when isMainModule:
] ]
assert j3 == %[%{"name": %"John", "age": %30}, %{"name": %"Susan", "age": %31}] assert j3 == %[%{"name": %"John", "age": %30}, %{"name": %"Susan", "age": %31}]
when not defined(testing):
discard """ discard """
while true: while true:
var json = stdin.readLine() var json = stdin.readLine()

View file

@ -278,7 +278,7 @@ proc getLogFilter*(): Level =
# -------------- # --------------
when isMainModule: when not defined(testing) and isMainModule:
var L = newConsoleLogger() var L = newConsoleLogger()
var fL = newFileLogger("test.log", fmtStr = verboseFmtStr) var fL = newFileLogger("test.log", fmtStr = verboseFmtStr)
var rL = newRollingFileLogger("rolling.log", fmtStr = verboseFmtStr) var rL = newRollingFileLogger("rolling.log", fmtStr = verboseFmtStr)

View file

@ -244,7 +244,7 @@ proc to*[T](data: string): T =
var tab = initTable[BiggestInt, pointer]() var tab = initTable[BiggestInt, pointer]()
loadAny(newStringStream(data), toAny(result), tab) loadAny(newStringStream(data), toAny(result), tab)
when isMainModule: when not defined(testing) and isMainModule:
template testit(x: expr) = echo($$to[type(x)]($$x)) template testit(x: expr) = echo($$to[type(x)]($$x))
var x: array[0..4, array[0..4, string]] = [ var x: array[0..4, array[0..4, string]] = [

View file

@ -372,6 +372,8 @@ when isMainModule and not defined(JS):
randomize(seed) randomize(seed)
for i in 0..SIZE-1: for i in 0..SIZE-1:
assert buf[i] == random(high(int)), "non deterministic random seeding" assert buf[i] == random(high(int)), "non deterministic random seeding"
when not defined(testing):
echo "random values equal after reseeding" echo "random values equal after reseeding"
# Check for no side effect annotation # Check for no side effect annotation

View file

@ -32,7 +32,7 @@ proc getNum*(m: var MersenneTwister): int =
return int(y) return int(y)
# Test # Test
when isMainModule: when not defined(testing) and isMainModule:
var mt = newMersenneTwister(2525) var mt = newMersenneTwister(2525)
for i in 0..99: for i in 0..99:

View file

@ -518,5 +518,5 @@ proc register*(mimedb: var MimeDB, ext: string, mimetype: string) =
when isMainModule: when isMainModule:
var m = newMimetypes() var m = newMimetypes()
echo m.getMimetype("mp4") assert m.getMimetype("mp4") == "video/mp4"
echo m.getExt("text/html") assert m.getExt("text/html") == "html"

View file

@ -88,6 +88,6 @@ proc generatedTime*(oid: Oid): Time =
bigEndian32(addr(tmp), addr(dummy)) bigEndian32(addr(tmp), addr(dummy))
result = Time(tmp) result = Time(tmp)
when isMainModule: when not defined(testing) and isMainModule:
let xo = genOid() let xo = genOid()
echo xo.generatedTime echo xo.generatedTime

View file

@ -166,7 +166,7 @@ proc close*(my: var CsvParser) {.inline.} =
## closes the parser `my` and its associated input stream. ## closes the parser `my` and its associated input stream.
lexbase.close(my) lexbase.close(my)
when isMainModule: when not defined(testing) and isMainModule:
import os import os
var s = newFileStream(paramStr(1), fmRead) var s = newFileStream(paramStr(1), fmRead)
if s == nil: quit("cannot open the file" & paramStr(1)) if s == nil: quit("cannot open the file" & paramStr(1))

View file

@ -1330,7 +1330,7 @@ proc renderSQL*(n: SqlNode): string =
result = "" result = ""
ra(n, result, 0) ra(n, result, 0)
when isMainModule: when not defined(testing) and isMainModule:
echo(renderSQL(parseSQL(newStringStream(""" echo(renderSQL(parseSQL(newStringStream("""
CREATE TYPE happiness AS ENUM ('happy', 'very happy', 'ecstatic'); CREATE TYPE happiness AS ENUM ('happy', 'very happy', 'ecstatic');
CREATE TABLE holidays ( CREATE TABLE holidays (

View file

@ -323,8 +323,12 @@ iterator interpolatedFragments*(s: string): tuple[kind: InterpolatedKind,
i = j i = j
when isMainModule: when isMainModule:
for k, v in interpolatedFragments("$test{} $this is ${an{ example}} "): import sequtils
echo "(", k, ", \"", v, "\")" let input = "$test{} $this is ${an{ example}} "
let expected = @[(ikVar, "test"), (ikStr, "{} "), (ikVar, "this"),
(ikStr, " is "), (ikExpr, "an{ example}"), (ikStr, " ")]
assert toSeq(interpolatedFragments(input)) == expected
var value = 0 var value = 0
discard parseHex("0x38", value) discard parseHex("0x38", value)
assert value == 56 assert value == 56

View file

@ -628,7 +628,7 @@ proc next*(my: var XmlParser) =
my.kind = xmlError my.kind = xmlError
my.state = stateNormal my.state = stateNormal
when isMainModule: when not defined(testing) and isMainModule:
import os import os
var s = newFileStream(paramStr(1), fmRead) var s = newFileStream(paramStr(1), fmRead)
if s == nil: quit("cannot open the file" & paramStr(1)) if s == nil: quit("cannot open the file" & paramStr(1))

View file

@ -1080,7 +1080,7 @@ proc assertListsIdentical(listA, listB: seq[string]) =
assert(item == listB[i]) assert(item == listB[i])
i = i + 1 i = i + 1
when isMainModule: when not defined(testing) and isMainModule:
when false: when false:
var r = open() var r = open()

View file

@ -44,16 +44,13 @@ proc decimalToRoman*(number: range[1..3_999]): string =
("XC", 90), ("L", 50), ("XL", 40), ("X", 10), ("IX", 9), ("XC", 90), ("L", 50), ("XL", 40), ("X", 10), ("IX", 9),
("V", 5), ("IV", 4), ("I", 1)] ("V", 5), ("IV", 4), ("I", 1)]
result = "" result = ""
var decVal = number var decVal: int = number
for key, val in items(romanComposites): for key, val in items(romanComposites):
while decVal >= val: while decVal >= val:
dec(decVal, val) dec(decVal, val)
result.add(key) result.add(key)
when isMainModule: when isMainModule:
import math for i in 1 .. 3_999:
randomize() assert i == i.decimalToRoman.romanToDecimal
for i in 1 .. 100:
var rnd = 1 + random(3990)
assert rnd == rnd.decimalToRoman.romanToDecimal

View file

@ -296,7 +296,7 @@ proc contains*(s: Selector, key: SelectorKey): bool =
TReadyInfo: ReadyInfo, PSelector: Selector].} TReadyInfo: ReadyInfo, PSelector: Selector].}
when isMainModule and not defined(nimdoc): when not defined(testing) and isMainModule and not defined(nimdoc):
# Select() # Select()
import sockets import sockets
type type

View file

@ -253,7 +253,7 @@ proc close*(smtp: AsyncSmtp) {.async.} =
await smtp.sock.send("QUIT\c\L") await smtp.sock.send("QUIT\c\L")
smtp.sock.close() smtp.sock.close()
when isMainModule: when not defined(testing) and isMainModule:
#var msg = createMessage("Test subject!", #var msg = createMessage("Test subject!",
# "Hello, my name is dom96.\n What\'s yours?", @["dominik@localhost"]) # "Hello, my name is dom96.\n What\'s yours?", @["dominik@localhost"])
#echo(msg) #echo(msg)

View file

@ -1402,12 +1402,18 @@ when isMainModule:
doAssert align("a", 0) == "a" doAssert align("a", 0) == "a"
doAssert align("1232", 6) == " 1232" doAssert align("1232", 6) == " 1232"
doAssert align("1232", 6, '#') == "##1232" doAssert align("1232", 6, '#') == "##1232"
echo wordWrap(""" this is a long text -- muchlongerthan10chars and here
it goes""", 10, false) let
inp = """ this is a long text -- muchlongerthan10chars and here
it goes"""
outp = " this is a\nlong text\n--\nmuchlongerthan10chars\nand here\nit goes"
doAssert wordWrap(inp, 10, false) == outp
doAssert formatBiggestFloat(0.00000000001, ffDecimal, 11) == "0.00000000001" doAssert formatBiggestFloat(0.00000000001, ffDecimal, 11) == "0.00000000001"
doAssert formatBiggestFloat(0.00000000001, ffScientific, 1) == "1.0e-11" doAssert formatBiggestFloat(0.00000000001, ffScientific, 1) == "1.0e-11"
doAssert "$# $3 $# $#" % ["a", "b", "c"] == "a c b c" doAssert "$# $3 $# $#" % ["a", "b", "c"] == "a c b c"
when not defined(testing):
echo formatSize(1'i64 shl 31 + 300'i64) # == "4,GB" echo formatSize(1'i64 shl 31 + 300'i64) # == "4,GB"
echo formatSize(1'i64 shl 31) echo formatSize(1'i64 shl 31)

View file

@ -386,8 +386,13 @@ when isMainModule:
longishA, longishA,
longish)""" longish)"""
echo "type TMyEnum* = enum\n $', '2i'\n '{..}" % ["fieldA", assert "type TMyEnum* = enum\n $', '2i'\n '{..}" % ["fieldA",
"fieldB", "FiledClkad", "fieldD", "fieldE", "longishFieldName"] "fieldB", "FiledClkad", "fieldD", "fieldE", "longishFieldName"] ==
strutils.unindent """
type TMyEnum* = enum
fieldA, fieldB,
FiledClkad, fieldD,
fieldE, longishFieldName"""
doAssert subex"$1($', '{2..})" % ["f", "a", "b", "c"] == "f(a, b, c)" doAssert subex"$1($', '{2..})" % ["f", "a", "b", "c"] == "f(a, b, c)"
@ -395,7 +400,12 @@ when isMainModule:
doAssert subex"$['''|'|''''|']']#" % "0" == "'|" doAssert subex"$['''|'|''''|']']#" % "0" == "'|"
echo subex("type\n TEnum = enum\n $', '40c'\n '{..}") % [ assert subex("type\n TEnum = enum\n $', '40c'\n '{..}") % [
"fieldNameA", "fieldNameB", "fieldNameC", "fieldNameD"] "fieldNameA", "fieldNameB", "fieldNameC", "fieldNameD"] ==
strutils.unindent """
type
TEnum = enum
fieldNameA, fieldNameB, fieldNameC,
fieldNameD"""

View file

@ -375,7 +375,7 @@ when not defined(windows):
result = stdin.readChar() result = stdin.readChar()
discard fd.tcsetattr(TCSADRAIN, addr oldMode) discard fd.tcsetattr(TCSADRAIN, addr oldMode)
when isMainModule: when not defined(testing) and isMainModule:
system.addQuitProc(resetAttributes) system.addQuitProc(resetAttributes)
write(stdout, "never mind") write(stdout, "never mind")
eraseLine() eraseLine()

View file

@ -1036,8 +1036,6 @@ when isMainModule:
# Tue 19 Jan 03:14:07 GMT 2038 # Tue 19 Jan 03:14:07 GMT 2038
var t = getGMTime(fromSeconds(2147483647)) var t = getGMTime(fromSeconds(2147483647))
echo t.format("ddd dd MMM hh:mm:ss ZZZ yyyy")
echo t.format("ddd ddMMMhhmmssZZZyyyy")
assert t.format("ddd dd MMM hh:mm:ss ZZZ yyyy") == "Tue 19 Jan 03:14:07 UTC 2038" assert t.format("ddd dd MMM hh:mm:ss ZZZ yyyy") == "Tue 19 Jan 03:14:07 UTC 2038"
assert t.format("ddd ddMMMhh:mm:ssZZZyyyy") == "Tue 19Jan03:14:07UTC2038" assert t.format("ddd ddMMMhh:mm:ssZZZyyyy") == "Tue 19Jan03:14:07UTC2038"
@ -1112,4 +1110,6 @@ when isMainModule:
# Kitchen = "3:04PM" # Kitchen = "3:04PM"
s = "3:04PM" s = "3:04PM"
f = "h:mmtt" f = "h:mmtt"
assert "15:04:00" in $s.parse(f)
when not defined(testing):
echo "Kitchen: " & $s.parse(f) echo "Kitchen: " & $s.parse(f)

View file

@ -70,5 +70,5 @@ proc unidecode*(s: string): string =
when isMainModule: when isMainModule:
loadUnidecodeTable("lib/pure/unidecode/unidecode.dat") loadUnidecodeTable("lib/pure/unidecode/unidecode.dat")
echo unidecode("Äußerst") assert unidecode("Äußerst") == "Ausserst"

View file

@ -155,7 +155,7 @@ proc loadXMLFile*(path: string): PDocument =
return loadXMLStream(s) return loadXMLStream(s)
when isMainModule: when not defined(testing) and isMainModule:
var xml = loadXMLFile("nim/xmldom/test.xml") var xml = loadXMLFile("nim/xmldom/test.xml")
#echo(xml.getElementsByTagName("m:test2")[0].namespaceURI) #echo(xml.getElementsByTagName("m:test2")[0].namespaceURI)
#echo(xml.getElementsByTagName("bla:test")[0].namespaceURI) #echo(xml.getElementsByTagName("bla:test")[0].namespaceURI)

View file

@ -143,7 +143,7 @@ proc loadXml*(path: string): XmlNode =
result = loadXml(path, errors) result = loadXml(path, errors)
if errors.len > 0: raiseInvalidXml(errors) if errors.len > 0: raiseInvalidXml(errors)
when isMainModule: when not defined(testing) and isMainModule:
import os import os
var errors: seq[string] = @[] var errors: seq[string] = @[]

View file

@ -353,5 +353,6 @@ proc findAll*(n: XmlNode, tag: string): seq[XmlNode] =
findAll(n, tag, result) findAll(n, tag, result)
when isMainModule: when isMainModule:
assert """<a href="http://nim-lang.org">Nim rules.</a>""" == let link = "http://nim-lang.org"
assert """<a href="""" & escape(link) & """">Nim rules.</a>""" ==
$(<>a(href="http://nim-lang.org", newText("Nim rules."))) $(<>a(href="http://nim-lang.org", newText("Nim rules.")))

View file

@ -2710,7 +2710,7 @@ proc workspace_window_set_icon*(w: ptr TWorkspaceWindow, icon: ptr TImage){.
claro_base_init() claro_base_init()
claro_graphics_init() claro_graphics_init()
when isMainModule: when not defined(testing) and isMainModule:
var w = newWindow(nil, newBounds(100, 100, 230, 230), 0) var w = newWindow(nil, newBounds(100, 100, 230, 230), 0)
window_set_title(w, "Hello, World!") window_set_title(w, "Hello, World!")