preserves-nim/tests/test_rfc8259.nim

68 lines
1.1 KiB
Nim
Raw Normal View History

2021-06-02 13:51:36 +00:00
# SPDX-License-Identifier: ISC
import json, streams, unittest
import preserves
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
]
}
}
""",
"""
[
{
"precision": "zip",
"Latitude": 37.7668,
"Longitude": -122.3959,
"Address": "",
"City": "SAN FRANCISCO",
"State": "CA",
"Zip": "94107",
"Country": "US"
},
{
"precision": "zip",
"Latitude": 37.371991,
"Longitude": -122.02602,
"Address": "",
"City": "SUNNYVALE",
"State": "CA",
"Zip": "94085",
"Country": "US"
}
]
"""
]
for i, jsText in testVectors:
test $i:
let
control = parseJson jsText
x = control.toPreserve
var stream = newStringStream()
stream.write(x)
stream.setPosition(0)
let
y = stream.parsePreserve()
test = y.toJson
check(y == x)
check(test == control)