made some tests green
This commit is contained in:
parent
dd830d2e7d
commit
ae548a696f
8 changed files with 28 additions and 29 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
===========================
|
========================
|
||||||
Tools available with Nim
|
Tools available with Nim
|
||||||
===========================
|
========================
|
||||||
|
|
||||||
The standard distribution ships with the following tools:
|
The standard distribution ships with the following tools:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@ type
|
||||||
disp: Dispatcher
|
disp: Dispatcher
|
||||||
AsyncScgiState* = ref AsyncScgiStateObj
|
AsyncScgiState* = ref AsyncScgiStateObj
|
||||||
|
|
||||||
{.deprected: [EScgi: ScgiError, TScgiState: ScgiState,
|
{.deprecated: [EScgi: ScgiError, TScgiState: ScgiState,
|
||||||
PAsyncScgiState: AsyncScgiState, scgiError: raiseScgiError].}
|
PAsyncScgiState: AsyncScgiState, scgiError: raiseScgiError].}
|
||||||
|
|
||||||
proc recvBuffer(s: var ScgiState, L: int) =
|
proc recvBuffer(s: var ScgiState, L: int) =
|
||||||
|
|
@ -108,12 +108,12 @@ proc open*(s: var ScgiState, port = Port(4000), address = "127.0.0.1",
|
||||||
s.input = newString(s.buflen) # will be reused
|
s.input = newString(s.buflen) # will be reused
|
||||||
|
|
||||||
s.server = socket()
|
s.server = socket()
|
||||||
if s.server == InvalidSocket: raiseOSError(osLastError())
|
if s.server == invalidSocket: raiseOSError(osLastError())
|
||||||
new(s.client) # Initialise s.client for `next`
|
new(s.client) # Initialise s.client for `next`
|
||||||
if s.server == InvalidSocket: raiseScgiError("could not open socket")
|
if s.server == invalidSocket: raiseScgiError("could not open socket")
|
||||||
#s.server.connect(connectionName, port)
|
#s.server.connect(connectionName, port)
|
||||||
if reuseAddr:
|
if reuseAddr:
|
||||||
s.server.setSockOpt(OptReuseAddr, True)
|
s.server.setSockOpt(OptReuseAddr, true)
|
||||||
bindAddr(s.server, port, address)
|
bindAddr(s.server, port, address)
|
||||||
listen(s.server)
|
listen(s.server)
|
||||||
|
|
||||||
|
|
@ -135,7 +135,7 @@ proc next*(s: var ScgiState, timeout: int = -1): bool =
|
||||||
if d == '\0':
|
if d == '\0':
|
||||||
s.client.close()
|
s.client.close()
|
||||||
return false
|
return false
|
||||||
if d notin strutils.digits:
|
if d notin strutils.Digits:
|
||||||
if d != ':': raiseScgiError("':' after length expected")
|
if d != ':': raiseScgiError("':' after length expected")
|
||||||
break
|
break
|
||||||
L = L * 10 + ord(d) - ord('0')
|
L = L * 10 + ord(d) - ord('0')
|
||||||
|
|
@ -144,7 +144,7 @@ proc next*(s: var ScgiState, timeout: int = -1): bool =
|
||||||
if s.headers["SCGI"] != "1": raiseScgiError("SCGI Version 1 expected")
|
if s.headers["SCGI"] != "1": raiseScgiError("SCGI Version 1 expected")
|
||||||
L = parseInt(s.headers["CONTENT_LENGTH"])
|
L = parseInt(s.headers["CONTENT_LENGTH"])
|
||||||
recvBuffer(s, L)
|
recvBuffer(s, L)
|
||||||
return True
|
return true
|
||||||
|
|
||||||
proc writeStatusOkTextContent*(c: Socket, contentType = "text/html") =
|
proc writeStatusOkTextContent*(c: Socket, contentType = "text/html") =
|
||||||
## sends the following string to the socket `c`::
|
## sends the following string to the socket `c`::
|
||||||
|
|
@ -206,7 +206,7 @@ proc handleClientRead(client: AsyncClient, s: AsyncScgiState) =
|
||||||
return
|
return
|
||||||
if ret == -1:
|
if ret == -1:
|
||||||
return # No more data available
|
return # No more data available
|
||||||
if d[0] notin strutils.digits:
|
if d[0] notin strutils.Digits:
|
||||||
if d[0] != ':': raiseScgiError("':' after length expected")
|
if d[0] != ':': raiseScgiError("':' after length expected")
|
||||||
break
|
break
|
||||||
client.dataLen = client.dataLen * 10 + ord(d[0]) - ord('0')
|
client.dataLen = client.dataLen * 10 + ord(d[0]) - ord('0')
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,8 @@ var
|
||||||
|
|
||||||
checkpoints = @[]
|
checkpoints = @[]
|
||||||
|
|
||||||
template TestSetupIMPL*: stmt {.immediate, dirty.} = discard
|
template testSetupIMPL*: stmt {.immediate, dirty.} = discard
|
||||||
template TestTeardownIMPL*: stmt {.immediate, dirty.} = discard
|
template testTeardownIMPL*: stmt {.immediate, dirty.} = discard
|
||||||
|
|
||||||
proc shouldRun(testName: string): bool =
|
proc shouldRun(testName: string): bool =
|
||||||
result = true
|
result = true
|
||||||
|
|
@ -49,10 +49,10 @@ proc shouldRun(testName: string): bool =
|
||||||
template suite*(name: expr, body: stmt): stmt {.immediate, dirty.} =
|
template suite*(name: expr, body: stmt): stmt {.immediate, dirty.} =
|
||||||
block:
|
block:
|
||||||
template setup*(setupBody: stmt): stmt {.immediate, dirty.} =
|
template setup*(setupBody: stmt): stmt {.immediate, dirty.} =
|
||||||
template TestSetupIMPL: stmt {.immediate, dirty.} = setupBody
|
template testSetupIMPL: stmt {.immediate, dirty.} = setupBody
|
||||||
|
|
||||||
template teardown*(teardownBody: stmt): stmt {.immediate, dirty.} =
|
template teardown*(teardownBody: stmt): stmt {.immediate, dirty.} =
|
||||||
template TestTeardownIMPL: stmt {.immediate, dirty.} = teardownBody
|
template testTeardownIMPL: stmt {.immediate, dirty.} = teardownBody
|
||||||
|
|
||||||
body
|
body
|
||||||
|
|
||||||
|
|
@ -60,10 +60,10 @@ proc testDone(name: string, s: TestStatus) =
|
||||||
if s == FAILED:
|
if s == FAILED:
|
||||||
programResult += 1
|
programResult += 1
|
||||||
|
|
||||||
if OutputLevel != PRINT_NONE and (OutputLevel == PRINT_ALL or s == FAILED):
|
if outputLevel != PRINT_NONE and (outputLevel == PRINT_ALL or s == FAILED):
|
||||||
template rawPrint() = echo("[", $s, "] ", name, "\n")
|
template rawPrint() = echo("[", $s, "] ", name, "\n")
|
||||||
when not defined(ECMAScript):
|
when not defined(ECMAScript):
|
||||||
if ColorOutput and not defined(ECMAScript):
|
if colorOutput and not defined(ECMAScript):
|
||||||
var color = (if s == OK: fgGreen else: fgRed)
|
var color = (if s == OK: fgGreen else: fgRed)
|
||||||
styledEcho styleBright, color, "[", $s, "] ", fgWhite, name, "\n"
|
styledEcho styleBright, color, "[", $s, "] ", fgWhite, name, "\n"
|
||||||
else:
|
else:
|
||||||
|
|
@ -76,10 +76,10 @@ template test*(name: expr, body: stmt): stmt {.immediate, dirty.} =
|
||||||
|
|
||||||
if shouldRun(name):
|
if shouldRun(name):
|
||||||
checkpoints = @[]
|
checkpoints = @[]
|
||||||
var TestStatusIMPL {.inject.} = OK
|
var testStatusIMPL {.inject.} = OK
|
||||||
|
|
||||||
try:
|
try:
|
||||||
TestSetupIMPL()
|
testSetupIMPL()
|
||||||
body
|
body
|
||||||
|
|
||||||
except:
|
except:
|
||||||
|
|
@ -87,8 +87,8 @@ template test*(name: expr, body: stmt): stmt {.immediate, dirty.} =
|
||||||
fail()
|
fail()
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
TestTeardownIMPL()
|
testTeardownIMPL()
|
||||||
testDone name, TestStatusIMPL
|
testDone name, testStatusIMPL
|
||||||
|
|
||||||
proc checkpoint*(msg: string) =
|
proc checkpoint*(msg: string) =
|
||||||
checkpoints.add(msg)
|
checkpoints.add(msg)
|
||||||
|
|
@ -100,10 +100,10 @@ template fail* =
|
||||||
echo msg
|
echo msg
|
||||||
|
|
||||||
when not defined(ECMAScript):
|
when not defined(ECMAScript):
|
||||||
if AbortOnError: quit(1)
|
if abortOnError: quit(1)
|
||||||
|
|
||||||
when declared(TestStatusIMPL):
|
when declared(testStatusIMPL):
|
||||||
TestStatusIMPL = FAILED
|
testStatusIMPL = FAILED
|
||||||
else:
|
else:
|
||||||
programResult += 1
|
programResult += 1
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,4 +18,4 @@ proc `++`(x, y: DF): DF {.borrow.}
|
||||||
proc `$`(x: DI): string {.borrow.}
|
proc `$`(x: DI): string {.borrow.}
|
||||||
proc `$`(x: DF): string {.borrow.}
|
proc `$`(x: DF): string {.borrow.}
|
||||||
|
|
||||||
echo 4544.DI ++ 343.di, " ", (4.5.df ++ 0.5.df).float == 5.0
|
echo 4544.DI ++ 343.DI, " ", (4.5.DF ++ 0.5.DF).float == 5.0
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
discard """
|
discard """
|
||||||
file: "tsubrange2.nim"
|
file: "tsubrange2.nim"
|
||||||
outputsub: "value out of range: 50 [EOutOfRange]"
|
outputsub: "value out of range: 50 [RangeError]"
|
||||||
exitcode: "1"
|
exitcode: "1"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
discard """
|
discard """
|
||||||
file: "tsubrange.nim"
|
file: "tsubrange.nim"
|
||||||
outputsub: "value out of range: 50 [EOutOfRange]"
|
outputsub: "value out of range: 50 [RangeError]"
|
||||||
exitcode: "1"
|
exitcode: "1"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
@ -16,4 +16,3 @@ var
|
||||||
r = y
|
r = y
|
||||||
|
|
||||||
#p y
|
#p y
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,7 @@ block orderedTableTest1:
|
||||||
block countTableTest1:
|
block countTableTest1:
|
||||||
var s = data.toTable
|
var s = data.toTable
|
||||||
var t = initCountTable[string]()
|
var t = initCountTable[string]()
|
||||||
for k in s.Keys: t.inc(k)
|
for k in s.keys: t.inc(k)
|
||||||
for k in t.keys: assert t[k] == 1
|
for k in t.keys: assert t[k] == 1
|
||||||
t.inc("90", 3)
|
t.inc("90", 3)
|
||||||
t.inc("12", 2)
|
t.inc("12", 2)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
type pnode* = ref object of tobject
|
type PNode* = ref object of RootObj
|
||||||
|
|
||||||
template litNode (name, ty): stmt =
|
template litNode (name, ty): stmt =
|
||||||
type name* = ref object of PNode
|
type name* = ref object of PNode
|
||||||
|
|
@ -8,7 +8,7 @@ litNode PIntNode, int
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
template withKey*(j: PJsonNode; key: string; varname: expr;
|
template withKey*(j: JsonNode; key: string; varname: expr;
|
||||||
body:stmt): stmt {.immediate.} =
|
body:stmt): stmt {.immediate.} =
|
||||||
if j.hasKey(key):
|
if j.hasKey(key):
|
||||||
let varname{.inject.}= j[key]
|
let varname{.inject.}= j[key]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue