#![feature(decl_macro)]

extern crate mer;

use mer::{Elf, ElfError};

macro assert_err($name: ident, $elf: expr, $error: path) {
    #[test]
    fn $name() {
        let elf = Elf::new($elf);
        assert!(elf.is_err());
        let error = elf.err().unwrap();
        assert!(
            error == $error,
            "Incorrect error on '{}': {:?}",
            stringify!($name),
            error
        );
    }
}

/// An empty byte stream should return an error because it's too short to contain a valid ELF
assert_err!(no_bits, &[], ElfError::TooShort);

/// Check that a byte stream with nothing but the correct magic number is also too short
assert_err!(only_magic, &[0x7f, b'E', b'L', b'F'], ElfError::TooShort);
