diff --git a/.gitignore b/.gitignore index 5d49397..8b13789 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ -/tests/test_output_stream diff --git a/faststreams.nimble b/faststreams.nimble index f470a6c..0f744ad 100644 --- a/faststreams.nimble +++ b/faststreams.nimble @@ -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] diff --git a/faststreams/input_stream.nim b/faststreams/input_stream.nim index f7753dd..ae7f1b3 100644 --- a/faststreams/input_stream.nim +++ b/faststreams/input_stream.nim @@ -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) diff --git a/faststreams/output_stream.nim b/faststreams/output_stream.nim index ff06991..45777ff 100644 --- a/faststreams/output_stream.nim +++ b/faststreams/output_stream.nim @@ -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]) = diff --git a/tests/test_input_stream.nim b/tests/test_input_stream.nim index 922ab06..31ea12c 100644 --- a/tests/test_input_stream.nim +++ b/tests/test_input_stream.nim @@ -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) diff --git a/tests/test_output_stream.nim b/tests/test_output_stream.nim index 0d5cc62..228c549 100644 --- a/tests/test_output_stream.nim +++ b/tests/test_output_stream.nim @@ -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 " (for the `==` proc) + check cast[string](streamOutput) == altOutput