Propagate constants to functions for Engine::XXX_with_scope calls.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#![cfg(not(feature = "no_optimize"))]
|
||||
|
||||
use rhai::{Engine, EvalAltResult, OptimizationLevel, INT};
|
||||
use rhai::{Engine, EvalAltResult, OptimizationLevel, Scope, INT};
|
||||
|
||||
#[test]
|
||||
fn test_optimizer() -> Result<(), Box<EvalAltResult>> {
|
||||
@@ -107,3 +107,24 @@ fn test_optimizer_parse() -> Result<(), Box<EvalAltResult>> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_optimizer_scope() -> Result<(), Box<EvalAltResult>> {
|
||||
let engine = Engine::new();
|
||||
let mut scope = Scope::new();
|
||||
|
||||
scope.push_constant("FOO", 42 as INT);
|
||||
|
||||
let ast = engine.compile_with_scope(&scope, "fn foo() { FOO } foo()")?;
|
||||
|
||||
scope.push("FOO", 123 as INT);
|
||||
|
||||
assert_eq!(engine.eval_ast::<INT>(&ast)?, 42);
|
||||
assert_eq!(engine.eval_ast_with_scope::<INT>(&mut scope, &ast)?, 42);
|
||||
|
||||
let ast = engine.compile_with_scope(&scope, "fn foo() { FOO } foo()")?;
|
||||
|
||||
assert!(engine.eval_ast_with_scope::<INT>(&mut scope, &ast).is_err());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Reference in New Issue
Block a user