61 lines
1.6 KiB
Rust
61 lines
1.6 KiB
Rust
//! Integration coverage for the shared TOON core exposed by `common`.
|
|
|
|
use common::formats::toon::{DecodeOptions, Delimiter, EncodeOptions, SafeMode};
|
|
use serde_json::json;
|
|
|
|
#[test]
|
|
fn common_toon_encoder_handles_nested_and_tabular_values() {
|
|
let rendered = common::formats::toon::encode_value(
|
|
&json!({
|
|
"context": {
|
|
"task": "Shared TOON core",
|
|
"location": "common",
|
|
},
|
|
"items": [
|
|
{"id": 1, "name": "Ada"},
|
|
{"id": 2, "name": "Bob"},
|
|
],
|
|
}),
|
|
EncodeOptions {
|
|
indent: 2,
|
|
delimiter: Delimiter::Comma,
|
|
key_folding: SafeMode::Off,
|
|
flatten_depth: usize::MAX,
|
|
},
|
|
)
|
|
.expect("encode");
|
|
|
|
assert_eq!(
|
|
rendered,
|
|
"context:\n task: \"Shared TOON core\"\n location: common\nitems[2]{id,name}:\n 1,Ada\n 2,Bob"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn common_toon_decoder_handles_tabular_values_and_path_expansion() {
|
|
let decoded = common::formats::toon::decode_str(
|
|
"data.metadata.items[2]: a,b\nrows[2]{id,name}:\n 1,Ada\n 2,Bob\n",
|
|
DecodeOptions {
|
|
indent: 2,
|
|
strict: true,
|
|
expand_paths: SafeMode::Safe,
|
|
},
|
|
)
|
|
.expect("decode should succeed");
|
|
|
|
assert_eq!(
|
|
decoded,
|
|
json!({
|
|
"data": {
|
|
"metadata": {
|
|
"items": ["a", "b"],
|
|
},
|
|
},
|
|
"rows": [
|
|
{"id": 1, "name": "Ada"},
|
|
{"id": 2, "name": "Bob"},
|
|
],
|
|
})
|
|
);
|
|
}
|