mirror of
https://github.com/logos-storage/nim-chronos.git
synced 2026-01-07 16:03:09 +00:00
Add hexValue tests.
This commit is contained in:
parent
4e9a857b90
commit
25688cd0aa
@ -36,7 +36,7 @@ proc LT(x, y: uint32): uint32 {.inline.} =
|
|||||||
let z = x - y
|
let z = x - y
|
||||||
(z xor ((y xor x) and (y xor z))) shr 31
|
(z xor ((y xor x) and (y xor z))) shr 31
|
||||||
|
|
||||||
proc hexValue(c: byte): int =
|
proc hexValue*(c: byte): int =
|
||||||
# This is nim adaptation of
|
# This is nim adaptation of
|
||||||
# https://github.com/pornin/CTTK/blob/master/src/hex.c#L28-L52
|
# https://github.com/pornin/CTTK/blob/master/src/hex.c#L28-L52
|
||||||
let x = uint32(c) - 0x30'u32
|
let x = uint32(c) - 0x30'u32
|
||||||
|
|||||||
@ -629,6 +629,19 @@ suite "ChunkedStream test suite":
|
|||||||
result = res
|
result = res
|
||||||
check waitFor(testVectors2(initTAddress("127.0.0.1:46001"))) == true
|
check waitFor(testVectors2(initTAddress("127.0.0.1:46001"))) == true
|
||||||
|
|
||||||
|
test "ChunkedStream hex decoding test":
|
||||||
|
for i in 0 ..< 256:
|
||||||
|
let ch = char(i)
|
||||||
|
case ch
|
||||||
|
of '0' .. '9':
|
||||||
|
check hexValue(byte(ch)) == ord(ch) - ord('0')
|
||||||
|
of 'a' .. 'f':
|
||||||
|
check hexValue(byte(ch)) == ord(ch) - ord('a') + 10
|
||||||
|
of 'A' .. 'F':
|
||||||
|
check hexValue(byte(ch)) == ord(ch) - ord('A') + 10
|
||||||
|
else:
|
||||||
|
check hexValue(byte(ch)) == -1
|
||||||
|
|
||||||
test "ChunkedStream leaks test":
|
test "ChunkedStream leaks test":
|
||||||
check:
|
check:
|
||||||
getTracker("async.stream.reader").isLeaked() == false
|
getTracker("async.stream.reader").isLeaked() == false
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user