mirror of
https://github.com/status-im/nim-stint.git
synced 2025-02-21 11:28:23 +00:00
improve io test coverage + compile time test
This commit is contained in:
parent
523b74d0d2
commit
0cd6b2a052
60
stint/io.nim
60
stint/io.nim
@ -47,6 +47,9 @@ func stint*[T: SomeInteger](n: T, bits: static[int]): StInt[bits] {.inline.}=
|
||||
static_check_size(T, bits)
|
||||
when T is SomeSignedInt:
|
||||
if n < 0:
|
||||
# TODO: when bits >= 128, cannot create from
|
||||
# low(int8-64)
|
||||
# see: status-im/nim-stint/issues/92
|
||||
assignLo(result.data, -n)
|
||||
result = -result
|
||||
else:
|
||||
@ -71,19 +74,8 @@ func truncate*(num: Stint or StUint, T: typedesc[SomeInteger]): T {.inline.}=
|
||||
doAssert bitsof(T) <= bitsof(num.data.leastSignificantWord)
|
||||
|
||||
when nimvm:
|
||||
const bits = bitsof(T)
|
||||
let data = num.data.leastSignificantWord
|
||||
type DT = type data
|
||||
|
||||
# we use esoteric type juggling here to trick the Nim VM
|
||||
when bits == 64:
|
||||
cast[T](uint64(data and 0xFFFFFFFF_FFFFFFFF.DT))
|
||||
elif bits == 32:
|
||||
cast[T](uint32(data and 0xFFFFFFFF.DT))
|
||||
elif bits == 16:
|
||||
cast[T](uint16(data and 0xFFFF.DT))
|
||||
else:
|
||||
cast[T](uint8(data and 0xFF.DT))
|
||||
vmIntCast[T](data)
|
||||
else:
|
||||
cast[T](num.data.leastSignificantWord)
|
||||
|
||||
@ -187,9 +179,9 @@ func parse*[bits: static[int]](input: string, T: typedesc[Stint[bits]], radix: s
|
||||
|
||||
# TODO: we can't create the lowest int this way
|
||||
if isNeg:
|
||||
result = -cast[Stint[bits]](no_overflow)
|
||||
result = -convert[T](no_overflow)
|
||||
else:
|
||||
result = cast[Stint[bits]](no_overflow)
|
||||
result = convert[T](no_overflow)
|
||||
|
||||
func fromHex*(T: type StUint, s: string): T {.inline.} =
|
||||
## Convert an hex string to the corresponding unsigned integer
|
||||
@ -215,6 +207,9 @@ func toString*[bits: static[int]](num: StUint[bits], radix: static[uint8] = 10):
|
||||
var (q, r) = divmod(num, base)
|
||||
|
||||
while true:
|
||||
when bitsof(r.data) <= 64:
|
||||
result.add hexChars[r.data.int]
|
||||
else:
|
||||
result.add hexChars[r.truncate(int)]
|
||||
if q.isZero:
|
||||
break
|
||||
@ -232,23 +227,27 @@ func toString*[bits: static[int]](num: Stint[bits], radix: static[int8] = 10): s
|
||||
# TODO: use static[range[2 .. 16]], not supported at the moment (2018-04-26)
|
||||
|
||||
const hexChars = "0123456789abcdef"
|
||||
const base = radix.int8.stint(bits)
|
||||
const base = radix.int8.stuint(bits)
|
||||
|
||||
result = ""
|
||||
|
||||
type T = Stuint[bits]
|
||||
let isNeg = num.isNegative
|
||||
let num = if radix == 10 and isNeg: -num
|
||||
else: num
|
||||
let num = convert[T](if radix == 10 and isNeg: -num
|
||||
else: num)
|
||||
|
||||
var (q, r) = divmod(num, base)
|
||||
|
||||
while true:
|
||||
when bitsof(r.data) <= 64:
|
||||
result.add hexChars[r.data.int]
|
||||
else:
|
||||
result.add hexChars[r.truncate(int)]
|
||||
if q.isZero:
|
||||
break
|
||||
(q, r) = divmod(q, base)
|
||||
|
||||
if isNeg:
|
||||
if isNeg and radix == 10:
|
||||
result.add '-'
|
||||
|
||||
reverse(result)
|
||||
@ -318,7 +317,23 @@ proc initFromBytesBE*[bits: static[int]](val: var Stuint[bits], ba: openarray[by
|
||||
doAssert(ba.len == N)
|
||||
else:
|
||||
doAssert ba.len <= N
|
||||
when system.cpuEndian == bigEndian:
|
||||
let baseIdx = N - val.len
|
||||
else:
|
||||
let baseIdx = ba.len - 1
|
||||
|
||||
when nimvm:
|
||||
when system.cpuEndian == bigEndian:
|
||||
when allowPadding:
|
||||
for i, b in ba: val.data.setByte(baseIdx + i, b)
|
||||
else:
|
||||
for i, b in ba: val.data.setByte(i, b)
|
||||
else:
|
||||
when allowPadding:
|
||||
for i, b in ba: val.data.setByte(baseIdx - i, b)
|
||||
else:
|
||||
for i, b in ba: val.data.setByte(N-1 - i, b)
|
||||
else:
|
||||
{.pragma: restrict, codegenDecl: "$# __restrict $#".}
|
||||
let r_ptr {.restrict.} = cast[ptr array[N, byte]](val.addr)
|
||||
|
||||
@ -326,13 +341,11 @@ proc initFromBytesBE*[bits: static[int]](val: var Stuint[bits], ba: openarray[by
|
||||
# TODO: due to https://github.com/status-im/nim-stint/issues/38
|
||||
# We can't cast a stack byte array to stuint with a convenient proc signature.
|
||||
when allowPadding:
|
||||
let baseIdx = N - val.len
|
||||
for i, b in ba: r_ptr[baseIdx + i] = b
|
||||
else:
|
||||
for i, b in ba: r_ptr[i] = b
|
||||
else:
|
||||
when allowPadding:
|
||||
let baseIdx = ba.len - 1
|
||||
for i, b in ba: r_ptr[baseIdx - i] = b
|
||||
else:
|
||||
for i, b in ba: r_ptr[N-1 - i] = b
|
||||
@ -370,6 +383,13 @@ func toByteArrayBE*[bits: static[int]](n: StUint[bits]): array[bits div 8, byte]
|
||||
|
||||
const N = bits div 8
|
||||
|
||||
when nimvm:
|
||||
for i in 0 ..< N:
|
||||
when system.cpuEndian == bigEndian:
|
||||
result[i] = n.data.getByte(i)
|
||||
else:
|
||||
result[i] = n.data.getByte(N - 1 - i)
|
||||
else:
|
||||
when system.cpuEndian == bigEndian:
|
||||
result = cast[type result](n)
|
||||
else:
|
||||
|
@ -7,7 +7,10 @@ func convertImpl[T: IntImpl|UintImpl](x: IntImpl|UintImpl): T {.compileTime.} =
|
||||
result.hi = convertImpl[type(result.hi)](x.hi)
|
||||
result.lo = x.lo
|
||||
|
||||
template convert*[T](x: UintImpl|IntImpl|SomeInteger): T =
|
||||
func convertImpl[T: Stuint|Stint](x: StUint|StInt): T {.compileTime.} =
|
||||
result.data = convertImpl[type(result.data)](x.data)
|
||||
|
||||
template convert*[T](x: Stuint|Stint|UintImpl|IntImpl|SomeInteger): T =
|
||||
when nimvm:
|
||||
# this is a workaround Nim VM inability to cast
|
||||
# something non integer
|
||||
@ -17,10 +20,16 @@ template convert*[T](x: UintImpl|IntImpl|SomeInteger): T =
|
||||
|
||||
func getByte*(x: SomeInteger, pos: int): byte {.compileTime.} =
|
||||
type DT = type x
|
||||
when bitsof(DT) == 8:
|
||||
cast[byte](x)
|
||||
else:
|
||||
byte((x shr (pos * 8)) and 0xFF.DT)
|
||||
|
||||
func getByte*(x: UintImpl | IntImpl, pos: int): byte {.compileTime.} =
|
||||
type DT = type x.leastSignificantWord
|
||||
when bitsof(DT) == 8:
|
||||
cast[byte](x.leastSignificantWord)
|
||||
else:
|
||||
byte((x shr (pos * 8)).leastSignificantWord and 0xFF.DT)
|
||||
|
||||
proc setByte*(x: var SomeInteger, pos: int, b: byte) {.compileTime.} =
|
||||
@ -57,3 +66,31 @@ func copyFromArray*(x: var SomeInteger, data: openArray[byte]) {.compileTime.} =
|
||||
doAssert data.len >= size
|
||||
for i in 0 ..< size:
|
||||
x.setByte(i, data[i])
|
||||
|
||||
template vmIntCast*[T](data: SomeInteger): T =
|
||||
type DT = type data
|
||||
const
|
||||
bits = bitsof(T)
|
||||
DTbits = bitsof(DT)
|
||||
|
||||
# we use esoteric type juggling here to trick the Nim VM
|
||||
when bits == 64:
|
||||
when DTbits == 64:
|
||||
cast[T](data)
|
||||
else:
|
||||
cast[T](uint64(data and DT(0xFFFFFFFF_FFFFFFFF)))
|
||||
elif bits == 32:
|
||||
when DTbits == 32:
|
||||
cast[T](data)
|
||||
else:
|
||||
cast[T](uint32(data and DT(0xFFFFFFFF)))
|
||||
elif bits == 16:
|
||||
when DTbits == 16:
|
||||
cast[T](data)
|
||||
else:
|
||||
cast[T](uint16(data and DT(0xFFFF)))
|
||||
else:
|
||||
when DTBits == 8:
|
||||
cast[T](data)
|
||||
else:
|
||||
cast[T](uint8(data and DT(0xFF)))
|
||||
|
@ -7,7 +7,7 @@
|
||||
#
|
||||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||
|
||||
import ./datatypes, ./int_negabs, ./uint_div, ./int_comparison
|
||||
import ./datatypes, ./int_negabs, ./uint_div, ./int_comparison, ./compiletime_helpers
|
||||
|
||||
# Here are the expected signs for division/modulo by opposite signs and both negative numbers
|
||||
# in EVM
|
||||
@ -39,6 +39,13 @@ func divmod*(x, y: SomeSignedInt): tuple[quot, rem: SomeSignedInt] {.inline.}=
|
||||
proc divmod*[T, T2](x, y: IntImpl[T, T2]): tuple[quot, rem: IntImpl[T, T2]] =
|
||||
## Divmod operation for multi-precision signed integer
|
||||
|
||||
when nimvm:
|
||||
let res = divmod(
|
||||
convert[UintImpl[T2]](x.abs),
|
||||
convert[UintImpl[T2]](y.abs))
|
||||
result.quot = convert[type result.quot](res.quot)
|
||||
result.rem = convert[type result.rem](res.rem)
|
||||
else:
|
||||
result = cast[type result](divmod(
|
||||
cast[UintImpl[T2]](x.abs),
|
||||
cast[UintImpl[T2]](y.abs)
|
||||
|
@ -0,0 +1,5 @@
|
||||
import ../stint, unittest
|
||||
|
||||
suite "int boundchecks":
|
||||
test "to be implemented":
|
||||
discard
|
@ -9,7 +9,985 @@
|
||||
|
||||
import ../stint, unittest, strutils, math
|
||||
|
||||
suite "Testing input and output procedures":
|
||||
template nativeStuint(chk, nint: untyped, bits: int) =
|
||||
chk $(nint.stuint(bits)) == $(nint)
|
||||
|
||||
template nativeStint(chk, nint: untyped, bits: int) =
|
||||
chk $(nint.stint(bits)) == $(nint)
|
||||
|
||||
template chkTruncateStuint(chk, number, toType: untyped, bits: int) =
|
||||
chk (number.stuint(bits)).truncate(toType) == toType(number)
|
||||
|
||||
template chkTruncateStint(chk, number, toType: untyped, bits: int) =
|
||||
chk (number.stint(bits)).truncate(toType) == toType(number)
|
||||
|
||||
template chkTruncateStint(chk, number, toType: untyped, res: string, bits: int) =
|
||||
block:
|
||||
let x = (number.stint(bits)).truncate(toType).toHex()
|
||||
chk "0x" & x == res
|
||||
|
||||
template chkRoundtripStuint(chk: untyped, prefix, str: string, bits, radix: int) =
|
||||
block:
|
||||
let data = prefix & str
|
||||
let x = parse(data, Stuint[bits], radix)
|
||||
let y = x.toString(radix)
|
||||
chk y == str
|
||||
|
||||
template chkRoundtripStuint(chk: untyped, str: string, bits, radix: int) =
|
||||
chkRoundtripStuint(chk, "", str, bits, radix)
|
||||
|
||||
template chkRoundtripStint(chk: untyped, prefix, str: string, bits, radix: int) =
|
||||
block:
|
||||
let data = prefix & str
|
||||
let x = parse(data, Stint[bits], radix)
|
||||
let y = x.toString(radix)
|
||||
chk y == str
|
||||
|
||||
template chkRoundtripStint(chk: untyped, str: string, bits, radix: int) =
|
||||
chkRoundtripStint(chk, "", str, bits, radix)
|
||||
|
||||
template chkRoundtripBin(chk, chkProc: untyped, bits, rep: int) =
|
||||
chkProc(chk, "0", bits, 2)
|
||||
chkProc(chk, repeat("1", rep), bits, 2)
|
||||
chkProc(chk, repeat("1010", rep), bits, 2)
|
||||
chkProc(chk, repeat("1111", rep), bits, 2)
|
||||
chkProc(chk, repeat("11110000", rep), bits, 2)
|
||||
chkProc(chk, repeat("10101010", rep), bits, 2)
|
||||
chkProc(chk, repeat("1010101", rep), bits, 2)
|
||||
chkProc(chk, repeat("11111111", rep), bits, 2)
|
||||
|
||||
template chkRoundtripHex(chk, chkProc: untyped, bits, rep: int) =
|
||||
chkProc(chk, "0", bits, 16)
|
||||
chkProc(chk, repeat("1", rep), bits, 16)
|
||||
chkProc(chk, repeat("7", rep), bits, 16)
|
||||
chkProc(chk, repeat("f", rep), bits, 16)
|
||||
chkProc(chk, repeat("aa", rep), bits, 16)
|
||||
chkProc(chk, repeat("ff", rep), bits, 16)
|
||||
chkProc(chk, repeat("f0", rep), bits, 16)
|
||||
|
||||
template chkRoundtripOct(chk, chkProc: untyped, bits, rep: int) =
|
||||
chkProc(chk, "0", bits, 8)
|
||||
chkProc(chk, repeat("1", rep), bits, 8)
|
||||
chkProc(chk, repeat("7", rep), bits, 8)
|
||||
chkProc(chk, repeat("177", rep), bits, 8)
|
||||
|
||||
template chkRoundtripDec(chk, chkProc: untyped, bits, rep: int) =
|
||||
chkProc(chk, "0", bits, 10)
|
||||
chkProc(chk, repeat("1", rep), bits, 10)
|
||||
chkProc(chk, repeat("9", rep), bits, 10)
|
||||
|
||||
func toByteArray(x: static[string]): auto {.compileTime.} =
|
||||
var ret: array[x.len, byte]
|
||||
for i, b in x: ret[i] = byte(b)
|
||||
ret
|
||||
|
||||
template chkRoundtripBE(chk: untyped, str: string, bits: int) =
|
||||
block:
|
||||
const data = toByteArray(str)
|
||||
var x: Stuint[bits]
|
||||
initFromBytesBE(x, data)
|
||||
let y = toByteArrayBE(x)
|
||||
chk y == data
|
||||
|
||||
template chkCTvsRT(chk: untyped, num: untyped, bits: int) =
|
||||
block:
|
||||
let x = stuint(num, bits)
|
||||
let y = toByteArrayBE(x)
|
||||
const xx = stuint(num, bits)
|
||||
const yy = toByteArrayBE(xx)
|
||||
chk y == yy
|
||||
|
||||
template chkDumpHex(chk: untyped, BE, LE: string, bits: int) =
|
||||
block:
|
||||
let data = BE
|
||||
let x = fromHex(Stuint[bits], data)
|
||||
chk dumpHex(x, bigEndian) == data
|
||||
chk dumpHex(x, littleEndian) == LE
|
||||
|
||||
template ctTest(name: string, body: untyped) =
|
||||
body
|
||||
echo "[OK] compile time ", name
|
||||
|
||||
template testIO(chk, tst: untyped) =
|
||||
tst "[stuint] Creation from native ints":
|
||||
nativeStuint(chk, 0, 8)
|
||||
nativeStuint(chk, 0'u8, 8)
|
||||
nativeStuint(chk, 0xFF'u16, 8)
|
||||
nativeStuint(chk, 0xFF'u32, 8)
|
||||
nativeStuint(chk, 0xFF'u64, 8)
|
||||
nativeStuint(chk, 0'i8, 8)
|
||||
nativeStuint(chk, 0xFF'i16, 8)
|
||||
nativeStuint(chk, 0xFF'i32, 8)
|
||||
nativeStuint(chk, 0xFF'i64, 8)
|
||||
nativeStuint(chk, high(uint8), 8)
|
||||
nativeStuint(chk, low(uint8), 8)
|
||||
nativeStuint(chk, high(int8), 8)
|
||||
|
||||
nativeStuint(chk, 0, 16)
|
||||
nativeStuint(chk, 0'u8, 16)
|
||||
nativeStuint(chk, 0xFFFF'u32, 16)
|
||||
nativeStuint(chk, 0xFFFF'u64, 16)
|
||||
nativeStuint(chk, 0xFFFF'i32, 16)
|
||||
nativeStuint(chk, 0xFFFF'i64, 16)
|
||||
nativeStuint(chk, high(uint8), 16)
|
||||
nativeStuint(chk, low(uint8), 16)
|
||||
nativeStuint(chk, high(int8), 16)
|
||||
nativeStuint(chk, 0'u16, 16)
|
||||
nativeStuint(chk, high(uint16), 16)
|
||||
nativeStuint(chk, low(uint16), 16)
|
||||
nativeStuint(chk, high(int16), 16)
|
||||
|
||||
nativeStuint(chk, 0, 32)
|
||||
nativeStuint(chk, 0'u8, 32)
|
||||
nativeStuint(chk, 0xFFFFFFFF'u64, 32)
|
||||
nativeStuint(chk, 0xFFFFFFFF'i64, 32)
|
||||
nativeStuint(chk, high(uint8), 32)
|
||||
nativeStuint(chk, low(uint8), 32)
|
||||
nativeStuint(chk, high(int8), 32)
|
||||
nativeStuint(chk, 0'u16, 32)
|
||||
nativeStuint(chk, high(uint16), 32)
|
||||
nativeStuint(chk, low(uint16), 32)
|
||||
nativeStuint(chk, high(int16), 32)
|
||||
nativeStuint(chk, 0'u32, 32)
|
||||
nativeStuint(chk, high(uint32), 32)
|
||||
nativeStuint(chk, low(uint32), 32)
|
||||
nativeStuint(chk, high(int32), 32)
|
||||
|
||||
nativeStuint(chk, 0, 64)
|
||||
nativeStuint(chk, 0'u8, 64)
|
||||
nativeStuint(chk, high(uint8), 64)
|
||||
nativeStuint(chk, low(uint8), 64)
|
||||
nativeStuint(chk, high(int8), 64)
|
||||
nativeStuint(chk, 0'u16, 64)
|
||||
nativeStuint(chk, high(uint16), 64)
|
||||
nativeStuint(chk, low(uint16), 64)
|
||||
nativeStuint(chk, high(int16), 64)
|
||||
nativeStuint(chk, 0'u32, 64)
|
||||
nativeStuint(chk, high(uint32), 64)
|
||||
nativeStuint(chk, low(uint32), 64)
|
||||
nativeStuint(chk, high(int32), 64)
|
||||
nativeStuint(chk, 0'u64, 64)
|
||||
when (NimMajor, NimMinor, NimPatch) >= (1, 0, 0):
|
||||
nativeStuint(chk, high(uint64), 64)
|
||||
nativeStuint(chk, low(uint64), 64)
|
||||
nativeStuint(chk, high(int64), 64)
|
||||
|
||||
when sizeof(uint) == 4:
|
||||
nativeStuint(chk, high(uint), 32)
|
||||
nativeStuint(chk, low(uint), 32)
|
||||
nativeStuint(chk, high(int), 32)
|
||||
else:
|
||||
when (NimMajor, NimMinor, NimPatch) >= (1, 0, 0):
|
||||
nativeStuint(chk, high(uint), 64)
|
||||
nativeStuint(chk, low(uint), 64)
|
||||
nativeStuint(chk, high(int), 64)
|
||||
|
||||
nativeStuint(chk, 0, 128)
|
||||
nativeStuint(chk, 0'u8, 128)
|
||||
nativeStuint(chk, high(uint8), 128)
|
||||
nativeStuint(chk, low(uint8), 128)
|
||||
nativeStuint(chk, high(int8), 128)
|
||||
nativeStuint(chk, 0'u16, 128)
|
||||
nativeStuint(chk, high(uint16), 128)
|
||||
nativeStuint(chk, low(uint16), 128)
|
||||
nativeStuint(chk, high(int16), 128)
|
||||
nativeStuint(chk, 0'u32, 128)
|
||||
nativeStuint(chk, high(uint32), 128)
|
||||
nativeStuint(chk, low(uint32), 128)
|
||||
nativeStuint(chk, high(int32), 128)
|
||||
nativeStuint(chk, 0'u64, 128)
|
||||
when (NimMajor, NimMinor, NimPatch) >= (1, 0, 0):
|
||||
nativeStuint(chk, high(uint64), 128)
|
||||
nativeStuint(chk, low(uint64), 128)
|
||||
nativeStuint(chk, high(int64), 128)
|
||||
|
||||
tst "[stint] Creation from native ints":
|
||||
nativeStint(chk, 0, 8)
|
||||
nativeStint(chk, 0'u8, 8)
|
||||
nativeStint(chk, high(int8), 8)
|
||||
nativeStint(chk, low(int8), 8)
|
||||
nativeStint(chk, low(uint8), 8)
|
||||
|
||||
nativeStint(chk, 0, 16)
|
||||
nativeStint(chk, 0'u8, 16)
|
||||
nativeStint(chk, high(int8), 16)
|
||||
nativeStint(chk, low(int8), 16)
|
||||
nativeStint(chk, low(uint8), 16)
|
||||
nativeStint(chk, 0'u16, 16)
|
||||
nativeStint(chk, high(int16), 16)
|
||||
nativeStint(chk, low(int16), 16)
|
||||
nativeStint(chk, low(uint16), 16)
|
||||
|
||||
nativeStint(chk, 0, 32)
|
||||
nativeStint(chk, 0'u8, 32)
|
||||
nativeStint(chk, high(int8), 32)
|
||||
nativeStint(chk, low(int8), 32)
|
||||
nativeStint(chk, low(uint8), 32)
|
||||
nativeStint(chk, 0'u16, 32)
|
||||
nativeStint(chk, high(int16), 32)
|
||||
nativeStint(chk, low(int16), 32)
|
||||
nativeStint(chk, low(uint16), 32)
|
||||
nativeStint(chk, 0'u32, 32)
|
||||
nativeStint(chk, high(int32), 32)
|
||||
nativeStint(chk, low(int32), 32)
|
||||
nativeStint(chk, low(uint32), 32)
|
||||
|
||||
nativeStint(chk, 0, 64)
|
||||
nativeStint(chk, 0'u8, 64)
|
||||
nativeStint(chk, high(int8), 64)
|
||||
nativeStint(chk, low(int8), 64)
|
||||
nativeStint(chk, low(uint8), 64)
|
||||
nativeStint(chk, 0'u16, 64)
|
||||
nativeStint(chk, high(int16), 64)
|
||||
nativeStint(chk, low(int16), 64)
|
||||
nativeStint(chk, low(uint16), 64)
|
||||
nativeStint(chk, 0'u32, 64)
|
||||
nativeStint(chk, high(int32), 64)
|
||||
nativeStint(chk, low(int32), 64)
|
||||
nativeStint(chk, low(uint32), 64)
|
||||
nativeStint(chk, 0'u64, 64)
|
||||
nativeStint(chk, high(int64), 64)
|
||||
nativeStint(chk, low(int64), 64)
|
||||
when (NimMajor, NimMinor, NimPatch) >= (1, 0, 0):
|
||||
nativeStint(chk, low(uint64), 64)
|
||||
|
||||
when sizeof(uint) == 4:
|
||||
nativeStint(chk, high(int), 32)
|
||||
nativeStint(chk, low(int), 32)
|
||||
nativeStint(chk, low(uint), 32)
|
||||
else:
|
||||
nativeStint(chk, high(int), 64)
|
||||
nativeStint(chk, low(int), 64)
|
||||
when (NimMajor, NimMinor, NimPatch) >= (1, 0, 0):
|
||||
nativeStint(chk, low(uint), 64)
|
||||
|
||||
nativeStint(chk, 0, 128)
|
||||
nativeStint(chk, 0'u8, 128)
|
||||
nativeStint(chk, high(int8), 128)
|
||||
nativeStint(chk, low(uint8), 128)
|
||||
nativeStint(chk, 0'u16, 128)
|
||||
nativeStint(chk, high(int16), 128)
|
||||
nativeStint(chk, low(uint16), 128)
|
||||
nativeStint(chk, 0'u32, 128)
|
||||
nativeStint(chk, high(int32), 128)
|
||||
nativeStint(chk, low(uint32), 128)
|
||||
nativeStint(chk, 0'u64, 128)
|
||||
nativeStint(chk, high(int64), 128)
|
||||
when (NimMajor, NimMinor, NimPatch) >= (1, 0, 0):
|
||||
nativeStint(chk, low(uint64), 128)
|
||||
|
||||
# TODO: bug #92
|
||||
#nativeStint(chk, low(int8), 128)
|
||||
#nativeStint(chk, low(int16), 128)
|
||||
#nativeStint(chk, low(int32), 128)
|
||||
#nativeStint(chk, low(int64), 128)
|
||||
|
||||
tst "[stuint] truncate":
|
||||
chkTruncateStuint(chk, low(uint8), uint8, 8)
|
||||
chkTruncateStuint(chk, high(uint8), uint8, 8)
|
||||
chkTruncateStuint(chk, high(int8), uint8, 8)
|
||||
chkTruncateStuint(chk, high(int8), int8, 8)
|
||||
|
||||
chkTruncateStuint(chk, low(uint8), uint8, 16)
|
||||
chkTruncateStuint(chk, high(uint8), uint8, 16)
|
||||
chkTruncateStuint(chk, high(int8), uint8, 16)
|
||||
chkTruncateStuint(chk, high(int8), int8, 16)
|
||||
|
||||
chkTruncateStuint(chk, low(uint8), uint16, 16)
|
||||
chkTruncateStuint(chk, high(uint8), uint16, 16)
|
||||
chkTruncateStuint(chk, high(int8), uint16, 16)
|
||||
chkTruncateStuint(chk, high(int8), int16, 16)
|
||||
|
||||
chkTruncateStuint(chk, low(uint16), uint16, 16)
|
||||
chkTruncateStuint(chk, high(uint16), uint16, 16)
|
||||
chkTruncateStuint(chk, high(int16), uint16, 16)
|
||||
chkTruncateStuint(chk, high(int16), int16, 16)
|
||||
|
||||
chkTruncateStuint(chk, low(uint8), uint8, 32)
|
||||
chkTruncateStuint(chk, high(uint8), uint8, 32)
|
||||
chkTruncateStuint(chk, high(int8), uint8, 32)
|
||||
chkTruncateStuint(chk, high(int8), int8, 32)
|
||||
|
||||
chkTruncateStuint(chk, low(uint8), uint16, 32)
|
||||
chkTruncateStuint(chk, high(uint8), uint16, 32)
|
||||
chkTruncateStuint(chk, high(int8), uint16, 32)
|
||||
chkTruncateStuint(chk, high(int8), int16, 32)
|
||||
|
||||
chkTruncateStuint(chk, low(uint16), uint16, 32)
|
||||
chkTruncateStuint(chk, high(uint16), uint16, 32)
|
||||
chkTruncateStuint(chk, high(int16), uint16, 32)
|
||||
chkTruncateStuint(chk, high(int16), int16, 32)
|
||||
|
||||
chkTruncateStuint(chk, low(uint8), uint32, 32)
|
||||
chkTruncateStuint(chk, high(uint8), uint32, 32)
|
||||
chkTruncateStuint(chk, high(int8), uint32, 32)
|
||||
chkTruncateStuint(chk, high(int8), int32, 32)
|
||||
|
||||
chkTruncateStuint(chk, low(uint16), uint32, 32)
|
||||
chkTruncateStuint(chk, high(uint16), uint32, 32)
|
||||
chkTruncateStuint(chk, high(int16), uint32, 32)
|
||||
chkTruncateStuint(chk, high(int16), int32, 32)
|
||||
|
||||
chkTruncateStuint(chk, low(uint32), uint32, 32)
|
||||
chkTruncateStuint(chk, high(uint32), uint32, 32)
|
||||
chkTruncateStuint(chk, high(int32), uint32, 32)
|
||||
chkTruncateStuint(chk, high(int32), int32, 32)
|
||||
|
||||
chkTruncateStuint(chk, low(uint8), uint8, 64)
|
||||
chkTruncateStuint(chk, high(uint8), uint8, 64)
|
||||
chkTruncateStuint(chk, high(int8), uint8, 64)
|
||||
chkTruncateStuint(chk, high(int8), int8, 64)
|
||||
|
||||
chkTruncateStuint(chk, low(uint8), uint16, 64)
|
||||
chkTruncateStuint(chk, high(uint8), uint16, 64)
|
||||
chkTruncateStuint(chk, high(int8), uint16, 64)
|
||||
chkTruncateStuint(chk, high(int8), int16, 64)
|
||||
|
||||
chkTruncateStuint(chk, low(uint16), uint16, 64)
|
||||
chkTruncateStuint(chk, high(uint16), uint16, 64)
|
||||
chkTruncateStuint(chk, high(int16), uint16, 64)
|
||||
chkTruncateStuint(chk, high(int16), int16, 64)
|
||||
|
||||
chkTruncateStuint(chk, low(uint8), uint32, 64)
|
||||
chkTruncateStuint(chk, high(uint8), uint32, 64)
|
||||
chkTruncateStuint(chk, high(int8), uint32, 64)
|
||||
chkTruncateStuint(chk, high(int8), int32, 64)
|
||||
|
||||
chkTruncateStuint(chk, low(uint16), uint32, 64)
|
||||
chkTruncateStuint(chk, high(uint16), uint32, 64)
|
||||
chkTruncateStuint(chk, high(int16), uint32, 64)
|
||||
chkTruncateStuint(chk, high(int16), int32, 64)
|
||||
|
||||
chkTruncateStuint(chk, low(uint32), uint32, 64)
|
||||
chkTruncateStuint(chk, high(uint32), uint32, 64)
|
||||
chkTruncateStuint(chk, high(int32), uint32, 64)
|
||||
chkTruncateStuint(chk, high(int32), int32, 64)
|
||||
|
||||
chkTruncateStuint(chk, low(uint8), uint64, 64)
|
||||
chkTruncateStuint(chk, high(uint8), uint64, 64)
|
||||
chkTruncateStuint(chk, high(int8), uint64, 64)
|
||||
chkTruncateStuint(chk, high(int8), int64, 64)
|
||||
|
||||
chkTruncateStuint(chk, low(uint16), uint64, 64)
|
||||
chkTruncateStuint(chk, high(uint16), uint64, 64)
|
||||
chkTruncateStuint(chk, high(int16), uint64, 64)
|
||||
chkTruncateStuint(chk, high(int16), int64, 64)
|
||||
|
||||
chkTruncateStuint(chk, low(uint32), uint64, 64)
|
||||
chkTruncateStuint(chk, high(uint32), uint64, 64)
|
||||
chkTruncateStuint(chk, high(int32), uint64, 64)
|
||||
chkTruncateStuint(chk, high(int32), int64, 64)
|
||||
|
||||
when (NimMajor, NimMinor, NimPatch) >= (1, 0, 0):
|
||||
chkTruncateStuint(chk, low(uint64), uint64, 64)
|
||||
chkTruncateStuint(chk, high(uint64), uint64, 64)
|
||||
chkTruncateStuint(chk, high(int64), uint64, 64)
|
||||
chkTruncateStuint(chk, high(int64), int64, 64)
|
||||
|
||||
chkTruncateStuint(chk, low(uint8), uint8, 128)
|
||||
chkTruncateStuint(chk, high(uint8), uint8, 128)
|
||||
chkTruncateStuint(chk, high(int8), uint8, 128)
|
||||
chkTruncateStuint(chk, high(int8), int8, 128)
|
||||
|
||||
chkTruncateStuint(chk, low(uint8), uint16, 128)
|
||||
chkTruncateStuint(chk, high(uint8), uint16, 128)
|
||||
chkTruncateStuint(chk, high(int8), uint16, 128)
|
||||
chkTruncateStuint(chk, high(int8), int16, 128)
|
||||
|
||||
chkTruncateStuint(chk, low(uint16), uint16, 128)
|
||||
chkTruncateStuint(chk, high(uint16), uint16, 128)
|
||||
chkTruncateStuint(chk, high(int16), uint16, 128)
|
||||
chkTruncateStuint(chk, high(int16), int16, 128)
|
||||
|
||||
chkTruncateStuint(chk, low(uint8), uint32, 128)
|
||||
chkTruncateStuint(chk, high(uint8), uint32, 128)
|
||||
chkTruncateStuint(chk, high(int8), uint32, 128)
|
||||
chkTruncateStuint(chk, high(int8), int32, 128)
|
||||
|
||||
chkTruncateStuint(chk, low(uint16), uint32, 128)
|
||||
chkTruncateStuint(chk, high(uint16), uint32, 128)
|
||||
chkTruncateStuint(chk, high(int16), uint32, 128)
|
||||
chkTruncateStuint(chk, high(int16), int32, 128)
|
||||
|
||||
chkTruncateStuint(chk, low(uint32), uint32, 128)
|
||||
chkTruncateStuint(chk, high(uint32), uint32, 128)
|
||||
chkTruncateStuint(chk, high(int32), uint32, 128)
|
||||
chkTruncateStuint(chk, high(int32), int32, 128)
|
||||
|
||||
chkTruncateStuint(chk, low(uint8), uint64, 128)
|
||||
chkTruncateStuint(chk, high(uint8), uint64, 128)
|
||||
chkTruncateStuint(chk, high(int8), uint64, 128)
|
||||
chkTruncateStuint(chk, high(int8), int64, 128)
|
||||
|
||||
chkTruncateStuint(chk, low(uint16), uint64, 128)
|
||||
chkTruncateStuint(chk, high(uint16), uint64, 128)
|
||||
chkTruncateStuint(chk, high(int16), uint64, 128)
|
||||
chkTruncateStuint(chk, high(int16), int64, 128)
|
||||
|
||||
chkTruncateStuint(chk, low(uint32), uint64, 128)
|
||||
chkTruncateStuint(chk, high(uint32), uint64, 128)
|
||||
chkTruncateStuint(chk, high(int32), uint64, 128)
|
||||
chkTruncateStuint(chk, high(int32), int64, 128)
|
||||
|
||||
when (NimMajor, NimMinor, NimPatch) >= (1, 0, 0):
|
||||
chkTruncateStuint(chk, low(uint64), uint64, 128)
|
||||
chkTruncateStuint(chk, high(uint64), uint64, 128)
|
||||
chkTruncateStuint(chk, high(int64), uint64, 128)
|
||||
chkTruncateStuint(chk, high(int64), int64, 128)
|
||||
|
||||
tst "[stint] truncate":
|
||||
chkTruncateStint(chk, low(uint8), uint8, 8)
|
||||
chkTruncateStint(chk, low(int8), int8, 8)
|
||||
chkTruncateStint(chk, high(int8), uint8, 8)
|
||||
chkTruncateStint(chk, high(int8), int8, 8)
|
||||
chkTruncateStint(chk, low(int8), uint8, "0x80", 8)
|
||||
|
||||
chkTruncateStint(chk, low(uint8), uint8, 16)
|
||||
chkTruncateStint(chk, low(int8), int8, 16)
|
||||
chkTruncateStint(chk, high(int8), uint8, 16)
|
||||
chkTruncateStint(chk, high(int8), int8, 16)
|
||||
chkTruncateStint(chk, low(int8), uint8, "0x80", 16)
|
||||
|
||||
chkTruncateStint(chk, low(uint8), uint16, 16)
|
||||
chkTruncateStint(chk, low(int8), int16, 16)
|
||||
chkTruncateStint(chk, high(int8), uint16, 16)
|
||||
chkTruncateStint(chk, high(int8), int16, 16)
|
||||
chkTruncateStint(chk, low(int8), uint16, "0xFF80", 16)
|
||||
|
||||
chkTruncateStint(chk, low(uint16), uint16, 16)
|
||||
chkTruncateStint(chk, low(int16), int16, 16)
|
||||
chkTruncateStint(chk, high(int16), uint16, 16)
|
||||
chkTruncateStint(chk, high(int16), int16, 16)
|
||||
chkTruncateStint(chk, low(int16), uint16, "0x8000", 16)
|
||||
|
||||
chkTruncateStint(chk, low(uint8), uint8, 32)
|
||||
chkTruncateStint(chk, low(int8), int8, 32)
|
||||
chkTruncateStint(chk, high(int8), uint8, 32)
|
||||
chkTruncateStint(chk, high(int8), int8, 32)
|
||||
chkTruncateStint(chk, low(int8), uint8, "0x80", 32)
|
||||
|
||||
chkTruncateStint(chk, low(uint8), uint16, 32)
|
||||
chkTruncateStint(chk, low(int8), int16, 32)
|
||||
chkTruncateStint(chk, high(int8), uint16, 32)
|
||||
chkTruncateStint(chk, high(int8), int16, 32)
|
||||
chkTruncateStint(chk, low(int8), uint16, "0xFF80", 32)
|
||||
|
||||
chkTruncateStint(chk, low(uint16), uint16, 32)
|
||||
chkTruncateStint(chk, low(int16), int16, 32)
|
||||
chkTruncateStint(chk, high(int16), uint16, 32)
|
||||
chkTruncateStint(chk, high(int16), int16, 32)
|
||||
chkTruncateStint(chk, low(int16), uint16, "0x8000", 32)
|
||||
|
||||
chkTruncateStint(chk, low(uint8), uint32, 32)
|
||||
chkTruncateStint(chk, low(int8), int32, 32)
|
||||
chkTruncateStint(chk, high(int8), uint32, 32)
|
||||
chkTruncateStint(chk, high(int8), int32, 32)
|
||||
chkTruncateStint(chk, low(int8), uint32, "0xFFFFFF80", 32)
|
||||
|
||||
chkTruncateStint(chk, low(uint16), uint32, 32)
|
||||
chkTruncateStint(chk, low(int16), int32, 32)
|
||||
chkTruncateStint(chk, high(int16), uint32, 32)
|
||||
chkTruncateStint(chk, high(int16), int32, 32)
|
||||
chkTruncateStint(chk, low(int16), uint32, "0xFFFF8000", 32)
|
||||
|
||||
chkTruncateStint(chk, low(uint32), uint32, 32)
|
||||
chkTruncateStint(chk, low(int32), int32, 32)
|
||||
chkTruncateStint(chk, high(int32), uint32, 32)
|
||||
chkTruncateStint(chk, high(int32), int32, 32)
|
||||
chkTruncateStint(chk, low(int32), uint32, "0x80000000", 32)
|
||||
|
||||
chkTruncateStint(chk, low(uint8), uint8, 64)
|
||||
chkTruncateStint(chk, low(int8), int8, 64)
|
||||
chkTruncateStint(chk, high(int8), uint8, 64)
|
||||
chkTruncateStint(chk, high(int8), int8, 64)
|
||||
chkTruncateStint(chk, low(int8), uint8, "0x80", 64)
|
||||
|
||||
chkTruncateStint(chk, low(uint8), uint16, 64)
|
||||
chkTruncateStint(chk, low(int8), int16, 64)
|
||||
chkTruncateStint(chk, high(int8), uint16, 64)
|
||||
chkTruncateStint(chk, high(int8), int16, 64)
|
||||
chkTruncateStint(chk, low(int8), uint16, "0xFF80", 64)
|
||||
|
||||
chkTruncateStint(chk, low(uint16), uint16, 64)
|
||||
chkTruncateStint(chk, low(int16), int16, 64)
|
||||
chkTruncateStint(chk, high(int16), uint16, 64)
|
||||
chkTruncateStint(chk, high(int16), int16, 64)
|
||||
chkTruncateStint(chk, low(int16), uint16, "0x8000", 64)
|
||||
|
||||
chkTruncateStint(chk, low(uint8), uint32, 64)
|
||||
chkTruncateStint(chk, low(int8), int32, 64)
|
||||
chkTruncateStint(chk, high(int8), uint32, 64)
|
||||
chkTruncateStint(chk, high(int8), int32, 64)
|
||||
chkTruncateStint(chk, low(int8), uint32, "0xFFFFFF80", 64)
|
||||
|
||||
chkTruncateStint(chk, low(uint16), uint32, 64)
|
||||
chkTruncateStint(chk, low(int16), int32, 64)
|
||||
chkTruncateStint(chk, high(int16), uint32, 64)
|
||||
chkTruncateStint(chk, high(int16), int32, 64)
|
||||
chkTruncateStint(chk, low(int16), uint32, "0xFFFF8000", 64)
|
||||
|
||||
chkTruncateStint(chk, low(uint32), uint32, 64)
|
||||
chkTruncateStint(chk, low(int32), int32, 64)
|
||||
chkTruncateStint(chk, high(int32), uint32, 64)
|
||||
chkTruncateStint(chk, high(int32), int32, 64)
|
||||
chkTruncateStint(chk, low(int32), uint32, "0x80000000", 64)
|
||||
|
||||
chkTruncateStint(chk, low(uint8), uint64, 64)
|
||||
chkTruncateStint(chk, low(int8), int64, 64)
|
||||
chkTruncateStint(chk, high(int8), uint64, 64)
|
||||
chkTruncateStint(chk, high(int8), int64, 64)
|
||||
chkTruncateStint(chk, low(int8), uint64, "0xFFFFFFFFFFFFFF80", 64)
|
||||
|
||||
chkTruncateStint(chk, low(uint16), uint64, 64)
|
||||
chkTruncateStint(chk, low(int16), int64, 64)
|
||||
chkTruncateStint(chk, high(int16), uint64, 64)
|
||||
chkTruncateStint(chk, high(int16), int64, 64)
|
||||
chkTruncateStint(chk, low(int16), uint64, "0xFFFFFFFFFFFF8000", 64)
|
||||
|
||||
chkTruncateStint(chk, low(uint32), uint64, 64)
|
||||
chkTruncateStint(chk, low(int32), int64, 64)
|
||||
chkTruncateStint(chk, high(int32), uint64, 64)
|
||||
chkTruncateStint(chk, high(int32), int64, 64)
|
||||
chkTruncateStint(chk, low(int32), uint64, "0xFFFFFFFF80000000", 64)
|
||||
|
||||
when (NimMajor, NimMinor, NimPatch) >= (1, 0, 0):
|
||||
chkTruncateStint(chk, low(uint64), uint64, 64)
|
||||
chkTruncateStint(chk, low(int64), int64, 64)
|
||||
chkTruncateStint(chk, high(int64), uint64, 64)
|
||||
chkTruncateStint(chk, high(int64), int64, 64)
|
||||
chkTruncateStint(chk, low(int64), uint64, "0x8000000000000000", 64)
|
||||
|
||||
tst "[stuint] parse - toString roundtrip":
|
||||
chkRoundTripBin(chk, chkRoundTripStuint, 8, 1)
|
||||
|
||||
chkRoundTripBin(chk, chkRoundTripStuint, 16, 1)
|
||||
chkRoundTripBin(chk, chkRoundTripStuint, 16, 2)
|
||||
|
||||
chkRoundTripBin(chk, chkRoundTripStuint, 32, 1)
|
||||
chkRoundTripBin(chk, chkRoundTripStuint, 32, 2)
|
||||
chkRoundTripBin(chk, chkRoundTripStuint, 32, 3)
|
||||
chkRoundTripBin(chk, chkRoundTripStuint, 32, 4)
|
||||
|
||||
chkRoundTripBin(chk, chkRoundTripStuint, 64, 1)
|
||||
chkRoundTripBin(chk, chkRoundTripStuint, 64, 2)
|
||||
chkRoundTripBin(chk, chkRoundTripStuint, 64, 3)
|
||||
chkRoundTripBin(chk, chkRoundTripStuint, 64, 4)
|
||||
chkRoundTripBin(chk, chkRoundTripStuint, 64, 5)
|
||||
chkRoundTripBin(chk, chkRoundTripStuint, 64, 6)
|
||||
chkRoundTripBin(chk, chkRoundTripStuint, 64, 7)
|
||||
chkRoundTripBin(chk, chkRoundTripStuint, 64, 8)
|
||||
|
||||
chkRoundTripBin(chk, chkRoundTripStuint, 128, 1)
|
||||
chkRoundTripBin(chk, chkRoundTripStuint, 128, 2)
|
||||
chkRoundTripBin(chk, chkRoundTripStuint, 128, 3)
|
||||
chkRoundTripBin(chk, chkRoundTripStuint, 128, 4)
|
||||
chkRoundTripBin(chk, chkRoundTripStuint, 128, 5)
|
||||
chkRoundTripBin(chk, chkRoundTripStuint, 128, 6)
|
||||
chkRoundTripBin(chk, chkRoundTripStuint, 128, 7)
|
||||
chkRoundTripBin(chk, chkRoundTripStuint, 128, 8)
|
||||
chkRoundTripBin(chk, chkRoundTripStuint, 128, 9)
|
||||
chkRoundTripBin(chk, chkRoundTripStuint, 128, 10)
|
||||
chkRoundTripBin(chk, chkRoundTripStuint, 128, 11)
|
||||
chkRoundTripBin(chk, chkRoundTripStuint, 128, 12)
|
||||
chkRoundTripBin(chk, chkRoundTripStuint, 128, 13)
|
||||
chkRoundTripBin(chk, chkRoundTripStuint, 128, 14)
|
||||
chkRoundTripBin(chk, chkRoundTripStuint, 128, 15)
|
||||
chkRoundTripBin(chk, chkRoundTripStuint, 128, 16)
|
||||
|
||||
chkRoundTripHex(chk, chkRoundTripStuint, 8, 1)
|
||||
|
||||
chkRoundTripHex(chk, chkRoundTripStuint, 16, 1)
|
||||
chkRoundTripHex(chk, chkRoundTripStuint, 16, 2)
|
||||
|
||||
chkRoundTripHex(chk, chkRoundTripStuint, 32, 1)
|
||||
chkRoundTripHex(chk, chkRoundTripStuint, 32, 2)
|
||||
chkRoundTripHex(chk, chkRoundTripStuint, 32, 3)
|
||||
chkRoundTripHex(chk, chkRoundTripStuint, 32, 4)
|
||||
|
||||
chkRoundTripHex(chk, chkRoundTripStuint, 64, 1)
|
||||
chkRoundTripHex(chk, chkRoundTripStuint, 64, 2)
|
||||
chkRoundTripHex(chk, chkRoundTripStuint, 64, 3)
|
||||
chkRoundTripHex(chk, chkRoundTripStuint, 64, 4)
|
||||
chkRoundTripHex(chk, chkRoundTripStuint, 64, 5)
|
||||
chkRoundTripHex(chk, chkRoundTripStuint, 64, 6)
|
||||
chkRoundTripHex(chk, chkRoundTripStuint, 64, 7)
|
||||
chkRoundTripHex(chk, chkRoundTripStuint, 64, 8)
|
||||
|
||||
chkRoundTripHex(chk, chkRoundTripStuint, 128, 1)
|
||||
chkRoundTripHex(chk, chkRoundTripStuint, 128, 2)
|
||||
chkRoundTripHex(chk, chkRoundTripStuint, 128, 3)
|
||||
chkRoundTripHex(chk, chkRoundTripStuint, 128, 4)
|
||||
chkRoundTripHex(chk, chkRoundTripStuint, 128, 5)
|
||||
chkRoundTripHex(chk, chkRoundTripStuint, 128, 6)
|
||||
chkRoundTripHex(chk, chkRoundTripStuint, 128, 7)
|
||||
chkRoundTripHex(chk, chkRoundTripStuint, 128, 8)
|
||||
chkRoundTripHex(chk, chkRoundTripStuint, 128, 9)
|
||||
chkRoundTripHex(chk, chkRoundTripStuint, 128, 10)
|
||||
chkRoundTripHex(chk, chkRoundTripStuint, 128, 11)
|
||||
chkRoundTripHex(chk, chkRoundTripStuint, 128, 12)
|
||||
chkRoundTripHex(chk, chkRoundTripStuint, 128, 13)
|
||||
chkRoundTripHex(chk, chkRoundTripStuint, 128, 14)
|
||||
chkRoundTripHex(chk, chkRoundTripStuint, 128, 15)
|
||||
chkRoundTripHex(chk, chkRoundTripStuint, 128, 16)
|
||||
|
||||
chkRoundTripOct(chk, chkRoundTripStuint, 8, 1)
|
||||
chkRoundtripStuint(chk, "377", 8, 8)
|
||||
|
||||
chkRoundTripOct(chk, chkRoundTripStuint, 16, 1)
|
||||
chkRoundTripOct(chk, chkRoundTripStuint, 16, 2)
|
||||
chkRoundtripStuint(chk, "377", 16, 8)
|
||||
chkRoundtripStuint(chk, "177777", 16, 8)
|
||||
|
||||
chkRoundTripOct(chk, chkRoundTripStuint, 32, 1)
|
||||
chkRoundTripOct(chk, chkRoundTripStuint, 32, 2)
|
||||
chkRoundTripOct(chk, chkRoundTripStuint, 32, 3)
|
||||
chkRoundtripStuint(chk, "377", 32, 8)
|
||||
chkRoundtripStuint(chk, "177777", 32, 8)
|
||||
chkRoundtripStuint(chk, "37777777777", 32, 8)
|
||||
|
||||
chkRoundTripOct(chk, chkRoundTripStuint, 64, 1)
|
||||
chkRoundTripOct(chk, chkRoundTripStuint, 64, 2)
|
||||
chkRoundTripOct(chk, chkRoundTripStuint, 64, 3)
|
||||
chkRoundTripOct(chk, chkRoundTripStuint, 64, 4)
|
||||
chkRoundTripOct(chk, chkRoundTripStuint, 64, 5)
|
||||
chkRoundTripOct(chk, chkRoundTripStuint, 64, 6)
|
||||
chkRoundTripOct(chk, chkRoundTripStuint, 64, 7)
|
||||
chkRoundtripStuint(chk, "377", 64, 8)
|
||||
chkRoundtripStuint(chk, "177777", 64, 8)
|
||||
chkRoundtripStuint(chk, "37777777777", 64, 8)
|
||||
chkRoundtripStuint(chk, "1777777777777777777777", 64, 8)
|
||||
|
||||
chkRoundTripOct(chk, chkRoundTripStuint, 128, 1)
|
||||
chkRoundTripOct(chk, chkRoundTripStuint, 128, 2)
|
||||
chkRoundTripOct(chk, chkRoundTripStuint, 128, 3)
|
||||
chkRoundTripOct(chk, chkRoundTripStuint, 128, 4)
|
||||
chkRoundTripOct(chk, chkRoundTripStuint, 128, 5)
|
||||
chkRoundTripOct(chk, chkRoundTripStuint, 128, 6)
|
||||
chkRoundTripOct(chk, chkRoundTripStuint, 128, 7)
|
||||
chkRoundTripOct(chk, chkRoundTripStuint, 128, 8)
|
||||
chkRoundTripOct(chk, chkRoundTripStuint, 128, 9)
|
||||
chkRoundTripOct(chk, chkRoundTripStuint, 128, 10)
|
||||
chkRoundTripOct(chk, chkRoundTripStuint, 128, 11)
|
||||
chkRoundTripOct(chk, chkRoundTripStuint, 128, 12)
|
||||
chkRoundTripOct(chk, chkRoundTripStuint, 128, 13)
|
||||
chkRoundTripOct(chk, chkRoundTripStuint, 128, 14)
|
||||
chkRoundtripStuint(chk, "377", 128, 8)
|
||||
chkRoundtripStuint(chk, "177777", 128, 8)
|
||||
chkRoundtripStuint(chk, "37777777777", 128, 8)
|
||||
chkRoundtripStuint(chk, "1777777777777777777777", 128, 8)
|
||||
chkRoundtripStuint(chk, "3777777777777777777777777777777777777777777", 128, 8)
|
||||
|
||||
chkRoundTripDec(chk, chkRoundTripStuint, 8, 1)
|
||||
chkRoundtripStuint(chk, "255", 8, 10)
|
||||
|
||||
chkRoundTripDec(chk, chkRoundTripStuint, 16, 1)
|
||||
chkRoundTripDec(chk, chkRoundTripStuint, 16, 2)
|
||||
chkRoundtripStuint(chk, "255", 16, 10)
|
||||
chkRoundtripStuint(chk, "65535", 16, 10)
|
||||
|
||||
chkRoundTripDec(chk, chkRoundTripStuint, 32, 1)
|
||||
chkRoundTripDec(chk, chkRoundTripStuint, 32, 2)
|
||||
chkRoundTripDec(chk, chkRoundTripStuint, 32, 3)
|
||||
chkRoundtripStuint(chk, "255", 32, 10)
|
||||
chkRoundtripStuint(chk, "65535", 32, 10)
|
||||
chkRoundtripStuint(chk, "4294967295", 32, 10)
|
||||
|
||||
chkRoundTripDec(chk, chkRoundTripStuint, 64, 1)
|
||||
chkRoundTripDec(chk, chkRoundTripStuint, 64, 2)
|
||||
chkRoundTripDec(chk, chkRoundTripStuint, 64, 3)
|
||||
chkRoundTripDec(chk, chkRoundTripStuint, 64, 4)
|
||||
chkRoundTripDec(chk, chkRoundTripStuint, 64, 5)
|
||||
chkRoundTripDec(chk, chkRoundTripStuint, 64, 6)
|
||||
chkRoundTripDec(chk, chkRoundTripStuint, 64, 7)
|
||||
chkRoundtripStuint(chk, "255", 64, 10)
|
||||
chkRoundtripStuint(chk, "65535", 64, 10)
|
||||
chkRoundtripStuint(chk, "4294967295", 64, 10)
|
||||
chkRoundtripStuint(chk, "18446744073709551615", 64, 10)
|
||||
|
||||
chkRoundTripDec(chk, chkRoundTripStuint, 128, 1)
|
||||
chkRoundTripDec(chk, chkRoundTripStuint, 128, 2)
|
||||
chkRoundTripDec(chk, chkRoundTripStuint, 128, 3)
|
||||
chkRoundTripDec(chk, chkRoundTripStuint, 128, 4)
|
||||
chkRoundTripDec(chk, chkRoundTripStuint, 128, 5)
|
||||
chkRoundTripDec(chk, chkRoundTripStuint, 128, 6)
|
||||
chkRoundTripDec(chk, chkRoundTripStuint, 128, 7)
|
||||
chkRoundTripDec(chk, chkRoundTripStuint, 128, 8)
|
||||
chkRoundTripDec(chk, chkRoundTripStuint, 128, 9)
|
||||
chkRoundTripDec(chk, chkRoundTripStuint, 128, 10)
|
||||
chkRoundTripDec(chk, chkRoundTripStuint, 128, 11)
|
||||
chkRoundTripDec(chk, chkRoundTripStuint, 128, 12)
|
||||
chkRoundTripDec(chk, chkRoundTripStuint, 128, 13)
|
||||
chkRoundTripDec(chk, chkRoundTripStuint, 128, 14)
|
||||
chkRoundtripStuint(chk, "255", 128, 10)
|
||||
chkRoundtripStuint(chk, "65535", 128, 10)
|
||||
chkRoundtripStuint(chk, "4294967295", 128, 10)
|
||||
chkRoundtripStuint(chk, "18446744073709551615", 128, 10)
|
||||
chkRoundtripStuint(chk, "340282366920938463463374607431768211455", 128, 10)
|
||||
|
||||
tst "[stint] parse - toString roundtrip":
|
||||
chkRoundTripBin(chk, chkRoundTripStint, 8, 1)
|
||||
chkRoundtripStint(chk, "1" & repeat('0', 7), 8, 2)
|
||||
|
||||
chkRoundTripBin(chk, chkRoundTripStint, 16, 1)
|
||||
chkRoundTripBin(chk, chkRoundTripStint, 16, 2)
|
||||
chkRoundtripStint(chk, "1" & repeat('0', 15), 16, 2)
|
||||
|
||||
chkRoundTripBin(chk, chkRoundTripStint, 32, 1)
|
||||
chkRoundTripBin(chk, chkRoundTripStint, 32, 2)
|
||||
chkRoundTripBin(chk, chkRoundTripStint, 32, 3)
|
||||
chkRoundTripBin(chk, chkRoundTripStint, 32, 4)
|
||||
chkRoundtripStint(chk, "1" & repeat('0', 31), 32, 2)
|
||||
|
||||
chkRoundTripBin(chk, chkRoundTripStint, 64, 1)
|
||||
chkRoundTripBin(chk, chkRoundTripStint, 64, 2)
|
||||
chkRoundTripBin(chk, chkRoundTripStint, 64, 3)
|
||||
chkRoundTripBin(chk, chkRoundTripStint, 64, 4)
|
||||
chkRoundTripBin(chk, chkRoundTripStint, 64, 5)
|
||||
chkRoundTripBin(chk, chkRoundTripStint, 64, 6)
|
||||
chkRoundTripBin(chk, chkRoundTripStint, 64, 7)
|
||||
chkRoundTripBin(chk, chkRoundTripStint, 64, 8)
|
||||
chkRoundtripStint(chk, "1" & repeat('0', 63), 64, 2)
|
||||
|
||||
chkRoundTripBin(chk, chkRoundTripStint, 128, 1)
|
||||
chkRoundTripBin(chk, chkRoundTripStint, 128, 2)
|
||||
chkRoundTripBin(chk, chkRoundTripStint, 128, 3)
|
||||
chkRoundTripBin(chk, chkRoundTripStint, 128, 4)
|
||||
chkRoundTripBin(chk, chkRoundTripStint, 128, 5)
|
||||
chkRoundTripBin(chk, chkRoundTripStint, 128, 6)
|
||||
chkRoundTripBin(chk, chkRoundTripStint, 128, 7)
|
||||
chkRoundTripBin(chk, chkRoundTripStint, 128, 8)
|
||||
chkRoundTripBin(chk, chkRoundTripStint, 128, 9)
|
||||
chkRoundTripBin(chk, chkRoundTripStint, 128, 10)
|
||||
chkRoundTripBin(chk, chkRoundTripStint, 128, 11)
|
||||
chkRoundTripBin(chk, chkRoundTripStint, 128, 12)
|
||||
chkRoundTripBin(chk, chkRoundTripStint, 128, 13)
|
||||
chkRoundTripBin(chk, chkRoundTripStint, 128, 14)
|
||||
chkRoundTripBin(chk, chkRoundTripStint, 128, 15)
|
||||
chkRoundTripBin(chk, chkRoundTripStint, 128, 16)
|
||||
chkRoundtripStint(chk, "1" & repeat('0', 127), 128, 2)
|
||||
|
||||
chkRoundTripHex(chk, chkRoundTripStint, 8, 1)
|
||||
chkRoundtripStint(chk, "8" & repeat('0', 1), 8, 16)
|
||||
|
||||
chkRoundTripHex(chk, chkRoundTripStint, 16, 1)
|
||||
chkRoundTripHex(chk, chkRoundTripStint, 16, 2)
|
||||
chkRoundtripStint(chk, "8" & repeat('0', 3), 16, 16)
|
||||
|
||||
chkRoundTripHex(chk, chkRoundTripStint, 32, 1)
|
||||
chkRoundTripHex(chk, chkRoundTripStint, 32, 2)
|
||||
chkRoundTripHex(chk, chkRoundTripStint, 32, 3)
|
||||
chkRoundTripHex(chk, chkRoundTripStint, 32, 4)
|
||||
chkRoundtripStint(chk, "8" & repeat('0', 7), 32, 16)
|
||||
|
||||
chkRoundTripHex(chk, chkRoundTripStint, 64, 1)
|
||||
chkRoundTripHex(chk, chkRoundTripStint, 64, 2)
|
||||
chkRoundTripHex(chk, chkRoundTripStint, 64, 3)
|
||||
chkRoundTripHex(chk, chkRoundTripStint, 64, 4)
|
||||
chkRoundTripHex(chk, chkRoundTripStint, 64, 5)
|
||||
chkRoundTripHex(chk, chkRoundTripStint, 64, 6)
|
||||
chkRoundTripHex(chk, chkRoundTripStint, 64, 7)
|
||||
chkRoundTripHex(chk, chkRoundTripStint, 64, 8)
|
||||
chkRoundtripStint(chk, "8" & repeat('0', 15), 64, 16)
|
||||
|
||||
chkRoundTripHex(chk, chkRoundTripStint, 128, 1)
|
||||
chkRoundTripHex(chk, chkRoundTripStint, 128, 2)
|
||||
chkRoundTripHex(chk, chkRoundTripStint, 128, 3)
|
||||
chkRoundTripHex(chk, chkRoundTripStint, 128, 4)
|
||||
chkRoundTripHex(chk, chkRoundTripStint, 128, 5)
|
||||
chkRoundTripHex(chk, chkRoundTripStint, 128, 6)
|
||||
chkRoundTripHex(chk, chkRoundTripStint, 128, 7)
|
||||
chkRoundTripHex(chk, chkRoundTripStint, 128, 8)
|
||||
chkRoundTripHex(chk, chkRoundTripStint, 128, 9)
|
||||
chkRoundTripHex(chk, chkRoundTripStint, 128, 10)
|
||||
chkRoundTripHex(chk, chkRoundTripStint, 128, 11)
|
||||
chkRoundTripHex(chk, chkRoundTripStint, 128, 12)
|
||||
chkRoundTripHex(chk, chkRoundTripStint, 128, 13)
|
||||
chkRoundTripHex(chk, chkRoundTripStint, 128, 14)
|
||||
chkRoundTripHex(chk, chkRoundTripStint, 128, 15)
|
||||
chkRoundTripHex(chk, chkRoundTripStint, 128, 16)
|
||||
chkRoundtripStint(chk, "8" & repeat('0', 31), 128, 16)
|
||||
|
||||
chkRoundTripOct(chk, chkRoundTripStint, 8, 1)
|
||||
chkRoundtripStint(chk, "377", 8, 8)
|
||||
chkRoundtripStint(chk, "200", 8, 8)
|
||||
|
||||
chkRoundTripOct(chk, chkRoundTripStint, 16, 1)
|
||||
chkRoundTripOct(chk, chkRoundTripStint, 16, 2)
|
||||
chkRoundtripStint(chk, "377", 16, 8)
|
||||
chkRoundtripStint(chk, "200", 16, 8)
|
||||
chkRoundtripStint(chk, "177777", 16, 8)
|
||||
chkRoundtripStint(chk, "100000", 16, 8)
|
||||
|
||||
chkRoundTripOct(chk, chkRoundTripStint, 32, 1)
|
||||
chkRoundTripOct(chk, chkRoundTripStint, 32, 2)
|
||||
chkRoundTripOct(chk, chkRoundTripStint, 32, 3)
|
||||
chkRoundtripStint(chk, "377", 32, 8)
|
||||
chkRoundtripStint(chk, "200", 32, 8)
|
||||
chkRoundtripStint(chk, "177777", 32, 8)
|
||||
chkRoundtripStint(chk, "100000", 32, 8)
|
||||
chkRoundtripStint(chk, "37777777777", 32, 8)
|
||||
chkRoundtripStint(chk, "20000000000", 32, 8)
|
||||
|
||||
chkRoundTripOct(chk, chkRoundTripStint, 64, 1)
|
||||
chkRoundTripOct(chk, chkRoundTripStint, 64, 2)
|
||||
chkRoundTripOct(chk, chkRoundTripStint, 64, 3)
|
||||
chkRoundTripOct(chk, chkRoundTripStint, 64, 4)
|
||||
chkRoundTripOct(chk, chkRoundTripStint, 64, 5)
|
||||
chkRoundTripOct(chk, chkRoundTripStint, 64, 6)
|
||||
chkRoundTripOct(chk, chkRoundTripStint, 64, 7)
|
||||
chkRoundtripStint(chk, "377", 64, 8)
|
||||
chkRoundtripStint(chk, "200", 64, 8)
|
||||
chkRoundtripStint(chk, "177777", 64, 8)
|
||||
chkRoundtripStint(chk, "100000", 64, 8)
|
||||
chkRoundtripStint(chk, "37777777777", 64, 8)
|
||||
chkRoundtripStint(chk, "20000000000", 64, 8)
|
||||
chkRoundtripStint(chk, "1777777777777777777777", 64, 8)
|
||||
chkRoundtripStint(chk, "1000000000000000000000", 64, 8)
|
||||
|
||||
chkRoundTripOct(chk, chkRoundTripStint, 128, 1)
|
||||
chkRoundTripOct(chk, chkRoundTripStint, 128, 2)
|
||||
chkRoundTripOct(chk, chkRoundTripStint, 128, 3)
|
||||
chkRoundTripOct(chk, chkRoundTripStint, 128, 4)
|
||||
chkRoundTripOct(chk, chkRoundTripStint, 128, 5)
|
||||
chkRoundTripOct(chk, chkRoundTripStint, 128, 6)
|
||||
chkRoundTripOct(chk, chkRoundTripStint, 128, 7)
|
||||
chkRoundTripOct(chk, chkRoundTripStint, 128, 8)
|
||||
chkRoundTripOct(chk, chkRoundTripStint, 128, 9)
|
||||
chkRoundTripOct(chk, chkRoundTripStint, 128, 10)
|
||||
chkRoundTripOct(chk, chkRoundTripStint, 128, 11)
|
||||
chkRoundTripOct(chk, chkRoundTripStint, 128, 12)
|
||||
chkRoundTripOct(chk, chkRoundTripStint, 128, 13)
|
||||
chkRoundTripOct(chk, chkRoundTripStint, 128, 14)
|
||||
chkRoundtripStint(chk, "377", 128, 8)
|
||||
chkRoundtripStint(chk, "200", 128, 8)
|
||||
chkRoundtripStint(chk, "177777", 128, 8)
|
||||
chkRoundtripStint(chk, "100000", 128, 8)
|
||||
chkRoundtripStint(chk, "37777777777", 128, 8)
|
||||
chkRoundtripStint(chk, "20000000000", 128, 8)
|
||||
chkRoundtripStint(chk, "1777777777777777777777", 128, 8)
|
||||
chkRoundtripStint(chk, "1000000000000000000000", 128, 8)
|
||||
chkRoundtripStint(chk, "3777777777777777777777777777777777777777777", 128, 8)
|
||||
chkRoundtripStint(chk, "2000000000000000000000000000000000000000000", 128, 8)
|
||||
|
||||
chkRoundTripDec(chk, chkRoundTripStint, 8, 1)
|
||||
chkRoundtripStint(chk, "127", 8, 10)
|
||||
chkRoundtripStint(chk, "-127", 8, 10)
|
||||
# chkRoundtripStint(chk, "-128", 8, 10) # TODO: not supported yet
|
||||
|
||||
chkRoundTripDec(chk, chkRoundTripStint, 16, 1)
|
||||
chkRoundTripDec(chk, chkRoundTripStint, 16, 2)
|
||||
chkRoundtripStint(chk, "255", 16, 10)
|
||||
chkRoundtripStint(chk, "127", 16, 10)
|
||||
chkRoundtripStint(chk, "-128", 16, 10)
|
||||
chkRoundtripStint(chk, "32767", 16, 10)
|
||||
chkRoundtripStint(chk, "-32767", 16, 10)
|
||||
#chkRoundtripStint(chk, "-32768", 16, 10) # TODO: not supported yet
|
||||
|
||||
chkRoundTripDec(chk, chkRoundTripStint, 32, 1)
|
||||
chkRoundTripDec(chk, chkRoundTripStint, 32, 2)
|
||||
chkRoundTripDec(chk, chkRoundTripStint, 32, 3)
|
||||
chkRoundtripStint(chk, "255", 32, 10)
|
||||
chkRoundtripStint(chk, "127", 32, 10)
|
||||
chkRoundtripStint(chk, "-128", 32, 10)
|
||||
chkRoundtripStint(chk, "32767", 32, 10)
|
||||
chkRoundtripStint(chk, "-32768", 32, 10)
|
||||
chkRoundtripStint(chk, "65535", 32, 10)
|
||||
chkRoundtripStint(chk, "-2147483647", 32, 10)
|
||||
#chkRoundtripStint(chk, "-2147483648", 32, 10) # TODO: not supported yet
|
||||
|
||||
chkRoundTripDec(chk, chkRoundTripStint, 64, 1)
|
||||
chkRoundTripDec(chk, chkRoundTripStint, 64, 2)
|
||||
chkRoundTripDec(chk, chkRoundTripStint, 64, 3)
|
||||
chkRoundTripDec(chk, chkRoundTripStint, 64, 4)
|
||||
chkRoundTripDec(chk, chkRoundTripStint, 64, 5)
|
||||
chkRoundTripDec(chk, chkRoundTripStint, 64, 6)
|
||||
chkRoundTripDec(chk, chkRoundTripStint, 64, 7)
|
||||
chkRoundtripStint(chk, "255", 64, 10)
|
||||
chkRoundtripStint(chk, "65535", 64, 10)
|
||||
chkRoundtripStint(chk, "127", 64, 10)
|
||||
chkRoundtripStint(chk, "-128", 64, 10)
|
||||
chkRoundtripStint(chk, "32767", 64, 10)
|
||||
chkRoundtripStint(chk, "-32768", 64, 10)
|
||||
chkRoundtripStint(chk, "65535", 64, 10)
|
||||
chkRoundtripStint(chk, "-2147483648", 64, 10)
|
||||
chkRoundtripStint(chk, "4294967295", 64, 10)
|
||||
chkRoundtripStint(chk, "-9223372036854775807", 64, 10)
|
||||
#chkRoundtripStint(chk, "-9223372036854775808", 64, 10) # TODO: not supported yet
|
||||
|
||||
chkRoundTripDec(chk, chkRoundTripStint, 128, 1)
|
||||
chkRoundTripDec(chk, chkRoundTripStint, 128, 2)
|
||||
chkRoundTripDec(chk, chkRoundTripStint, 128, 3)
|
||||
chkRoundTripDec(chk, chkRoundTripStint, 128, 4)
|
||||
chkRoundTripDec(chk, chkRoundTripStint, 128, 5)
|
||||
chkRoundTripDec(chk, chkRoundTripStint, 128, 6)
|
||||
chkRoundTripDec(chk, chkRoundTripStint, 128, 7)
|
||||
chkRoundTripDec(chk, chkRoundTripStint, 128, 8)
|
||||
chkRoundTripDec(chk, chkRoundTripStint, 128, 9)
|
||||
chkRoundTripDec(chk, chkRoundTripStint, 128, 10)
|
||||
chkRoundTripDec(chk, chkRoundTripStint, 128, 11)
|
||||
chkRoundTripDec(chk, chkRoundTripStint, 128, 12)
|
||||
chkRoundTripDec(chk, chkRoundTripStint, 128, 13)
|
||||
chkRoundTripDec(chk, chkRoundTripStint, 128, 14)
|
||||
chkRoundtripStint(chk, "255", 128, 10)
|
||||
chkRoundtripStint(chk, "65535", 128, 10)
|
||||
chkRoundtripStint(chk, "4294967295", 128, 10)
|
||||
chkRoundtripStint(chk, "18446744073709551615", 128, 10)
|
||||
chkRoundtripStint(chk, "-170141183460469231731687303715884105727", 128, 10)
|
||||
#chkRoundtripStint(chk, "-170141183460469231731687303715884105728", 128, 10) # TODO: not supported yet
|
||||
|
||||
tst "roundtrip initFromBytesBE and toByteArrayBE":
|
||||
chkRoundtripBE(chk, "x", 8)
|
||||
chkRoundtripBE(chk, "xy", 16)
|
||||
chkRoundtripBE(chk, "xyzw", 32)
|
||||
chkRoundtripBE(chk, "xyzwabcd", 64)
|
||||
chkRoundtripBE(chk, "xyzwabcd12345678", 128)
|
||||
chkRoundtripBE(chk, "xyzwabcd12345678kilimanjarohello", 256)
|
||||
|
||||
tst "dumpHex":
|
||||
chkDumpHex(chk, "ab", "ab", 8)
|
||||
|
||||
chkDumpHex(chk, "00ab", "ab00", 16)
|
||||
chkDumpHex(chk, "abcd", "cdab", 16)
|
||||
|
||||
chkDumpHex(chk, "000000ab", "ab000000", 32)
|
||||
chkDumpHex(chk, "3412abcd", "cdab1234", 32)
|
||||
|
||||
chkDumpHex(chk, "00000000000000ab", "ab00000000000000", 64)
|
||||
chkDumpHex(chk, "abcdef0012345678", "7856341200efcdab", 64)
|
||||
|
||||
chkDumpHex(chk, "abcdef0012345678abcdef1122334455", "5544332211efcdab7856341200efcdab", 128)
|
||||
|
||||
static:
|
||||
testIO(doAssert, ctTest)
|
||||
|
||||
proc main() =
|
||||
# Nim GC protests we are using too much global variables
|
||||
# so put it in a proc
|
||||
suite "Testing input and output procedures":
|
||||
testIO(check, test)
|
||||
|
||||
# dumpHex
|
||||
|
||||
test "toByteArrayBE CT vs RT":
|
||||
chkCTvsRT(check, 0xab'u8, 8)
|
||||
|
||||
chkCTvsRT(check, 0xab'u16, 16)
|
||||
chkCTvsRT(check, 0xabcd'u16, 16)
|
||||
|
||||
chkCTvsRT(check, 0xab'u32, 32)
|
||||
chkCTvsRT(check, 0xabcd'u32, 32)
|
||||
chkCTvsRT(check, 0xabcdef12'u32, 32)
|
||||
|
||||
chkCTvsRT(check, 0xab'u64, 64)
|
||||
chkCTvsRT(check, 0xabcd'u64, 64)
|
||||
chkCTvsRT(check, 0xabcdef12'u64, 64)
|
||||
chkCTvsRT(check, 0xabcdef12abcdef12'u64, 64)
|
||||
|
||||
chkCTvsRT(check, 0xab'u64, 128)
|
||||
chkCTvsRT(check, 0xabcd'u64, 128)
|
||||
chkCTvsRT(check, 0xabcdef12'u64, 128)
|
||||
chkCTvsRT(check, 0xabcdef12abcdef12'u64, 128)
|
||||
|
||||
test "Creation from decimal strings":
|
||||
block:
|
||||
let a = "123456789".parse(Stint[64])
|
||||
@ -139,7 +1117,7 @@ suite "Testing input and output procedures":
|
||||
else:
|
||||
echo "Next test skipped when Stint forces uint32 backend in test mode"
|
||||
|
||||
suite "Testing conversion functions: Hex, Bytes, Endianness using secp256k1 curve":
|
||||
suite "Testing conversion functions: Hex, Bytes, Endianness using secp256k1 curve":
|
||||
|
||||
let
|
||||
SECPK1_N_HEX = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141".toLowerAscii
|
||||
@ -255,3 +1233,5 @@ suite "Testing conversion functions: Hex, Bytes, Endianness using secp256k1 curv
|
||||
test "Eve signature":
|
||||
check: eve.raw_sig.r.parse(Stuint[256], 16) == "84467545608142925331782333363288012579669270632210954476013542647119929595395".u256
|
||||
check: eve.raw_sig.s.parse(Stuint[256], 16) == "43529886636775750164425297556346136250671451061152161143648812009114516499167".u256
|
||||
|
||||
main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user