rhai/tests/var_scope.rs

17 lines
607 B
Rust
Raw Normal View History

2020-03-02 15:11:56 +01:00
use rhai::{Engine, EvalAltResult, Scope};
2017-11-03 17:58:51 +01:00
#[test]
2020-03-02 15:11:56 +01:00
fn test_var_scope() -> Result<(), EvalAltResult> {
2017-11-03 17:58:51 +01:00
let mut engine = Engine::new();
2019-09-18 12:21:07 +02:00
let mut scope = Scope::new();
2017-11-03 17:58:51 +01:00
2020-03-02 15:11:56 +01:00
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);
2017-11-03 17:58:51 +01:00
2020-03-02 15:11:56 +01:00
Ok(())
2017-11-03 17:58:51 +01:00
}