//! Rungs 1 and 5, natively, through the same function the wasm export calls. use std::fs; use std::path::Path; use z80_wasm::check::check_manifest; fn run_dir(rung: &str) -> Vec<(String, bool)> { let dir = Path::new(env!("CARGO_MANIFEST_DIR")) .join("conformance") .join(rung); let mut names: Vec = fs::read_dir(&dir) .unwrap() .filter_map(|entry| { let path = entry.unwrap().path(); (path.extension()? == "json") .then(|| path.file_stem().unwrap().to_string_lossy().into_owned()) }) .collect(); names.sort(); names .into_iter() .map(|name| { let manifest = fs::read_to_string(dir.join(format!("{name}.json"))).unwrap(); let reference = fs::read_to_string(dir.join(format!("{name}.jsonl"))).unwrap(); let result = check_manifest(&manifest, &reference).unwrap_or_else(|e| panic!("{name}: {e}")); assert!(result.identical(), "{name}: {}", result.to_json()); (name, result.identical()) }) .collect() } #[test] fn rung1_three_example_manifests_identical() { assert_eq!(run_dir("rung1").len(), 3); } #[test] fn rung5_ten_interrupt_manifests_identical() { assert_eq!(run_dir("rung5").len(), 10); } #[test] fn a_wrong_reference_is_reported_at_its_index() { let dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("conformance/rung1"); let manifest = fs::read_to_string(dir.join("flags-and-branches.json")).unwrap(); let reference = fs::read_to_string(dir.join("flags-and-branches.jsonl")).unwrap(); let mut lines: Vec = reference.lines().map(str::to_string).collect(); lines[5] = lines[5].replacen("\"t_states\":", "\"t_states\":9", 1); let result = check_manifest(&manifest, &lines.join("\n")).unwrap(); assert!(!result.identical()); assert_eq!(result.first_difference.unwrap().index, 5); }