CI: test with multiple Nim versions (#23)
* CI: test with multiple Nim versions * fix readIntoExImpl() when premature EOF is triggered on some Windows versions * also fix some unrelated pointer math
This commit is contained in:
parent
c653d05f27
commit
371e60b17c
5 changed files with 141 additions and 135 deletions
|
|
@ -58,26 +58,27 @@ suite "input stream":
|
|||
var input = memFileInput("files" / "empty_file")
|
||||
|
||||
template asciiTableFileTest(name: string, body: untyped) =
|
||||
test name & " of ascii table with regular pageSize":
|
||||
var input {.inject.} = fileInput(asciiTableFile)
|
||||
try:
|
||||
body
|
||||
finally:
|
||||
close input
|
||||
suite name:
|
||||
test name & " of ascii table with regular pageSize":
|
||||
var input {.inject.} = fileInput(asciiTableFile)
|
||||
try:
|
||||
body
|
||||
finally:
|
||||
close input
|
||||
|
||||
test name & " of ascii table with pageSize = 10":
|
||||
var input {.inject.} = fileInput(asciiTableFile, pageSize = 10)
|
||||
try:
|
||||
body
|
||||
finally:
|
||||
close input
|
||||
test name & " of ascii table with pageSize = 10":
|
||||
var input {.inject.} = fileInput(asciiTableFile, pageSize = 10)
|
||||
try:
|
||||
body
|
||||
finally:
|
||||
close input
|
||||
|
||||
test name & " of ascii table with pageSize = 1":
|
||||
var input {.inject.} = fileInput(asciiTableFile, pageSize = 1)
|
||||
try:
|
||||
body
|
||||
finally:
|
||||
close input
|
||||
test name & " of ascii table with pageSize = 1":
|
||||
var input {.inject.} = fileInput(asciiTableFile, pageSize = 1)
|
||||
try:
|
||||
body
|
||||
finally:
|
||||
close input
|
||||
|
||||
# TODO: fileInput with offset
|
||||
# - in the middle of the
|
||||
|
|
@ -124,41 +125,42 @@ suite "input stream":
|
|||
|
||||
check fileContents == asciiTableContents
|
||||
|
||||
test "missing file input":
|
||||
const fileName = "there-is-no-such-faststreams-file"
|
||||
suite "misc":
|
||||
test "missing file input":
|
||||
const fileName = "there-is-no-such-faststreams-file"
|
||||
|
||||
check not fileExists(fileName)
|
||||
expect CatchableError: discard fileInput(fileName)
|
||||
check not fileExists(fileName)
|
||||
expect CatchableError: discard fileInput(fileName)
|
||||
|
||||
check not fileExists(fileName)
|
||||
expect CatchableError: discard memFileInput(fileName)
|
||||
check not fileExists(fileName)
|
||||
expect CatchableError: discard memFileInput(fileName)
|
||||
|
||||
check not fileExists(fileName)
|
||||
check not fileExists(fileName)
|
||||
|
||||
test "non-blocking reads":
|
||||
let s = fileInput(asciiTableFile, pageSize = 100)
|
||||
if s.readable(20):
|
||||
s.withReadableRange(20, r):
|
||||
check r.len.get == 20
|
||||
check r.totalUnconsumedBytes == 20
|
||||
check r.readAll.len == 20
|
||||
test "non-blocking reads":
|
||||
let s = fileInput(asciiTableFile, pageSize = 100)
|
||||
if s.readable(20):
|
||||
s.withReadableRange(20, r):
|
||||
check r.len.get == 20
|
||||
check r.totalUnconsumedBytes == 20
|
||||
check r.readAll.len == 20
|
||||
|
||||
check s.readable
|
||||
check s.readable
|
||||
|
||||
if s.readable(200):
|
||||
s.withReadableRange(200, r):
|
||||
check r.len.get == 200
|
||||
check r.totalUnconsumedBytes == 200
|
||||
check r.readAll.len == 200
|
||||
if s.readable(200):
|
||||
s.withReadableRange(200, r):
|
||||
check r.len.get == 200
|
||||
check r.totalUnconsumedBytes == 200
|
||||
check r.readAll.len == 200
|
||||
|
||||
check s.readable
|
||||
check s.readable
|
||||
|
||||
test "simple":
|
||||
var input = repeat("1234 5678 90AB CDEF\n", 1000)
|
||||
var stream = unsafeMemoryInput(input)
|
||||
test "simple":
|
||||
var input = repeat("1234 5678 90AB CDEF\n", 1000)
|
||||
var stream = unsafeMemoryInput(input)
|
||||
|
||||
check:
|
||||
(stream.read(4) == "1234".toOpenArrayByte(0, 3))
|
||||
check:
|
||||
(stream.read(4) == "1234".toOpenArrayByte(0, 3))
|
||||
|
||||
template posTest(name: string, setup: untyped) =
|
||||
test name:
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{.used.}
|
||||
|
||||
import
|
||||
os, unittest, random, strformat,
|
||||
os, unittest2, random, strformat,
|
||||
stew/ranges/ptr_arith,
|
||||
../faststreams, ../faststreams/textio
|
||||
|
||||
|
|
@ -20,12 +20,10 @@ proc repeat(b: byte, count: int): seq[byte] =
|
|||
result = newSeq[byte](count)
|
||||
for i in 0 ..< count: result[i] = b
|
||||
|
||||
const line = "123456789123456789123456789123456789\n\n\n\n\n"
|
||||
|
||||
proc randomBytes(n: int): seq[byte] =
|
||||
result.newSeq n
|
||||
for i in 0 ..< n:
|
||||
result[i] = byte(rand(line))
|
||||
result[i] = byte(rand(int('1')..int('9')))
|
||||
|
||||
proc readAllAndClose(s: InputStream): seq[byte] =
|
||||
while s.readable:
|
||||
|
|
@ -55,6 +53,8 @@ suite "output stream":
|
|||
streamWritingToExistingBuffer = unsafeMemoryOutput(buffer, bufferSize)
|
||||
|
||||
teardown:
|
||||
fileStream.close()
|
||||
unbufferedFileStream.close()
|
||||
removeFile fileOutputPath
|
||||
removeFile unbufferedFileOutputPath
|
||||
dealloc buffer
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue