preserves-nim/tests/test_schemas.nim

41 lines
1.1 KiB
Nim
Raw Normal View History

2021-09-27 13:58:36 +00:00
# SPDX-FileCopyrightText: 2021 ☭ Emery Hemingway
# SPDX-License-Identifier: Unlicense
import std/[tables, options, os, unittest]
2022-04-25 16:44:43 +00:00
import preserves, preserves/schema, preserves/schemaparse
2021-11-11 10:11:40 +00:00
if dirExists "tests": setCurrentDir "tests"
# nimble runs tests in the directory above
2021-09-27 13:58:36 +00:00
suite "schema":
const
2022-02-19 16:33:16 +00:00
binPath = "../schema.bin"
textPath = "../schema.prs"
2021-09-27 13:58:36 +00:00
test "convertability":
if not fileExists(binPath): skip()
else:
var
b = decodePreserves readFile(binPath)
2021-10-17 12:50:27 +00:00
scm = preserveTo(b, Schema[void])
2021-09-27 13:58:36 +00:00
check scm.isSome
if scm.isSome:
var a = toPreserve(get scm)
check(a == b)
2021-11-11 10:11:40 +00:00
test "parser":
if not fileExists(binPath): skip()
else:
var
b = decodePreserves readFile(binPath)
scm = preserveTo(b, Schema[void])
check scm.isSome
if scm.isSome:
var a = toPreserve parsePreservesSchema(readFile textPath, textPath)
let aDefs = a[0][toSymbol "definitions"]
let bDefs = b[0][toSymbol "definitions"]
for (key, val) in aDefs.pairs:
check(bDefs[key] == val)
check(a == b)