preserves-nim/tests/test_conversions.nim

32 lines
758 B
Nim
Raw Normal View History

# SPDX-License-Identifier: ISC
import streams, strutils, unittest
import bigints, preserves, preserves/records
suite "conversions":
test "dictionary":
2021-07-01 10:48:07 +00:00
type Bar = object
s: string
2021-07-01 10:48:07 +00:00
type Foobar = tuple
a, b: int
c: Bar
let
2021-07-01 10:48:07 +00:00
c: Foobar = (a: 1, b: 2, c: Bar(s: "ku",))
b = toPreserve(c)
a = preserveTo(b, Foobar)
check(a == c)
check(b.kind == pkDictionary)
test "records":
2021-07-01 10:48:07 +00:00
type Bar {.record: "bar".} = object
s: string
2021-07-01 10:48:07 +00:00
type Foobar {.record: "foo".} = tuple
a, b: int
c: Bar
let
tup: Foobar = (a: 1, b: 2, c: Bar(s: "ku",))
prs = toPreserve(tup)
check(prs.kind == pkRecord)
check(preserveTo(prs, Foobar) == tup)
check(classOf(tup) == classOf(prs))