Add allow_shadowing.

This commit is contained in:
Stephen Chung
2022-02-04 13:20:47 +08:00
parent 6c1c8bc538
commit 3be27746e0
7 changed files with 65 additions and 14 deletions

View File

@@ -1,4 +1,4 @@
use rhai::{Engine, EvalAltResult};
use rhai::{Engine, EvalAltResult, Scope, INT};
#[test]
fn test_options_allow() -> Result<(), Box<EvalAltResult>> {
@@ -31,6 +31,20 @@ fn test_options_allow() -> Result<(), Box<EvalAltResult>> {
assert!(engine.compile("while x > y { foo(z); }").is_err());
engine.compile("let x = 42; let x = 123;")?;
engine.set_allow_shadowing(false);
assert!(engine.compile("let x = 42; let x = 123;").is_err());
assert!(engine.compile("const x = 42; let x = 123;").is_err());
assert!(engine.compile("let x = 42; const x = 123;").is_err());
assert!(engine.compile("const x = 42; const x = 123;").is_err());
let mut scope = Scope::new();
scope.push("x", 42 as INT);
assert!(engine.run_with_scope(&mut scope, "let x = 42;").is_err());
Ok(())
}