From 367cb55eefda58f78eec4a5ccbd295e83f1a914b Mon Sep 17 00:00:00 2001 From: andri lim Date: Thu, 18 Feb 2021 22:56:17 +0700 Subject: [PATCH] fix memFileInput.pos return negative value (#16) --- faststreams/inputs.nim | 1 + tests/test_inputs.nim | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/faststreams/inputs.nim b/faststreams/inputs.nim index c9024ff..92257fa 100644 --- a/faststreams/inputs.nim +++ b/faststreams/inputs.nim @@ -205,6 +205,7 @@ proc memFileInput*(filename: string, mappedSize = -1, offset = 0): InputStreamHa span: PageSpan( startAddr: head, endAddr: offset(head, mappedSize)), + spanEndPos: mappedSize, file: memFile) except OSError as err: raise newException(IOError, err.msg, err) diff --git a/tests/test_inputs.nim b/tests/test_inputs.nim index 3bfa3a7..b08d04b 100644 --- a/tests/test_inputs.nim +++ b/tests/test_inputs.nim @@ -164,3 +164,21 @@ procSuite "input stream": check: (stream.read(4) == "1234".toOpenArrayByte(0, 3)) + template posTest(name: string, setup: untyped) = + test name: + setup + check input.readable + check input.pos == 0 + discard input.read + check input.pos == 1 + close input + + posTest "unsafeMemoryInput pos": + var str = "hello" + var input = unsafeMemoryInput(str) + + posTest "fileInput pos": + var input = fileInput(asciiTableFile) + + posTest "memFileInput pos": + var input = memFileInput(asciiTableFile)