1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
discard """
cmd: "nim c -r --styleCheck:hint --panics:on $options $file"
matrix: "-d:danger; -d:release"
targets: "c cpp"
nimout: ""
action: "run"
exitcode: 0
timeout: 60.0
"""
import std/varints
block:
var dest: array[50, byte]
var got: uint64
for test in [0xFFFF_FFFF_FFFFF_FFFFu64, 77u64, 0u64, 10_000_000u64, uint64(high(int64)),
uint64(high(int32)), uint64(high(int32)), uint64(high(int64))]:
let wrLen = writeVu64(dest, test)
let rdLen = readVu64(dest, got)
doAssert wrLen == rdLen
doAssert got == test
for test in 0u64..300u64:
let wrLen = writeVu64(dest, test)
let rdLen = readVu64(dest, got)
doAssert wrLen == rdLen
doAssert got == test
# check this also works for floats:
for test in [0.0, 0.1, 2.0, +Inf, NegInf]:
let t = cast[uint64](test)
let wrLenB = writeVu64(dest, t)
let rdLenB = readVu64(dest, got)
doAssert wrLenB == rdLenB
doAssert<
|