Add test to call_fn with String parameter.
This commit is contained in:
parent
9d91349513
commit
5275778952
@ -316,7 +316,7 @@ Functions declared with `private` are hidden and cannot be called from Rust (see
|
|||||||
// Define functions in a script.
|
// Define functions in a script.
|
||||||
let ast = engine.compile(true,
|
let ast = engine.compile(true,
|
||||||
r#"
|
r#"
|
||||||
// a function with two parameters: String and i64
|
// a function with two parameters: string and i64
|
||||||
fn hello(x, y) {
|
fn hello(x, y) {
|
||||||
x.len + y
|
x.len + y
|
||||||
}
|
}
|
||||||
|
@ -89,6 +89,14 @@ fn test_anonymous_fn() -> Result<(), Box<EvalAltResult>> {
|
|||||||
|
|
||||||
assert_eq!(calc_func(42, 123, 9)?, 1485);
|
assert_eq!(calc_func(42, 123, 9)?, 1485);
|
||||||
|
|
||||||
|
let calc_func = Func::<(INT, String, INT), INT>::create_from_script(
|
||||||
|
Engine::new(),
|
||||||
|
"fn calc(x, y, z) { (x + len(y)) * z }",
|
||||||
|
"calc",
|
||||||
|
)?;
|
||||||
|
|
||||||
|
assert_eq!(calc_func(42, "hello".to_string(), 9)?, 423);
|
||||||
|
|
||||||
let calc_func = Func::<(INT, INT, INT), INT>::create_from_script(
|
let calc_func = Func::<(INT, INT, INT), INT>::create_from_script(
|
||||||
Engine::new(),
|
Engine::new(),
|
||||||
"private fn calc(x, y, z) { (x + y) * z }",
|
"private fn calc(x, y, z) { (x + y) * z }",
|
||||||
|
Loading…
Reference in New Issue
Block a user