mirror of
https://github.com/status-im/nim-serialization.git
synced 2025-02-17 14:36:27 +00:00
New roundtripTest helper that checks the serialized value as well
This commit is contained in:
parent
060c8fd9bf
commit
3a56635499
@ -29,12 +29,20 @@ type
|
|||||||
|
|
||||||
proc default(T: typedesc): T = discard
|
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":
|
test Format.name & " " & val.type.name & " roundtrip":
|
||||||
let v = val
|
let v = val
|
||||||
let serialized = Format.encode(v)
|
let serialized = Format.encode(v)
|
||||||
check: Format.decode(serialized, v.type) == 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) =
|
proc executeReaderWriterTests*(Format: type) =
|
||||||
mixin init, ReaderType, WriterType
|
mixin init, ReaderType, WriterType
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user