# SPDX-License-Identifier: ISC import std/[options, 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.isSome and (get(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 tup: Foobar = (a: 1, b: 2, c: Bar(s: "ku",)) prs = toPreserve(tup) check(prs.kind == pkRecord) check($prs == """>""") check(preserveTo(prs, Foobar) == some(tup)) check(classOf(tup) == classOf(prs)) suite "%": template check(p: Preserve; s: string) = test s: check($p == s) check %false, "#f" check %[0, 1, 2, 3], "[0 1 2 3]" #check %*{0, 1, 2, 3}, """#{ #t #f }"""