2020-03-04 15:00:01 +01:00
|
|
|
use rhai::{Engine, EvalAltResult};
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_engine_call_fn() -> Result<(), EvalAltResult> {
|
|
|
|
let mut engine = Engine::new();
|
|
|
|
|
2020-03-10 07:09:05 +01:00
|
|
|
let ast = engine.compile(
|
|
|
|
r"
|
|
|
|
fn hello(x, y) {
|
|
|
|
x.len() + y
|
|
|
|
}
|
|
|
|
",
|
|
|
|
)?;
|
2020-03-04 15:00:01 +01:00
|
|
|
|
2020-03-10 07:09:05 +01:00
|
|
|
let result: i64 = engine.call_fn("hello", &ast, (String::from("abc"), 123_i64))?;
|
2020-03-04 15:00:01 +01:00
|
|
|
|
|
|
|
assert_eq!(result, 126);
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|