forked from Crockan/MercuryToolbox
chore(release): prepare public source release
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
//! Miri regression coverage for compact JSON-family parsers.
|
||||
|
||||
use common::formats::toon::{DecodeOptions, EncodeOptions};
|
||||
use common::formats::{ison, tonl, toon, zon};
|
||||
use serde_json::json;
|
||||
|
||||
#[test]
|
||||
fn toon_roundtrip_exercises_nested_and_tabular_paths() {
|
||||
for value in [
|
||||
json!({
|
||||
"meta": {
|
||||
"ok": true,
|
||||
"count": 2
|
||||
},
|
||||
"items": [
|
||||
{"id": 1, "name": "Ada"},
|
||||
{"id": 2, "name": "Bob"}
|
||||
],
|
||||
"literal.path": "quoted when encoded"
|
||||
}),
|
||||
json!([1, 2, 3]),
|
||||
json!([{"id": 1}, {"id": 2}]),
|
||||
json!("plain"),
|
||||
] {
|
||||
let encoded = toon::encode_value(&value, EncodeOptions::default()).expect("TOON encode");
|
||||
let decoded = toon::decode_str(&encoded, DecodeOptions::default());
|
||||
|
||||
assert_eq!(decoded.expect("TOON decode"), value);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn toon_decoder_rejects_malformed_counts_and_path_conflicts() {
|
||||
let bad_count = toon::decode_str("[3]: a,b\n", DecodeOptions::default());
|
||||
assert!(bad_count.is_err());
|
||||
|
||||
let path_conflict = toon::decode_str(
|
||||
"a: 1\na.b: 2\n",
|
||||
DecodeOptions {
|
||||
expand_paths: common::formats::toon::SafeMode::Safe,
|
||||
..DecodeOptions::default()
|
||||
},
|
||||
);
|
||||
assert!(path_conflict.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn record_formats_decode_without_panicking() {
|
||||
let records = vec![json!({"id": 1, "name": "Ada", "active": true})];
|
||||
let isonl = ison::encode_records(&records, "user").expect("ISONL encode");
|
||||
assert_eq!(ison::decode_records(&isonl).expect("ISONL decode"), records);
|
||||
|
||||
assert_eq!(
|
||||
zon::decode_str("id:1\nname:\"Ada\"\nactive:true\n").expect("ZON decode"),
|
||||
json!({"id": 1, "name": "Ada", "active": true})
|
||||
);
|
||||
|
||||
let tonl = tonl::encode_documents(&[json!({"id": 1, "name": "Ada"})]).expect("TONL encode");
|
||||
assert_eq!(
|
||||
tonl::decode_documents(&tonl).expect("TONL decode"),
|
||||
vec![json!({"id": 1, "name": "Ada"})]
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user