use dismael::{disassemble, disassemble_to_string};
#[test]
fn test_simple_instruction_disassembly() {
let machine_code = vec![(0b00001 << 11) | 100];
let result = disassemble(&machine_code).unwrap();
assert_eq!(result.len(), 1); assert!(result[0].contains("DOD"));
assert!(result[0].contains("100"));
}
#[test]
fn test_instruction_without_operand() {
let machine_code = vec![0b00111 << 11];
let result = disassemble(&machine_code).unwrap();
assert_eq!(result.len(), 1);
assert!(result[0].contains("STP"));
let lines: Vec<&str> = result[0].lines().collect();
let instruction_line = lines.iter().find(|line| line.trim_start().starts_with("STP")).unwrap();
assert_eq!(instruction_line.trim(), "STP");
}
#[test]
fn test_all_opcodes() {
let instructions = vec![
(0b00001 << 11) | 1, (0b00010 << 11) | 2, (0b00011 << 11) | 3, (0b00100 << 11) | 4, (0b00101 << 11) | 5, (0b00110 << 11) | 6, (0b00111 << 11) | 0, (0b01000 << 11) | 0, (0b01001 << 11) | 0, (0b01010 << 11) | 0, (0b01011 << 11) | 0, (0b01100 << 11) | 11, (0b01101 << 11) | 0, (0b01110 << 11) | 13, (0b01111 << 11) | 14, ];
let expected_mnemonics = vec![
"DOD", "ODE", "ŁAD", "POB", "SOB", "SOM", "STP",
"DNS", "PZS", "SDP", "CZM", "MSK", "PWR", "WEJSCIE", "WYJSCIE"
];
let result = disassemble(&instructions).unwrap();
for (_, expected) in expected_mnemonics.iter().enumerate() {
let instruction_line = result.iter()
.find(|line| line.contains(expected))
.expect(&format!("Could not find instruction {}", expected));
assert!(instruction_line.contains(expected));
}
}
#[test]
fn test_disassemble_to_string() {
let machine_code = vec![
(0b00001 << 11) | 100, (0b00111 << 11) | 0, ];
let result = disassemble_to_string(&machine_code).unwrap();
assert!(result.contains("DOD"));
assert!(result.contains("STP"));
assert!(result.contains("100"));
}