Add test suite
This commit is contained in:
parent
80f4556786
commit
154cac779a
27
src/main.rs
27
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();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue