use dez80::Instruction; use std::io::{BufRead, BufReader}; #[test] fn decode_official_instructions() { // Read the compiled instructions using a buffered reader. let input_bytes: &[u8] = include_bytes!("allinstructions.bin"); let mut reader = BufReader::new(input_bytes); // Decode instructions in the byte stream. let instructions = Instruction::decode_all(&mut reader); // Format decoded instructions to their mnemonic representations. let formatted = instructions.iter().map(|i| i.to_string()).collect::>(); // Read the expected output mnemonics using a buffered reader. let input_text: &[u8] = include_bytes!("allinstructions.asm"); reader = BufReader::new(input_text); // Compare the expected output with the generated one for each instruction. for (expected, actual) in reader.lines().zip(formatted.iter()) { assert_eq!(expected.unwrap(), *actual); } // Compare the source opcode bytes to the ones generated by `Instruction::to_bytes()`. for (expected, actual) in input_bytes.iter().zip(instructions.iter().flat_map(|x| x.to_bytes())) { assert_eq!(*expected, actual); } }