Allow scope constants in strict variables mode.

This commit is contained in:
Stephen Chung
2022-04-21 13:21:53 +08:00
parent c3d013bddc
commit 6b8ddd925b
7 changed files with 44 additions and 28 deletions

View File

@@ -56,6 +56,10 @@ fn test_options_allow() -> Result<(), Box<EvalAltResult>> {
fn test_options_strict_var() -> Result<(), Box<EvalAltResult>> {
let mut engine = Engine::new();
let mut scope = Scope::new();
scope.push_constant("x", 42 as INT);
scope.push_constant("y", 0 as INT);
engine.compile("let x = if y { z } else { w };")?;
#[cfg(not(feature = "no_function"))]
@@ -79,6 +83,11 @@ fn test_options_strict_var() -> Result<(), Box<EvalAltResult>> {
assert!(engine.compile("let x = if y { z } else { w };").is_err());
engine.compile("let y = 42; let x = y;")?;
assert_eq!(
engine.eval_with_scope::<INT>(&mut scope, "{ let y = 42; x * y }")?,
42 * 42
);
#[cfg(not(feature = "no_function"))]
assert!(engine.compile("fn foo(x) { x + y }").is_err());
@@ -103,6 +112,10 @@ fn test_options_strict_var() -> Result<(), Box<EvalAltResult>> {
engine.compile("let x = 42; let f = |y| { || x + y };")?;
assert!(engine.compile("fn foo() { |y| { || x + y } }").is_err());
}
assert_eq!(
engine.eval_with_scope::<INT>(&mut scope, "fn foo(z) { x * y + z } foo(1)")?,
1
);
}
Ok(())