use crate::{
json, schema, test,
warning::{self, Warning as _},
};
const TARIFF: &str = r#"{
"country_code": "NLD",
"party_id": "ENE",
"currency": "EUR"
}"#;
#[test]
fn should_group_by_elem() {
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 mut iter = warnings.iter();
let (country_code_elem, country_code_warnings) = iter.next().unwrap().to_parts();
assert_eq!(country_code_elem.path.as_str(), "$.country_code");
let ids: Vec<String> = country_code_warnings
.iter()
.map(|w| w.id().as_str().to_owned())
.collect();
assert_eq!(ids, ["non_spec_field"]);
let (currency_elem, currency_warnings) = iter.next().unwrap().to_parts();
assert_eq!(currency_elem.path.as_str(), "$.currency");
let ids: Vec<String> = currency_warnings
.iter()
.map(|w| w.id().as_str().to_owned())
.collect();
assert_eq!(ids, ["null_field", "unexpected_field"]);
assert!(iter.next().is_none(), "No more warning groups expected");
assert!(country_code_elem.id < currency_elem.id);
}