From 94313ca095295889431551f273c58db9e34de498 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Sun, 5 Apr 2020 12:57:20 +0800 Subject: [PATCH] Test variable mutation in outer scope. --- tests/call_fn.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/call_fn.rs b/tests/call_fn.rs index 1535f504..909e8a90 100644 --- a/tests/call_fn.rs +++ b/tests/call_fn.rs @@ -31,10 +31,12 @@ fn test_call_fn() -> Result<(), EvalAltResult> { x + y } fn hello(x) { - x * foo + x = x * foo; + foo = 1; + x } fn hello() { - 42 + foo + 41 + foo } ", )?; @@ -46,7 +48,14 @@ fn test_call_fn() -> Result<(), EvalAltResult> { assert_eq!(r, 5166); let r: i64 = engine.call_fn0(&mut scope, &ast, "hello")?; - assert_eq!(r, 84); + assert_eq!(r, 42); + + assert_eq!( + scope + .get_value::("foo") + .expect("variable foo should exist"), + 1 + ); Ok(()) }