New roundtripTest helper that checks the serialized value as well

This commit is contained in:
Zahary Karadjov 2019-06-24 16:46:23 +03:00
parent 060c8fd9bf
commit 3a56635499
1 changed files with 9 additions and 1 deletions

View File

@ -29,12 +29,20 @@ type
proc default(T: typedesc): T = discard
template roundripTest*(Format: type, val: auto) =
template roundtripTest*(Format: type, val: auto) =
test Format.name & " " & val.type.name & " roundtrip":
let v = val
let serialized = Format.encode(v)
check: Format.decode(serialized, v.type) == v
template roundtripTest*(Format: type, value: auto, expectedResult: auto) =
test Format.name & " " & val.type.name & " roundtrip":
let v = value
let serialized = Format.encode(v)
check:
serialized = expectedResult
Format.decode(serialized, v.type) == v
proc executeReaderWriterTests*(Format: type) =
mixin init, ReaderType, WriterType