use crate::Configuration; use std::collections::HashSet; fn check_configs_equal( cfg1: &Configuration, cfg2: &Configuration, ) -> Result<(), Box> { let keys1: HashSet<&str> = cfg1.iter().map(|(k, _)| k).collect(); let keys2: HashSet<&str> = cfg2.iter().map(|(k, _)| k).collect(); for key in keys1.difference(&keys2) { return Err(format!( "Key {key} appears at {}, but not in other configuration", cfg1.location(&key).unwrap() ) .into()); } for key in keys2.difference(&keys1) { return Err(format!( "Key {key} appears at {}, but not in other configuration", cfg2.location(&key).unwrap() ) .into()); } for (key, val1) in cfg1.iter() { let val2 = cfg2.get(&key).unwrap(); if val1 != val2 { return Err(format!( "Mismatch between values for key {key} defined as {val1:?} at {}, but defined as {val2:?} at {}", cfg1.location(&key) .map_or("".into(), |x| format!("{x}")), cfg2.location(&key) .map_or("".into(), |x| format!("{x}")), ) .into()); } } Ok(()) } #[test] fn parsing() { super::do_tests_in_dir("parsing", ".flat.pom", |filename| { let config1 = Configuration::load_path(filename)?; let config2 = Configuration::load_path(&filename.replace(".flat.pom", ".pom"))?; check_configs_equal(&config1, &config2) }) }