summaryrefslogtreecommitdiff
path: root/test/test.rs
blob: 3fe9dbe1a5db39b2a82d1968e7810629f98dd432 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use yaxpeax_arch::Decoder;

fn test_display(data: &[u8], expected: &'static str) {
    let mut reader = yaxpeax_arch::U8Reader::new(data);
    match yaxpeax_lc87::InstDecoder::default().decode(&mut reader) {
        Ok(instr) => {
            let displayed = instr.to_string();
            assert_eq!(&displayed, expected);
            assert_eq!(data.len() as u8, instr.len());
        }
        Err(e) => {
            panic!("failed to decode {:02x?}: {}", data, e);
        }
    }
}

#[test]
fn test_disassembly() {
//    test_display(&[0x43, 0x0a, 0x1f], "mov #13h, spl");
    test_display(&[0x43, 0x0a, 0x1f], "mov #1fh, fe0ah");
//    test_display(&[0x43, 0x0b, 0x00], "mov #00h, sph");
    test_display(&[0x43, 0x0b, 0x00], "mov #00h, fe0bh");
    test_display(&[0x47, 0x34, 0x12], "ldw #1234h");
    test_display(&[0x47, 0x78, 0x56], "ldw #5678h");
    test_display(&[0x97, 0x12, 0xfe], "stw fe12h");
    test_display(&[0x97, 0xc0, 0x00], "stw 00c0h");
    test_display(&[0x49, 0x00], "rcall $+0x100");
    test_display(&[0x59, 0x00], "rcall $+0x900");
    test_display(&[0x08, 0x10, 0x3f], "bp 0010h, 0, $+0x3f");
    test_display(&[0x0a, 0x10, 0x3f], "bp 0010h, 2, $+0x3f");
}