From 527577895242ff4e453543bc40c54ff24633a68e Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Fri, 12 Jun 2020 18:46:36 +0800 Subject: [PATCH] Add test to call_fn with String parameter. --- README.md | 2 +- tests/call_fn.rs | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 99ce9018..2b70b36d 100644 --- a/README.md +++ b/README.md @@ -316,7 +316,7 @@ Functions declared with `private` are hidden and cannot be called from Rust (see // Define functions in a script. let ast = engine.compile(true, r#" - // a function with two parameters: String and i64 + // a function with two parameters: string and i64 fn hello(x, y) { x.len + y } diff --git a/tests/call_fn.rs b/tests/call_fn.rs index 0bed8d7b..29f7abca 100644 --- a/tests/call_fn.rs +++ b/tests/call_fn.rs @@ -89,6 +89,14 @@ fn test_anonymous_fn() -> Result<(), Box> { 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( Engine::new(), "private fn calc(x, y, z) { (x + y) * z }",