Add test suite

This commit is contained in:
~karx 2021-02-07 19:35:00 +00:00
parent 80f4556786
commit 154cac779a
1 changed files with 27 additions and 0 deletions

View File

@ -128,3 +128,30 @@ fn main() {
let mut prog = Program::from_string(contents);
prog.run();
}
#[cfg(test)]
mod tests {
use super::*;
fn make_program(contents: &str) -> Program {
Program::from_string(contents.to_string())
}
#[test]
fn test_math() {
assert_eq!(eval::do_math("2-2".to_string(), '+'), 4);
}
#[test]
#[should_panic]
fn test_undefined_opcode() {
make_program("Hello\nWorld!").run();
}
#[test]
#[should_panic]
fn test_undefined_variable() {
make_program("p$v").run();
}
}