From d7c69c4f5134e3e48b1eab2894daff037f781d02 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Thu, 28 May 2020 14:08:21 +0800 Subject: [PATCH] More tests. --- tests/float.rs | 15 ++++++++++++++- tests/modules.rs | 5 ++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/float.rs b/tests/float.rs index 8d70c7b3..211828d0 100644 --- a/tests/float.rs +++ b/tests/float.rs @@ -22,7 +22,7 @@ fn test_float() -> Result<(), Box> { #[test] #[cfg(not(feature = "no_object"))] -fn struct_with_float() -> Result<(), Box> { +fn test_struct_with_float() -> Result<(), Box> { #[derive(Clone)] struct TestStruct { x: f64, @@ -64,3 +64,16 @@ fn struct_with_float() -> Result<(), Box> { Ok(()) } + +#[test] +fn test_float_func() -> Result<(), Box> { + let mut engine = Engine::new(); + + engine.register_fn("sum", |x: FLOAT, y: FLOAT, z: FLOAT, w: FLOAT| { + x + y + z + w + }); + + assert_eq!(engine.eval::("sum(1.0, 2.0, 3.0, 4.0)")?, 10.0); + + Ok(()) +} diff --git a/tests/modules.rs b/tests/modules.rs index 6e49a43c..61273f53 100644 --- a/tests/modules.rs +++ b/tests/modules.rs @@ -63,6 +63,9 @@ fn test_module_resolver() -> Result<(), Box> { let mut module = Module::new(); module.set_var("answer", 42 as INT); + module.set_fn_4("sum".to_string(), |x: INT, y: INT, z: INT, w: INT| { + Ok(x + y + z + w) + }); resolver.insert("hello".to_string(), module); @@ -74,7 +77,7 @@ fn test_module_resolver() -> Result<(), Box> { r#" import "hello" as h1; import "hello" as h2; - h2::answer + h1::sum(h2::answer, -10, 3, 7) "# )?, 42