Add test to make sure call_fn does not pollute scope.

This commit is contained in:
Stephen Chung 2020-11-06 13:41:04 +08:00
parent 3f6db1d9d4
commit c6ef2d1e95

View File

@ -38,6 +38,10 @@ fn test_call_fn() -> Result<(), Box<EvalAltResult>> {
fn hello() {
41 + foo
}
fn define_var() {
let bar = 21;
bar * 2
}
",
)?;
@ -50,6 +54,11 @@ fn test_call_fn() -> Result<(), Box<EvalAltResult>> {
let r: INT = engine.call_fn(&mut scope, &ast, "hello", ())?;
assert_eq!(r, 42);
let r: INT = engine.call_fn(&mut scope, &ast, "define_var", ())?;
assert_eq!(r, 42);
assert!(!scope.contains("bar"));
assert_eq!(
scope
.get_value::<INT>("foo")