assert() -> doAssert()

Also fixed a test and added the other to the Nimble task.
This commit is contained in:
Ștefan Talpalaru 2019-03-14 04:19:41 +01:00
commit acd5a6063c
No known key found for this signature in database
GPG key ID: CBF7934204F1B6F9
6 changed files with 18 additions and 13 deletions

1
.gitignore vendored
View file

@ -1,2 +1 @@
/tests/test_output_stream

View file

@ -11,6 +11,11 @@ requires "nim >= 0.17.0",
"ranges",
"std_shims"
task test, "run tests":
exec "nim c -r tests/test_output_stream.nim"
import ospaths, strutils
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]

View file

@ -101,7 +101,7 @@ proc eob*(s: ByteStream): bool {.inline.} =
s.head != s.bufferEnd
proc peek*(s: ByteStream): byte {.inline.} =
assert s.head != s.bufferEnd
doAssert s.head != s.bufferEnd
return s.head[]
when debugHelpers:
@ -121,7 +121,7 @@ proc read*(s: var ByteStream): byte =
proc checkReadAhead(s: ByteStreamVar, n: int): ptr byte =
result = s.head
assert distance(s.head, s.bufferEnd) >= n
doAssert distance(s.head, s.bufferEnd) >= n
s.head = s.head.shift(n)
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 =
let shiftFromEnd = pos - s.bufferEndPos
assert shiftFromEnd < 0
doAssert shiftFromEnd < 0
result = s.bufferEnd.shift shiftFromEnd
assert result >= s.bufferStart
doAssert result >= s.bufferStart
proc pos*(s: ByteStream): int {.inline.} =
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) =
s.head = s.head.shift(-delta)
assert s.head >= s.bufferStart
doAssert s.head >= s.bufferStart
proc rewindTo*(s: var ByteStream, pos: int) {.inline.} =
s.head = s.bufferPos(pos)

View file

@ -91,7 +91,7 @@ proc getOutput*(s: OutputStreamVar, T: type string): string =
else:
result = newStringOfCap(s.pos)
for page in s.pages:
assert page.delayedWrites == 0
doAssert page.delayedWrites == 0
result.add page.buffer.toOpenArray(page.startOffset.int,
page.buffer.len - 1)
@ -110,7 +110,7 @@ proc flushDelayedPages*(s: OutputStreamVar) =
# Send to output
proc delayFixedSizeWrite*(s: OutputStreamVar, size: int): DelayedWriteCursor =
assert size < pageSize
doAssert size < pageSize
let remainingBytesInPage = distance(s.head, s.bufferEnd)
if size > remainingBytesInPage:
@ -132,7 +132,7 @@ proc delayVarSizeWrite*(s: OutputStreamVar, maxSize: int): DelayedWriteCursor =
proc decRef(x: var int16): int16 =
result = x - 1
assert result >= 0
doAssert result >= 0
x = result
proc endWrite*(cursor: DelayedWriteCursor, data: openarray[byte]) =

View file

@ -3,7 +3,7 @@ import
../faststreams
suite "input stream":
test "string output":
test "string input":
var input = repeat("1234 5678 90AB CDEF\n", 1000)
var stream = memoryStream(input)

View file

@ -17,5 +17,6 @@ suite "output stream":
altOutput.add '\n'
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