use crate::{json, schema, test, warning};
const TARIFF: &str = r#"{
"country_code": "NLD",
"party_id": "ENE",
"currency": "EUR"
}"#;
#[test]
fn should_find_a_warning_behind_another_on_the_same_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(country_code, schema::Warning::NonSpecField);
warnings.insert(currency, schema::Warning::NullField);
warnings.insert(currency, schema::Warning::UnexpectedField);
let contains_unexpected =
warnings.contains(|warning| matches!(warning, schema::Warning::UnexpectedField));
assert!(contains_unexpected);
}
#[test]
fn should_not_find_a_warning_the_set_lacks() {
test::setup();
let doc = json::parse_object(TARIFF).unwrap();
let root = doc.root();
let currency = root.find_field("currency").unwrap().element();
let mut warnings = warning::Set::<schema::Warning>::new();
warnings.insert(currency, schema::Warning::NullField);
let contains_unexpected =
warnings.contains(|warning| matches!(warning, schema::Warning::UnexpectedField));
assert!(!contains_unexpected);
}