preserves-nim/tests/test_conversions.nim

34 lines
857 B
Nim

# SPDX-License-Identifier: ISC
import streams, strutils, unittest
import bigints, preserves, preserves/records
suite "conversions":
test "dictionary":
type Bar = object
s: string
type Foobar = tuple
a, b: int
c: Bar
let
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":
type Bar {.record: "bar".} = object
s: string
type Foobar {.record: "foo".} = tuple
a, b: int
c: Bar
let
c: Foobar = (a: 1, b: 2, c: Bar(s: "ku",))
b = toPreserve(c)
a = preserveTo(b, Foobar)
check(a == c)
check(b.kind == pkRecord)
check(classOf(c) == RecordClass(label: symbol"foo", arity: 3))
check(classOf(Foobar) == RecordClass(label: symbol"foo", arity: 3))