assert() -> doAssert()
Also fixed a test and added the other to the Nimble task.
This commit is contained in:
parent
7903f1680f
commit
acd5a6063c
6 changed files with 18 additions and 13 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,2 +1 @@
|
||||||
/tests/test_output_stream
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,11 @@ requires "nim >= 0.17.0",
|
||||||
"ranges",
|
"ranges",
|
||||||
"std_shims"
|
"std_shims"
|
||||||
|
|
||||||
task test, "run tests":
|
import ospaths, strutils
|
||||||
exec "nim c -r tests/test_output_stream.nim"
|
|
||||||
|
task test, "Run tests":
|
||||||
|
for filename in listFiles("tests"):
|
||||||
|
if filename.startsWith("tests" / "test_") and filename.endsWith(".nim"):
|
||||||
|
exec "nim c -r " & filename
|
||||||
|
rmFile filename[0..^5]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ proc eob*(s: ByteStream): bool {.inline.} =
|
||||||
s.head != s.bufferEnd
|
s.head != s.bufferEnd
|
||||||
|
|
||||||
proc peek*(s: ByteStream): byte {.inline.} =
|
proc peek*(s: ByteStream): byte {.inline.} =
|
||||||
assert s.head != s.bufferEnd
|
doAssert s.head != s.bufferEnd
|
||||||
return s.head[]
|
return s.head[]
|
||||||
|
|
||||||
when debugHelpers:
|
when debugHelpers:
|
||||||
|
|
@ -121,7 +121,7 @@ proc read*(s: var ByteStream): byte =
|
||||||
|
|
||||||
proc checkReadAhead(s: ByteStreamVar, n: int): ptr byte =
|
proc checkReadAhead(s: ByteStreamVar, n: int): ptr byte =
|
||||||
result = s.head
|
result = s.head
|
||||||
assert distance(s.head, s.bufferEnd) >= n
|
doAssert distance(s.head, s.bufferEnd) >= n
|
||||||
s.head = s.head.shift(n)
|
s.head = s.head.shift(n)
|
||||||
|
|
||||||
template readBytes*(s: ByteStreamVar, n: int): auto =
|
template readBytes*(s: ByteStreamVar, n: int): auto =
|
||||||
|
|
@ -133,9 +133,9 @@ proc next*(s: var ByteStream): Option[byte] =
|
||||||
|
|
||||||
proc bufferPos(s: ByteStream, pos: int): ptr byte =
|
proc bufferPos(s: ByteStream, pos: int): ptr byte =
|
||||||
let shiftFromEnd = pos - s.bufferEndPos
|
let shiftFromEnd = pos - s.bufferEndPos
|
||||||
assert shiftFromEnd < 0
|
doAssert shiftFromEnd < 0
|
||||||
result = s.bufferEnd.shift shiftFromEnd
|
result = s.bufferEnd.shift shiftFromEnd
|
||||||
assert result >= s.bufferStart
|
doAssert result >= s.bufferStart
|
||||||
|
|
||||||
proc pos*(s: ByteStream): int {.inline.} =
|
proc pos*(s: ByteStream): int {.inline.} =
|
||||||
s.bufferEndPos - distance(s.head, s.bufferEnd)
|
s.bufferEndPos - distance(s.head, s.bufferEnd)
|
||||||
|
|
@ -148,7 +148,7 @@ proc `[]`*(s: ByteStream, pos: int): byte {.inline.} =
|
||||||
|
|
||||||
proc rewind*(s: var ByteStream, delta: int) =
|
proc rewind*(s: var ByteStream, delta: int) =
|
||||||
s.head = s.head.shift(-delta)
|
s.head = s.head.shift(-delta)
|
||||||
assert s.head >= s.bufferStart
|
doAssert s.head >= s.bufferStart
|
||||||
|
|
||||||
proc rewindTo*(s: var ByteStream, pos: int) {.inline.} =
|
proc rewindTo*(s: var ByteStream, pos: int) {.inline.} =
|
||||||
s.head = s.bufferPos(pos)
|
s.head = s.bufferPos(pos)
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ proc getOutput*(s: OutputStreamVar, T: type string): string =
|
||||||
else:
|
else:
|
||||||
result = newStringOfCap(s.pos)
|
result = newStringOfCap(s.pos)
|
||||||
for page in s.pages:
|
for page in s.pages:
|
||||||
assert page.delayedWrites == 0
|
doAssert page.delayedWrites == 0
|
||||||
result.add page.buffer.toOpenArray(page.startOffset.int,
|
result.add page.buffer.toOpenArray(page.startOffset.int,
|
||||||
page.buffer.len - 1)
|
page.buffer.len - 1)
|
||||||
|
|
||||||
|
|
@ -110,7 +110,7 @@ proc flushDelayedPages*(s: OutputStreamVar) =
|
||||||
# Send to output
|
# Send to output
|
||||||
|
|
||||||
proc delayFixedSizeWrite*(s: OutputStreamVar, size: int): DelayedWriteCursor =
|
proc delayFixedSizeWrite*(s: OutputStreamVar, size: int): DelayedWriteCursor =
|
||||||
assert size < pageSize
|
doAssert size < pageSize
|
||||||
|
|
||||||
let remainingBytesInPage = distance(s.head, s.bufferEnd)
|
let remainingBytesInPage = distance(s.head, s.bufferEnd)
|
||||||
if size > remainingBytesInPage:
|
if size > remainingBytesInPage:
|
||||||
|
|
@ -132,7 +132,7 @@ proc delayVarSizeWrite*(s: OutputStreamVar, maxSize: int): DelayedWriteCursor =
|
||||||
|
|
||||||
proc decRef(x: var int16): int16 =
|
proc decRef(x: var int16): int16 =
|
||||||
result = x - 1
|
result = x - 1
|
||||||
assert result >= 0
|
doAssert result >= 0
|
||||||
x = result
|
x = result
|
||||||
|
|
||||||
proc endWrite*(cursor: DelayedWriteCursor, data: openarray[byte]) =
|
proc endWrite*(cursor: DelayedWriteCursor, data: openarray[byte]) =
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import
|
||||||
../faststreams
|
../faststreams
|
||||||
|
|
||||||
suite "input stream":
|
suite "input stream":
|
||||||
test "string output":
|
test "string input":
|
||||||
var input = repeat("1234 5678 90AB CDEF\n", 1000)
|
var input = repeat("1234 5678 90AB CDEF\n", 1000)
|
||||||
var stream = memoryStream(input)
|
var stream = memoryStream(input)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,5 +17,6 @@ suite "output stream":
|
||||||
altOutput.add '\n'
|
altOutput.add '\n'
|
||||||
|
|
||||||
let streamOutput = s.getOutput
|
let streamOutput = s.getOutput
|
||||||
check streamOutput == altOutput
|
# without the cast, in nim-0.19.0: "Error: type mismatch: got <seq[byte], string>" (for the `==` proc)
|
||||||
|
check cast[string](streamOutput) == altOutput
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue