#![deny(clippy::all)]
use std::borrow::Cow;
use yamp::{YamlValue, emit, parse};
#[test]
fn test_emit_non_standard_booleans_as_strings() {
let yaml = r#"
test_yes: yes
test_no: no
test_on: on
test_off: off
test_true: true
test_false: false
"#;
let parsed = parse(yaml).expect("Failed to parse");
if let YamlValue::Object(map) = &parsed.value {
assert!(
matches!(map.get(&Cow::Borrowed("test_yes")).unwrap().value, YamlValue::String(ref s) if s == "yes")
);
assert!(
matches!(map.get(&Cow::Borrowed("test_no")).unwrap().value, YamlValue::String(ref s) if s == "no")
);
assert!(
matches!(map.get(&Cow::Borrowed("test_on")).unwrap().value, YamlValue::String(ref s) if s == "on")
);
assert!(
matches!(map.get(&Cow::Borrowed("test_off")).unwrap().value, YamlValue::String(ref s) if s == "off")
);
assert!(
matches!(map.get(&Cow::Borrowed("test_true")).unwrap().value, YamlValue::String(ref s) if s == "true")
);
assert!(
matches!(map.get(&Cow::Borrowed("test_false")).unwrap().value, YamlValue::String(ref s) if s == "false")
);
}
let emitted = emit(&parsed);
assert!(emitted.contains("test_yes: yes"));
assert!(emitted.contains("test_no: no"));
assert!(emitted.contains("test_on: on"));
assert!(emitted.contains("test_off: off"));
assert!(emitted.contains("test_true: \"true\""));
assert!(emitted.contains("test_false: \"false\""));
}
#[test]
fn test_roundtrip_boolean_strings() {
let yaml = "bool_string: yes\ntrue_bool: true";
let parsed = parse(yaml).expect("Failed to parse");
let emitted = emit(&parsed);
let reparsed = parse(&emitted).expect("Failed to reparse");
if let YamlValue::Object(original_map) = &parsed.value
&& let YamlValue::Object(reparsed_map) = &reparsed.value
{
assert!(
matches!(original_map.get(&Cow::Borrowed("bool_string")).unwrap().value, YamlValue::String(ref s) if s == "yes")
);
assert!(
matches!(reparsed_map.get(&Cow::Borrowed("bool_string")).unwrap().value, YamlValue::String(ref s) if s == "yes")
);
assert!(
matches!(original_map.get(&Cow::Borrowed("true_bool")).unwrap().value, YamlValue::String(ref s) if s == "true")
);
assert!(
matches!(reparsed_map.get(&Cow::Borrowed("true_bool")).unwrap().value, YamlValue::String(ref s) if s == "true")
);
}
}