mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
make tests green
This commit is contained in:
@@ -12,11 +12,11 @@ const
|
||||
|
||||
var clientCount = 0
|
||||
|
||||
proc sendMessages(client: TAsyncFD) {.async.} =
|
||||
proc sendMessages(client: AsyncFD) {.async.} =
|
||||
for i in 0 .. <messagesToSend:
|
||||
await send(client, "Message " & $i & "\c\L")
|
||||
|
||||
proc launchSwarm(port: TPort) {.async.} =
|
||||
proc launchSwarm(port: Port) {.async.} =
|
||||
for i in 0 .. <swarmSize:
|
||||
var sock = newAsyncNativeSocket()
|
||||
|
||||
@@ -24,7 +24,7 @@ proc launchSwarm(port: TPort) {.async.} =
|
||||
await sendMessages(sock)
|
||||
closeSocket(sock)
|
||||
|
||||
proc readMessages(client: TAsyncFD) {.async.} =
|
||||
proc readMessages(client: AsyncFD) {.async.} =
|
||||
while true:
|
||||
var line = await recvLine(client)
|
||||
if line == "":
|
||||
@@ -37,7 +37,7 @@ proc readMessages(client: TAsyncFD) {.async.} =
|
||||
else:
|
||||
doAssert false
|
||||
|
||||
proc createServer(port: TPort) {.async.} =
|
||||
proc createServer(port: Port) {.async.} =
|
||||
var server = newAsyncNativeSocket()
|
||||
block:
|
||||
var name: Sockaddr_in
|
||||
@@ -55,8 +55,8 @@ proc createServer(port: TPort) {.async.} =
|
||||
while true:
|
||||
asyncCheck readMessages(await accept(server))
|
||||
|
||||
asyncCheck createServer(TPort(10335))
|
||||
asyncCheck launchSwarm(TPort(10335))
|
||||
asyncCheck createServer(Port(10335))
|
||||
asyncCheck launchSwarm(Port(10335))
|
||||
while true:
|
||||
poll()
|
||||
if clientCount == swarmSize: break
|
||||
|
||||
@@ -3,7 +3,7 @@ discard """
|
||||
"""
|
||||
|
||||
import tables
|
||||
from hashes import THash
|
||||
from hashes import Hash
|
||||
|
||||
# Test with int
|
||||
block:
|
||||
@@ -66,7 +66,7 @@ block:
|
||||
# The same test with a custom hash(s: string) does
|
||||
# work though.
|
||||
block:
|
||||
proc hash(x: int): THash {.inline.} =
|
||||
proc hash(x: int): Hash {.inline.} =
|
||||
echo "overloaded hash"
|
||||
result = x
|
||||
var t = initTable[int, int]()
|
||||
|
||||
@@ -81,7 +81,7 @@ semiProblem()
|
||||
# bug #844
|
||||
|
||||
import json
|
||||
proc parseResponse(): PJsonNode =
|
||||
proc parseResponse(): JsonNode =
|
||||
result = % { "key1": % { "key2": % "value" } }
|
||||
for key, val in result["key1"]:
|
||||
var excMsg = key & "("
|
||||
|
||||
@@ -40,11 +40,11 @@ proc mustRehash(length, counter: int): bool {.inline.} =
|
||||
assert(length > counter)
|
||||
result = (length * 2 < counter * 3) or (length - counter < 4)
|
||||
|
||||
proc nextTry(h, maxHash: THash): THash {.inline.} =
|
||||
proc nextTry(h, maxHash: Hash): Hash {.inline.} =
|
||||
result = ((5 * h) + 1) and maxHash
|
||||
|
||||
template rawGetImpl() =
|
||||
var h: THash = hash(key) and high(t.data) # start with real hash value
|
||||
var h: Hash = hash(key) and high(t.data) # start with real hash value
|
||||
while t.data[h].slot != seEmpty:
|
||||
if t.data[h].key == key and t.data[h].slot == seFilled:
|
||||
return h
|
||||
@@ -52,7 +52,7 @@ template rawGetImpl() =
|
||||
result = -1
|
||||
|
||||
template rawInsertImpl() =
|
||||
var h: THash = hash(key) and high(data)
|
||||
var h: Hash = hash(key) and high(data)
|
||||
while data[h].slot == seFilled:
|
||||
h = nextTry(h, high(data))
|
||||
data[h].key = key
|
||||
@@ -162,7 +162,7 @@ iterator values*[A](t: TCountTable[A]): int =
|
||||
if t.data[h].val != 0: yield t.data[h].val
|
||||
|
||||
proc RawGet[A](t: TCountTable[A], key: A): int =
|
||||
var h: THash = hash(key) and high(t.data) # start with real hash value
|
||||
var h: Hash = hash(key) and high(t.data) # start with real hash value
|
||||
while t.data[h].val != 0:
|
||||
if t.data[h].key == key: return h
|
||||
h = nextTry(h, high(t.data))
|
||||
@@ -181,7 +181,7 @@ proc hasKey*[A](t: TCountTable[A], key: A): bool =
|
||||
|
||||
proc rawInsert[A](t: TCountTable[A], data: var seq[tuple[key: A, val: int]],
|
||||
key: A, val: int) =
|
||||
var h: THash = hash(key) and high(data)
|
||||
var h: Hash = hash(key) and high(data)
|
||||
while data[h].val != 0: h = nextTry(h, high(data))
|
||||
data[h].key = key
|
||||
data[h].val = val
|
||||
|
||||
@@ -5,7 +5,7 @@ true'''
|
||||
|
||||
import pegs
|
||||
|
||||
template optPeg{peg(pattern)}(pattern: string{lit}): TPeg =
|
||||
template optPeg{peg(pattern)}(pattern: string{lit}): Peg =
|
||||
var gl {.global, gensym.} = peg(pattern)
|
||||
gl
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ proc works() =
|
||||
sort(f, system.cmp[int])
|
||||
outp(f)
|
||||
|
||||
proc weird(json_params: TTable) =
|
||||
proc weird(json_params: Table) =
|
||||
var f = @[3, 2, 1]
|
||||
# The following line doesn't compile: type mismatch. Why?
|
||||
sort(f, system.cmp[int])
|
||||
@@ -29,4 +29,4 @@ when isMainModule:
|
||||
sort(t, system.cmp[int])
|
||||
outp(t)
|
||||
works()
|
||||
weird(initTable[string, TJsonNode]())
|
||||
weird(initTable[string, JsonNode]())
|
||||
|
||||
Reference in New Issue
Block a user