use rust_yaml::Yaml;
use std::panic::{AssertUnwindSafe, catch_unwind};
const MALFORMED_INPUTS: &[(&str, &str)] = &[
("bare flow seq close", "]"),
("bare flow seq close after start", "[}"),
("flow seq close after key marker", "? ]"),
("bare flow map close", "}"),
("flow mapping close after seq start", "[}"),
("nested explicit key with truncation", "?\n a: b\n?"),
("dangling colon", ":"),
("dangling dash", "-"),
("only directive marker", "---"),
("only doc end", "..."),
("nested brackets unclosed", "[[[[[[[[[[[[[[[[[[[["),
("nested braces unclosed", "{{{{{{{{{{{{{{{{{{{{"),
("flow seq with bare commas", "[,,,,]"),
("flow map with bare colons", "{::::}"),
("alt close then open", "]["),
("explicit-key without colon then close", "? a ]"),
("explicit-key without colon then map close", "? a }"),
("leading tab indent", "\t- a\n\t- b"),
("only indent then nothing", " "),
];
#[test]
fn malformed_inputs_never_panic() {
let yaml = Yaml::new();
for (label, input) in MALFORMED_INPUTS {
let result = catch_unwind(AssertUnwindSafe(|| {
let _ = yaml.load_str(input);
}));
assert!(
result.is_ok(),
"input '{label}' (`{input:?}`) panicked — must return Err instead"
);
}
}