#![allow(dead_code)] use crate::assembler::Opcode; #[derive(Debug, PartialEq)] pub struct Instruction { opcode: Opcode, } impl Instruction { pub fn new(opcode: Opcode) -> Self { Instruction { opcode } } } #[cfg(test)] mod instruction_tests { use crate::assembler::Opcode; use crate::instruction::*; use nom::types::CompleteStr; #[test] fn test_crate_hlt() { let opcode = Opcode::HLT; assert_eq!(opcode, Opcode::HLT); } #[test] fn test_create_instruction() { let inst = Instruction::new(Opcode::HLT); assert_eq!(inst.opcode, Opcode::HLT); } #[test] fn test_str_to_opcode() { let opcode = Opcode::from(CompleteStr("load")); assert_eq!(opcode, Opcode::LOAD); let opcode = Opcode::from(CompleteStr("add")); assert_eq!(opcode, Opcode::ADD); let opcode = Opcode::from(CompleteStr("illegal")); assert_eq!(opcode, Opcode::IGL); } }