1
0

Oraganize test

This commit is contained in:
Jeff 2024-12-14 16:18:50 -05:00
parent 9d544d789c
commit b59d51d620
2 changed files with 47 additions and 46 deletions

View File

@ -249,49 +249,3 @@ impl Display for Pointer {
} }
} }
} }
#[cfg(test)]
mod tests {
use runner::{RunnerLogic, RUNNER_LOGIC_TABLE};
use super::*;
const ALL_OPERATIONS: [(Operation, RunnerLogic); 24] = [
(Operation::MOVE, runner::r#move),
(Operation::CLOSE, runner::close),
(Operation::LOAD_BOOLEAN, runner::load_boolean),
(Operation::LOAD_CONSTANT, runner::load_constant),
(Operation::LOAD_LIST, runner::load_list),
(Operation::LOAD_SELF, runner::load_self),
(Operation::GET_LOCAL, runner::get_local),
(Operation::SET_LOCAL, runner::set_local),
(Operation::ADD, runner::add),
(Operation::SUBTRACT, runner::subtract),
(Operation::MULTIPLY, runner::multiply),
(Operation::DIVIDE, runner::divide),
(Operation::MODULO, runner::modulo),
(Operation::TEST, runner::test),
(Operation::TEST_SET, runner::test_set),
(Operation::EQUAL, runner::equal),
(Operation::LESS, runner::less),
(Operation::LESS_EQUAL, runner::less_equal),
(Operation::NEGATE, runner::negate),
(Operation::NOT, runner::not),
(Operation::CALL, runner::call),
(Operation::CALL_NATIVE, runner::call_native),
(Operation::JUMP, runner::jump),
(Operation::RETURN, runner::r#return),
];
#[test]
fn operations_map_to_the_correct_runner() {
for (operation, expected_runner) in ALL_OPERATIONS {
let actual_runner = RUNNER_LOGIC_TABLE[operation.0 as usize];
assert_eq!(
expected_runner, actual_runner,
"{operation} runner is incorrect"
);
}
}
}

View File

@ -633,3 +633,50 @@ pub fn r#return(vm: &mut Vm, instruction_data: InstructionData) {
panic!("Stack underflow"); panic!("Stack underflow");
} }
} }
#[cfg(test)]
mod tests {
use crate::Operation;
use super::*;
const ALL_OPERATIONS: [(Operation, RunnerLogic); 24] = [
(Operation::MOVE, r#move),
(Operation::CLOSE, close),
(Operation::LOAD_BOOLEAN, load_boolean),
(Operation::LOAD_CONSTANT, load_constant),
(Operation::LOAD_LIST, load_list),
(Operation::LOAD_SELF, load_self),
(Operation::GET_LOCAL, get_local),
(Operation::SET_LOCAL, set_local),
(Operation::ADD, add),
(Operation::SUBTRACT, subtract),
(Operation::MULTIPLY, multiply),
(Operation::DIVIDE, divide),
(Operation::MODULO, modulo),
(Operation::TEST, test),
(Operation::TEST_SET, test_set),
(Operation::EQUAL, equal),
(Operation::LESS, less),
(Operation::LESS_EQUAL, less_equal),
(Operation::NEGATE, negate),
(Operation::NOT, not),
(Operation::CALL, call),
(Operation::CALL_NATIVE, call_native),
(Operation::JUMP, jump),
(Operation::RETURN, r#return),
];
#[test]
fn operations_map_to_the_correct_runner() {
for (operation, expected_runner) in ALL_OPERATIONS {
let actual_runner = RUNNER_LOGIC_TABLE[operation.0 as usize];
assert_eq!(
expected_runner, actual_runner,
"{operation} runner is incorrect"
);
}
}
}