Add set_value to Scope.

This commit is contained in:
Stephen Chung
2020-04-05 19:17:48 +08:00
parent 44d6a5e466
commit c4498d147d
3 changed files with 48 additions and 10 deletions

View File

@@ -9,8 +9,12 @@ fn test_var_scope() -> Result<(), EvalAltResult> {
assert_eq!(engine.eval_with_scope::<INT>(&mut scope, "x")?, 9);
engine.eval_with_scope::<()>(&mut scope, "x = x + 1; x = x + 2;")?;
assert_eq!(engine.eval_with_scope::<INT>(&mut scope, "x")?, 12);
scope.set_value("x", 42 as INT);
assert_eq!(engine.eval_with_scope::<INT>(&mut scope, "x")?, 42);
engine.eval_with_scope::<()>(&mut scope, "{let x = 3}")?;
assert_eq!(engine.eval_with_scope::<INT>(&mut scope, "x")?, 12);
assert_eq!(engine.eval_with_scope::<INT>(&mut scope, "x")?, 42);
Ok(())
}