|
1 | | -discard """ |
2 | | - cmd: "nim c -r --styleCheck:hint --panics:on $options $file" |
3 | | - matrix: "-d:danger; -d:release" |
4 | | - targets: "c cpp" |
5 | | - nimout: "" |
6 | | - action: "run" |
7 | | - exitcode: 0 |
8 | | - timeout: 60.0 |
9 | | -""" |
10 | | - |
11 | 1 | import std/varints |
12 | 2 |
|
| 3 | +# xxx doesn't work with js: tvarints.nim(18, 14) `wrLen == rdLen` [AssertionDefect] |
13 | 4 |
|
14 | 5 | block: |
15 | 6 | var dest: array[50, byte] |
@@ -39,46 +30,39 @@ block: |
39 | 30 | block: |
40 | 31 | var hugeIntArray: array[50, byte] |
41 | 32 | var readedInt: uint64 |
42 | | - doAssert writeVu64(hugeIntArray, 0.uint64) == readVu64(hugeIntArray, readedInt) |
43 | | - doAssert readedInt == 0.uint64 |
44 | | - doAssert writeVu64(hugeIntArray, uint64.high) == readVu64(hugeIntArray, readedInt) |
45 | | - doAssert readedInt == uint64.high |
46 | | - doAssert writeVu64(hugeIntArray, uint64(int64.high)) == readVu64(hugeIntArray, readedInt) |
47 | | - doAssert readedInt == uint64(int64.high) |
48 | | - doAssert writeVu64(hugeIntArray, uint64(int32.high)) == readVu64(hugeIntArray, readedInt) |
49 | | - doAssert readedInt == uint64(int32.high) |
50 | | - doAssert writeVu64(hugeIntArray, uint64(int16.high)) == readVu64(hugeIntArray, readedInt) |
51 | | - doAssert readedInt == uint64(int16.high) |
52 | | - doAssert writeVu64(hugeIntArray, uint64(int8.high)) == readVu64(hugeIntArray, readedInt) |
53 | | - doAssert readedInt == uint64(int8.high) |
54 | | - doAssert writeVu64(hugeIntArray, cast[uint64](0.0)) == readVu64(hugeIntArray, readedInt) |
55 | | - doAssert readedInt == cast[uint64](0.0) |
56 | | - doAssert writeVu64(hugeIntArray, cast[uint64](-0.0)) == readVu64(hugeIntArray, readedInt) |
57 | | - doAssert readedInt == cast[uint64](-0.0) |
58 | | - doAssert writeVu64(hugeIntArray, cast[uint64](0.1)) == readVu64(hugeIntArray, readedInt) |
59 | | - doAssert readedInt == cast[uint64](0.1) |
60 | | - doAssert writeVu64(hugeIntArray, cast[uint64](0.9555555555555555555555501)) == readVu64(hugeIntArray, readedInt) |
61 | | - doAssert readedInt == cast[uint64](0.9555555555555555555555501) |
62 | | - doAssert writeVu64(hugeIntArray, cast[uint64](+Inf)) == readVu64(hugeIntArray, readedInt) |
63 | | - doAssert readedInt == cast[uint64](+Inf) |
64 | | - doAssert writeVu64(hugeIntArray, cast[uint64](NegInf)) == readVu64(hugeIntArray, readedInt) |
65 | | - doAssert readedInt == cast[uint64](NegInf) |
66 | | - doAssert writeVu64(hugeIntArray, cast[uint64](Nan)) == readVu64(hugeIntArray, readedInt) |
67 | | - doAssert readedInt == cast[uint64](Nan) |
68 | | - doAssert writeVu64(hugeIntArray, cast[uint64](3.1415926535897932384626433)) == readVu64(hugeIntArray, readedInt) |
69 | | - doAssert readedInt == cast[uint64](3.1415926535897932384626433) |
70 | | - doAssert writeVu64(hugeIntArray, cast[uint64](2.71828182845904523536028747)) == readVu64(hugeIntArray, readedInt) |
71 | | - doAssert readedInt == cast[uint64](2.71828182845904523536028747) |
| 33 | + |
| 34 | + template chk(a) = |
| 35 | + let b = cast[uint64](a) |
| 36 | + doAssert writeVu64(hugeIntArray, b) == readVu64(hugeIntArray, readedInt) |
| 37 | + doAssert readedInt == b |
| 38 | + |
| 39 | + chk 0 |
| 40 | + chk uint64.high |
| 41 | + chk int64.high |
| 42 | + chk int32.high |
| 43 | + chk int16.high |
| 44 | + chk int16.high |
| 45 | + chk int8.high |
| 46 | + chk 0.0 |
| 47 | + chk -0.0 |
| 48 | + chk 0.1 |
| 49 | + chk Inf |
| 50 | + chk NegInf |
| 51 | + chk Nan |
| 52 | + chk 3.1415926535897932384626433 |
72 | 53 |
|
73 | 54 | block: |
74 | | - doAssert encodeZigzag(decodeZigzag(0.uint64)) == 0.uint64 |
75 | | - doAssert encodeZigzag(decodeZigzag(uint64(uint32.high))) == uint64(uint32.high) |
76 | | - doAssert encodeZigzag(decodeZigzag(uint64(int32.high))) == uint64(int32.high) |
77 | | - doAssert encodeZigzag(decodeZigzag(uint64(int16.high))) == uint64(int16.high) |
78 | | - doAssert encodeZigzag(decodeZigzag(uint64(int8.high))) == uint64(int8.high) |
79 | | - doAssert encodeZigzag(decodeZigzag(cast[uint64](0.0))) == cast[uint64](0.0) |
80 | | - doAssert encodeZigzag(decodeZigzag(cast[uint64](0.1))) == cast[uint64](0.1) |
81 | | - doAssert encodeZigzag(decodeZigzag(cast[uint64](0.9555555555555555555555501))) == cast[uint64](0.9555555555555555555555501) |
82 | | - doAssert encodeZigzag(decodeZigzag(cast[uint64](+Inf))) == cast[uint64](+Inf) |
83 | | - doAssert encodeZigzag(decodeZigzag(cast[uint64](3.1415926535897932384626433))) == cast[uint64](3.1415926535897932384626433) |
84 | | - doAssert encodeZigzag(decodeZigzag(cast[uint64](2.71828182845904523536028747))) == cast[uint64](2.71828182845904523536028747) |
| 55 | + template chk(a) = |
| 56 | + let b = cast[uint64](a) |
| 57 | + doAssert encodeZigzag(decodeZigzag(b)) == b |
| 58 | + chk 0 |
| 59 | + chk uint32.high |
| 60 | + chk int32.high |
| 61 | + chk int16.high |
| 62 | + chk int8.high |
| 63 | + chk 0.0 |
| 64 | + chk 0.1 |
| 65 | + chk 0.9555555555555555555555501 |
| 66 | + chk Inf |
| 67 | + chk 3.1415926535897932384626433 |
| 68 | + chk 2.71828182845904523536028747 |
0 commit comments