#![allow(clippy::unwrap_used)]
mod compare;
use compare::{difference, microsofts};
use d3d9_reader::{Options, disassemble_with};
use std::path::Path;
#[test]
fn assembled_programs_list_as_microsofts_disassembler_lists_them() {
let here = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/assembled");
let mut programs: Vec<_> = std::fs::read_dir(&here)
.unwrap()
.map(|entry| entry.unwrap().path())
.filter(|p| p.extension().is_some_and(|e| e == "bin"))
.collect();
programs.sort();
let mut differing = Vec::new();
let mut compared = 0;
for program in &programs {
let stem = program.file_stem().unwrap().to_str().unwrap();
let bytes = std::fs::read(program).unwrap();
for (flags, ending) in [(0u32, "asm.ms"), (0x04, "flag04.ms")] {
let theirs = microsofts(&std::fs::read(here.join(format!("{stem}.{ending}"))).unwrap());
let ours = disassemble_with(&bytes, &Options::from_flags(flags).unwrap()).unwrap();
compared += 1;
differing.extend(difference(&format!("{stem} flags 0x{flags:02x}"), &ours, &theirs));
}
}
assert!(
differing.is_empty(),
"{} of {compared} listings differ:\n{}",
differing.len(),
differing.join("\n")
);
assert_eq!(compared, 574);
}