use crate::{
json, schema, test,
warning::{self, Warning as _},
};
const TARIFF: &str = r#"{
"country_code": "NLD",
"party_id": "ENE",
"currency": "EUR"
}"#;
#[test]
fn should_yield_every_warning_paired_with_its_own_element() {
test::setup();
let doc = json::parse_object(TARIFF).unwrap();
let root = doc.root();
let country_code = root.find_field("country_code").unwrap().element();
let currency = root.find_field("currency").unwrap().element();
let mut warnings = warning::Set::<schema::Warning>::new();
warnings.insert(currency, schema::Warning::NullField);
warnings.insert(currency, schema::Warning::UnexpectedField);
warnings.insert(country_code, schema::Warning::NonSpecField);
let pairs: Vec<(&str, String)> = warnings
.iter_warnings()
.map(|(element, warning)| (element.path.as_str(), warning.id().as_str().to_owned()))
.collect();
assert_eq!(
pairs,
[
("$.country_code", "non_spec_field".to_owned()),
("$.currency", "null_field".to_owned()),
("$.currency", "unexpected_field".to_owned()),
]
);
}