1
0
Fork 0
mirror of https://tildegit.org/karx/sandwich.git synced 2024-05-19 05:25:48 -05:00

Add test suite

This commit is contained in:
~karx 2021-02-07 19:35:00 +00:00
parent 80f4556786
commit 154cac779a

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();
}
}