From d13c22a473b0b5929826d671d62278d24f9e61fd Mon Sep 17 00:00:00 2001 From: Alex Bethel Date: Sun, 30 May 2021 13:24:16 -0500 Subject: [PATCH] More thorough unit tests --- src/interpret.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/interpret.rs b/src/interpret.rs index d1e2230f..4f3dc4a6 100644 --- a/src/interpret.rs +++ b/src/interpret.rs @@ -320,6 +320,18 @@ mod tests { position: _, }) )); + + // And the same for divide by zero. + assert!(matches!( + env.eval_items(&[Item::Expr(Expr::Divide { + left: Box::new(Expr::Literal(Value::Int(1))), + right: Box::new(Expr::Literal(Value::Int(0))), + })]), + Err(Error { + kind: ErrorKind::ArithmeticError, + position: _, + }) + )); } // From here on out, I'll use this function to parse and run @@ -347,6 +359,10 @@ mod tests { eval(&mut ExecEnv::new(), "var bar = 10; bar = 20; bar").unwrap(), Value::Int(20) ); + + // But variable assignment should be illegal when the variable + // hasn't been declared in advance. + eval(&mut ExecEnv::new(), "baz = 10;").unwrap_err(); } #[test]