diff options
author | flywind <43030857+xflywind@users.noreply.github.com> | 2021-01-11 08:13:13 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-11 15:13:13 +0100 |
commit | 0c128259bb01cde8ed27430929b0a01c5ee7b88c (patch) | |
tree | c1018564f52d6fdf3bfb9bf1da2ee70532705942 | |
parent | aa185c0e9b4904b305496bd1f83cbbadf2fbfa36 (diff) | |
download | Nim-0c128259bb01cde8ed27430929b0a01c5ee7b88c.tar.gz |
close #7097 add testcase (#16682)
-rw-r--r-- | tests/converter/t7097.nim | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/converter/t7097.nim b/tests/converter/t7097.nim new file mode 100644 index 000000000..fdb573588 --- /dev/null +++ b/tests/converter/t7097.nim @@ -0,0 +1,38 @@ +type + Byte* = uint8 + Bytes* = seq[Byte] + + BytesRange* = object + bytes: Bytes + ibegin, iend: int + +proc initBytesRange*(s: var Bytes, ibegin = 0, iend = -1): BytesRange = + let e = if iend < 0: s.len + iend + 1 + else: iend + assert ibegin > 0 and e <= s.len + + shallow(s) + result.bytes = s + result.ibegin = ibegin + result.iend = e + +template `[]=`*(r: var BytesRange, i: int, v: Byte) = + r.bytes[r.ibegin + i] = v + +converter fromSeq*(s: Bytes): BytesRange = + var seqCopy = s + return initBytesRange(seqCopy) + +type + Reader* = object + data: BytesRange + position: int + +proc readerFromHex*(input: string): Reader = + let totalBytes = input.len div 2 + var backingStore = newSeq[Byte](totalBytes) + result.data = initBytesRange(backingStore) + + for i in 0 ..< totalBytes: + var nextByte = 0 + result.data[i] = Byte(nextByte) # <-------- instantiated from here |