preserves-nim/tests/test_rfc8259.nim

70 lines
1.4 KiB
Nim
Raw Normal View History

# SPDX-FileCopyrightText: 2021 ☭ Emery Hemingway
2021-08-31 15:00:00 +00:00
# SPDX-License-Identifier: Unlicense
2021-06-02 13:51:36 +00:00
import preserves, preserves/jsonhooks
2021-08-28 10:48:50 +00:00
import std/[json, jsonutils, streams, unittest]
2021-06-02 13:51:36 +00:00
let testVectors = [
"""
{
"Image": {
"Width": 800,
"Height": 600,
"Title": "View from 15th Floor",
"Thumbnail": {
"Url": "http://www.example.com/image/481989943",
"Height": 125,
"Width": 100
},
"Animated": false,
"IDs": [
116,
943,
234,
38793
]
}
}
""",
"""
[
{
"space": "C3D2",
"logo": "https://www.c3d2.de/images/ck.png",
"url": "https://www.c3d2.de/",
"location": {
"address": "Raum 1.04.01, Haus B, Zentralwerk, Riesaer Straße 32, 01127 Dresden, Germany",
"lat": 51.0810791,
"lon": 13.7286123
}
2021-06-02 13:51:36 +00:00
},
{
"space": "LAG",
"logo": "http://laglab.org/logo.png",
"url": "http://laglab.org",
"location": {
"address": "Eerste Schinkelstraat 16, 1075 TX Amsterdam, The Netherlands",
"lat": 52.35406,
"lon": 4.85423
}
2021-06-02 13:51:36 +00:00
}
]
"""
]
for i, jsText in testVectors:
test $i:
checkpoint(jsText)
2021-06-02 13:51:36 +00:00
let
control = parseJson jsText
x = control.toPreserves
checkpoint($x)
2021-06-02 13:51:36 +00:00
var stream = newStringStream()
stream.write(x)
stream.setPosition(0)
let
2021-07-16 17:11:19 +00:00
y = stream.decodePreserves()
2021-06-02 13:51:36 +00:00
test = y.toJson
check(y == x)
check(test == control)