From c6ef2d1e958ec77741184162a15b9ef7e05c26fb Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Fri, 6 Nov 2020 13:41:04 +0800 Subject: [PATCH] Add test to make sure call_fn does not pollute scope. --- tests/call_fn.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/call_fn.rs b/tests/call_fn.rs index 7e9170b0..7b959472 100644 --- a/tests/call_fn.rs +++ b/tests/call_fn.rs @@ -38,6 +38,10 @@ fn test_call_fn() -> Result<(), Box> { fn hello() { 41 + foo } + fn define_var() { + let bar = 21; + bar * 2 + } ", )?; @@ -50,6 +54,11 @@ fn test_call_fn() -> Result<(), Box> { 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::("foo")