Refactor.

This commit is contained in:
Stephen Chung
2020-05-10 00:19:13 +08:00
parent a7bfac21bd
commit 80debbc432
6 changed files with 299 additions and 301 deletions

View File

@@ -18,12 +18,7 @@ fn test_module_sub_module() -> Result<(), Box<EvalAltResult>> {
let mut sub_module2 = Module::new();
sub_module2.set_var("answer", 41 as INT);
let hash_inc = sub_module2.set_fn_1("inc", |x: INT| Ok(x + 1), false);
let hash_hidden = sub_module2.set_fn_0(
"hidden",
|| Err("shouldn't see me!".into()) as Result<(), Box<EvalAltResult>>,
true,
);
let hash_inc = sub_module2.set_fn_1("inc", |x: INT| Ok(x + 1));
sub_module.set_sub_module("universe", sub_module2);
module.set_sub_module("life", sub_module);
@@ -36,7 +31,6 @@ fn test_module_sub_module() -> Result<(), Box<EvalAltResult>> {
assert!(m2.contains_var("answer"));
assert!(m2.contains_fn(hash_inc));
assert!(m2.contains_fn(hash_hidden));
assert_eq!(m2.get_var_value::<INT>("answer").unwrap(), 41);
@@ -59,11 +53,6 @@ fn test_module_sub_module() -> Result<(), Box<EvalAltResult>> {
)?,
42
);
assert!(matches!(
*engine.eval_expression_with_scope::<()>(&mut scope, "question::life::universe::hidden()")
.expect_err("should error"),
EvalAltResult::ErrorFunctionNotFound(fn_name, _) if fn_name == "hidden"
));
Ok(())
}