diff --git a/tests/functions.rs b/tests/functions.rs index ff71e390..73b4fc60 100644 --- a/tests/functions.rs +++ b/tests/functions.rs @@ -1,5 +1,5 @@ #![cfg(not(feature = "no_function"))] -use rhai::{Engine, EvalAltResult, FnNamespace, Module, ParseErrorType, INT}; +use rhai::{Engine, EvalAltResult, FnNamespace, Module, NativeCallContext, ParseErrorType, INT}; #[test] fn test_functions() -> Result<(), Box> { @@ -51,6 +51,20 @@ fn test_functions() -> Result<(), Box> { Ok(()) } +#[test] +fn test_functions_context() -> Result<(), Box> { + let mut engine = Engine::new(); + + engine.set_max_modules(40); + engine.register_fn("test", |context: NativeCallContext, x: INT| { + context.engine().max_modules() as INT + x + }); + + assert_eq!(engine.eval::("test(2)")?, 42); + + Ok(()) +} + #[test] fn test_functions_params() -> Result<(), Box> { let engine = Engine::new(); @@ -67,7 +81,6 @@ fn test_functions_params() -> Result<(), Box> { Ok(()) } -#[cfg(not(feature = "no_function"))] #[test] fn test_functions_namespaces() -> Result<(), Box> { let mut engine = Engine::new(); @@ -81,12 +94,16 @@ fn test_functions_namespaces() -> Result<(), Box> { engine.register_static_module("hello", m.into()); assert_eq!(engine.eval::("test()")?, 999); + + #[cfg(not(feature = "no_function"))] assert_eq!(engine.eval::("fn test() { 123 } test()")?, 123); } engine.register_fn("test", || 42 as INT); assert_eq!(engine.eval::("test()")?, 42); + + #[cfg(not(feature = "no_function"))] assert_eq!(engine.eval::("fn test() { 123 } test()")?, 123); Ok(())