#![allow(missing_docs)]
use noyalib::{ParserConfig, Value, YamlVersion, from_str, from_str_with_config};
#[test]
fn default_is_v1_2() {
let cfg = ParserConfig::new();
assert_eq!(cfg.yaml_version, YamlVersion::V1_2);
assert!(!cfg.legacy_booleans);
assert!(!cfg.legacy_octal_numbers);
assert!(!cfg.legacy_sexagesimal);
}
#[test]
fn v1_1_sets_all_legacy_flags() {
let cfg = ParserConfig::new().version(YamlVersion::V1_1);
assert_eq!(cfg.yaml_version, YamlVersion::V1_1);
assert!(cfg.legacy_booleans);
assert!(cfg.legacy_octal_numbers);
assert!(cfg.legacy_sexagesimal);
}
#[test]
fn v1_2_resets_legacy_flags() {
let cfg = ParserConfig::new()
.version(YamlVersion::V1_1)
.version(YamlVersion::V1_2);
assert_eq!(cfg.yaml_version, YamlVersion::V1_2);
assert!(!cfg.legacy_booleans);
assert!(!cfg.legacy_octal_numbers);
assert!(!cfg.legacy_sexagesimal);
}
#[test]
fn v1_1_resolves_yes_no_on_off_as_bool() {
let cfg = ParserConfig::new().version(YamlVersion::V1_1);
for (yaml, expected) in [
("yes", true),
("no", false),
("on", true),
("off", false),
("Yes", true),
("No", false),
("ON", true),
("OFF", false),
] {
let v: Value = from_str_with_config(yaml, &cfg).unwrap();
assert_eq!(
v,
Value::Bool(expected),
"expected {yaml:?} → Bool({expected})"
);
}
}
#[test]
fn v1_2_keeps_yes_no_on_off_as_strings() {
for yaml in ["yes", "no", "on", "off"] {
let v: Value = from_str(yaml).unwrap();
assert_eq!(v.as_str(), Some(yaml), "1.2 must keep {yaml:?} as string");
}
}
#[test]
fn v1_1_resolves_bare_zero_prefix_as_octal() {
let cfg = ParserConfig::new().version(YamlVersion::V1_1);
let v: Value = from_str_with_config("0644", &cfg).unwrap();
assert_eq!(v, Value::from(420_i64), "0644 octal must equal 420");
}
#[test]
fn v1_2_keeps_bare_zero_prefix_as_decimal() {
let v: Value = from_str("0644").unwrap();
assert_eq!(v, Value::from(644_i64), "1.2 reads 0644 as decimal 644");
}
#[test]
fn v1_1_resolves_colon_separated_as_base60() {
let cfg = ParserConfig::new().version(YamlVersion::V1_1);
for (yaml, expected) in [
("1:30", 90_i64), ("1:30:00", 5_400_i64), ("60:00", 3_600_i64), ] {
let v: Value = from_str_with_config(yaml, &cfg).unwrap();
assert_eq!(v, Value::from(expected), "{yaml} must equal {expected}");
}
}
#[test]
fn v1_2_keeps_colon_separated_as_strings() {
let v: Value = from_str("1:30").unwrap();
assert_eq!(v.as_str(), Some("1:30"));
}
#[test]
fn version_then_individual_override_is_honoured() {
let cfg = ParserConfig::new()
.version(YamlVersion::V1_1)
.legacy_sexagesimal(false);
let v: Value = from_str_with_config("on", &cfg).unwrap();
assert_eq!(v, Value::Bool(true), "1.1 booleans still on");
let v: Value = from_str_with_config("0644", &cfg).unwrap();
assert_eq!(v, Value::from(420_i64), "1.1 octal still on");
let v: Value = from_str_with_config("1:30", &cfg).unwrap();
assert_eq!(
v.as_str(),
Some("1:30"),
"individual override beat the version preset"
);
}
#[test]
fn realistic_v1_1_document_round_trips() {
let yaml = "\
production: yes
debug: off
permissions: 0755
timeout: 1:30
";
let cfg = ParserConfig::new().version(YamlVersion::V1_1);
let v: Value = from_str_with_config(yaml, &cfg).unwrap();
assert_eq!(v["production"], Value::Bool(true));
assert_eq!(v["debug"], Value::Bool(false));
assert_eq!(v["permissions"], Value::from(493_i64)); assert_eq!(v["timeout"], Value::from(90_i64)); }