diff --git a/src/overview/mod.rs b/src/overview/mod.rs index 0b2a384..e8602e7 100644 --- a/src/overview/mod.rs +++ b/src/overview/mod.rs @@ -115,28 +115,32 @@ fn fetch_page(overview_id: usize, page: usize) -> Result { #[cfg(test)] mod tests { - use crate::overview::parse; + use crate::{config::Config, overview::parse}; use pretty_assertions::assert_eq; use std::fs; #[test] fn overview() { - let paths = fs::read_dir("./data/expected/overview/") - .expect("No folder with expected overview files"); + let configs = fs::read_dir("./data/configs").expect("No folder with config files"); - for path in paths { - let path = path.unwrap(); - let file_path = format!("{}", path.path().display()); - let law_id = path.file_name().into_string().unwrap().to_string(); - let law_id: usize = law_id - .parse() - .expect("Filename needs to be usize (= law_id in RIS)"); + for config in configs { + let path = format!("{}", config.unwrap().path().display()); - let expected = fs::read_to_string(file_path).expect("Could not read file {file_path}."); - let expected = expected.trim().split('\n').collect::>(); + let (law_id, _, _) = Config::load(&path).unwrap(); let actual = parse(law_id).unwrap(); - assert_eq!(actual, expected); + let expected_path = format!("./data/expected/overview/{law_id}"); + match fs::read_to_string(&expected_path) { + Ok(expected) => { + let expected = expected.trim().split('\n').collect::>(); + + assert_eq!(actual, expected); + } + Err(_) => { + let to_write = actual.join("\n"); + fs::write(expected_path, to_write).expect("Unable to write file"); + } + } } } }