Refactor tests.

This commit is contained in:
Stephen Chung
2020-03-02 22:11:56 +08:00
parent ed8d2ac20f
commit 0707fad1ca
27 changed files with 338 additions and 317 deletions

View File

@@ -1,28 +1,16 @@
use rhai::{Engine, Scope};
use rhai::{Engine, EvalAltResult, Scope};
#[test]
fn test_var_scope() {
fn test_var_scope() -> Result<(), EvalAltResult> {
let mut engine = Engine::new();
let mut scope = Scope::new();
assert_eq!(
engine.eval_with_scope::<()>(&mut scope, "let x = 4 + 5"),
Ok(())
);
engine.eval_with_scope::<()>(&mut scope, "let x = 4 + 5")?;
assert_eq!(engine.eval_with_scope::<i64>(&mut scope, "x")?, 9);
engine.eval_with_scope::<()>(&mut scope, "x = x + 1; x = x + 2;")?;
assert_eq!(engine.eval_with_scope::<i64>(&mut scope, "x")?, 12);
assert_eq!(engine.eval_with_scope::<()>(&mut scope, "{let x = 3}")?, ());
assert_eq!(engine.eval_with_scope::<i64>(&mut scope, "x")?, 12);
assert_eq!(engine.eval_with_scope::<i64>(&mut scope, "x"), Ok(9));
assert_eq!(
engine.eval_with_scope::<()>(&mut scope, "x = x + 1; x = x + 2;"),
Ok(())
);
assert_eq!(engine.eval_with_scope::<i64>(&mut scope, "x"), Ok(12));
assert_eq!(
engine.eval_with_scope::<()>(&mut scope, "{let x = 3}"),
Ok(())
);
assert_eq!(engine.eval_with_scope::<i64>(&mut scope, "x"), Ok(12));
Ok(())
}