mirror of
https://github.com/storytold/craft-anything.git
synced 2026-11-19 14:00:52 +01:00
Replays #688 and #690–#715. DEX, Java, SQLite, Android, ZIP, ASAR, file system, PyInstaller, JSON config and packet parsers keep to their declared lengths and refuse impossible values. Co-authored-by: Afloat <132809511+Afloat16@users.noreply.github.com>
21 lines
945 B
Rust
21 lines
945 B
Rust
use craft_anything_formats::jsonc::parse;
|
|
use serde_json::json;
|
|
|
|
#[test]
|
|
fn the_first_setting_keeps_comment_only_documents() {
|
|
for original in
|
|
["// local preferences\n", "// local preferences", "/* keep this explanation */\n\n", "\u{feff}// local preferences\n", "\u{feff}", " \t\r\n"]
|
|
{
|
|
let edited = parse(original, false).unwrap().set(&["mcp", "servers", "sample"], &json!({"command": "sample-cli"})).unwrap();
|
|
assert!(edited.starts_with(original), "lost the original prefix: {edited:?}");
|
|
assert_eq!(parse(&edited, false).unwrap().get(&["mcp", "servers", "sample"]), Some(json!({"command": "sample-cli"})));
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn a_truly_empty_file_still_gets_a_fresh_object() {
|
|
let edited = parse("", true).unwrap().set(&["enabled"], &json!(true)).unwrap();
|
|
assert_eq!(edited, "{\n \"enabled\": true\n}\n");
|
|
assert_eq!(parse(&edited, true).unwrap().get(&["enabled"]), Some(json!(true)));
|
|
}
|