Automatic global module.

This commit is contained in:
Stephen Chung
2021-04-17 17:25:35 +08:00
parent 9a409b5b49
commit 1be7e60be2
4 changed files with 52 additions and 2 deletions

View File

@@ -62,7 +62,22 @@ fn test_functions_namespaces() -> Result<(), Box<EvalAltResult>> {
assert_eq!(engine.eval::<INT>("test()")?, 42);
#[cfg(not(feature = "no_function"))]
assert_eq!(engine.eval::<INT>("fn test() { 123 } test()")?, 123);
{
assert_eq!(engine.eval::<INT>("fn test() { 123 } test()")?, 123);
assert_eq!(
engine.eval::<INT>(
r"
const ANSWER = 42;
fn foo() { global::ANSWER }
foo()
"
)?,
42
);
}
Ok(())
}