fix #16256: nimout: <empty> should give error (vacuously true); improve a few tests (#18089)

* fix #16256: nimout: <empty> should give error (vacuously true); improve some tests

* renamed:    tests/stdlib/t9710.nim -> tests/misc/t9710.nim

* improve tests

* fix non-DRY tests

* improve $nim_prs_D/tests/stdlib/t9091.nim

* renamed:    tests/stdlib/t9091.nim -> tests/misc/t9091.nim

* fixup

* address comment: doAssert => result.parseErrors
This commit is contained in:
Timothee Cour 2021-05-31 04:39:19 -07:00 • committed by GitHub
commit a36efb59b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 73 additions and 106 deletions

View file

@ -1,15 +1,6 @@
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
# xxx doesn't work with js: tvarints.nim(18, 14) `wrLen == rdLen` [AssertionDefect]
block:
var dest: array[50, byte]
@ -39,46 +30,39 @@ block:
block:
var hugeIntArray: array[50, byte]
var readedInt: uint64
doAssert writeVu64(hugeIntArray, 0.uint64) == readVu64(hugeIntArray, readedInt)
doAssert readedInt == 0.uint64
doAssert writeVu64(hugeIntArray, uint64.high) == readVu64(hugeIntArray, readedInt)
doAssert readedInt == uint64.high
doAssert writeVu64(hugeIntArray, uint64(int64.high)) == readVu64(hugeIntArray, readedInt)
doAssert readedInt == uint64(int64.high)
doAssert writeVu64(hugeIntArray, uint64(int32.high)) == readVu64(hugeIntArray, readedInt)
doAssert readedInt == uint64(int32.high)
doAssert writeVu64(hugeIntArray, uint64(int16.high)) == readVu64(hugeIntArray, readedInt)
doAssert readedInt == uint64(int16.high)
doAssert writeVu64(hugeIntArray, uint64(int8.high)) == readVu64(hugeIntArray, readedInt)
doAssert readedInt == uint64(int8.high)
doAssert writeVu64(hugeIntArray, cast[uint64](0.0)) == readVu64(hugeIntArray, readedInt)
doAssert readedInt == cast[uint64](0.0)
doAssert writeVu64(hugeIntArray, cast[uint64](-0.0)) == readVu64(hugeIntArray, readedInt)
doAssert readedInt == cast[uint64](-0.0)
doAssert writeVu64(hugeIntArray, cast[uint64](0.1)) == readVu64(hugeIntArray, readedInt)
doAssert readedInt == cast[uint64](0.1)
doAssert writeVu64(hugeIntArray, cast[uint64](0.9555555555555555555555501)) == readVu64(hugeIntArray, readedInt)
doAssert readedInt == cast[uint64](0.9555555555555555555555501)
doAssert writeVu64(hugeIntArray, cast[uint64](+Inf)) == readVu64(hugeIntArray, readedInt)
doAssert readedInt == cast[uint64](+Inf)
doAssert writeVu64(hugeIntArray, cast[uint64](NegInf)) == readVu64(hugeIntArray, readedInt)
doAssert readedInt == cast[uint64](NegInf)
doAssert writeVu64(hugeIntArray, cast[uint64](Nan)) == readVu64(hugeIntArray, readedInt)
doAssert readedInt == cast[uint64](Nan)
doAssert writeVu64(hugeIntArray, cast[uint64](3.1415926535897932384626433)) == readVu64(hugeIntArray, readedInt)
doAssert readedInt == cast[uint64](3.1415926535897932384626433)
doAssert writeVu64(hugeIntArray, cast[uint64](2.71828182845904523536028747)) == readVu64(hugeIntArray, readedInt)
doAssert readedInt == cast[uint64](2.71828182845904523536028747)
template chk(a) =
let b = cast[uint64](a)
doAssert writeVu64(hugeIntArray, b) == readVu64(hugeIntArray, readedInt)
doAssert readedInt == b
chk 0
chk uint64.high
chk int64.high
chk int32.high
chk int16.high
chk int16.high
chk int8.high
chk 0.0
chk -0.0
chk 0.1
chk Inf
chk NegInf
chk Nan
chk 3.1415926535897932384626433
block:
doAssert encodeZigzag(decodeZigzag(0.uint64)) == 0.uint64
doAssert encodeZigzag(decodeZigzag(uint64(uint32.high))) == uint64(uint32.high)
doAssert encodeZigzag(decodeZigzag(uint64(int32.high))) == uint64(int32.high)
doAssert encodeZigzag(decodeZigzag(uint64(int16.high))) == uint64(int16.high)
doAssert encodeZigzag(decodeZigzag(uint64(int8.high))) == uint64(int8.high)
doAssert encodeZigzag(decodeZigzag(cast[uint64](0.0))) == cast[uint64](0.0)
doAssert encodeZigzag(decodeZigzag(cast[uint64](0.1))) == cast[uint64](0.1)
doAssert encodeZigzag(decodeZigzag(cast[uint64](0.9555555555555555555555501))) == cast[uint64](0.9555555555555555555555501)
doAssert encodeZigzag(decodeZigzag(cast[uint64](+Inf))) == cast[uint64](+Inf)
doAssert encodeZigzag(decodeZigzag(cast[uint64](3.1415926535897932384626433))) == cast[uint64](3.1415926535897932384626433)
doAssert encodeZigzag(decodeZigzag(cast[uint64](2.71828182845904523536028747))) == cast[uint64](2.71828182845904523536028747)
template chk(a) =
let b = cast[uint64](a)
doAssert encodeZigzag(decodeZigzag(b)) == b
chk 0
chk uint32.high
chk int32.high
chk int16.high
chk int8.high
chk 0.0
chk 0.1
chk 0.9555555555555555555555501
chk Inf
chk 3.1415926535897932384626433
chk 2.71828182845904523536028747