From 3944ae36a800859a1fd8dc5b8217e24963ef8613 Mon Sep 17 00:00:00 2001 From: Denis-Cosmin NUTIU Date: Sun, 1 Dec 2024 23:10:46 +0200 Subject: [PATCH] add tests for instruction.rs --- src/instruction.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/instruction.rs b/src/instruction.rs index 9a5f0c6..b2fd0ad 100644 --- a/src/instruction.rs +++ b/src/instruction.rs @@ -24,3 +24,34 @@ impl Display for Instruction { )) } } + +impl PartialEq for Instruction { + fn eq(&self, other: &u16) -> bool { + self.data == *other + } +} + +impl LowerHex for Instruction { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + fmt::LowerHex::fmt(&self.data, f) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_instruction_raw() { + let instruction = Instruction::new([0xffu8, 0xffu8]); + + assert_eq!(instruction.raw(), 0xffffu16) + } + + #[test] + fn test_instruction_partial_eq() { + let instruction = Instruction::new([0xffu8, 0xffu8]); + + assert_eq!(instruction, 0xffffu16) + } +}