From 154cac779a99d6b7f5f5d874a52fa6ebdc888c7f Mon Sep 17 00:00:00 2001 From: ~karx Date: Sun, 7 Feb 2021 19:35:00 +0000 Subject: [PATCH] Add test suite --- src/main.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/main.rs b/src/main.rs index 4905d78..f9d7259 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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(); + } + +} \ No newline at end of file