From 772e44aa3df24e1178f71acefc3d43a1f626c2ed Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Tue, 18 Aug 2020 09:25:43 +0800 Subject: [PATCH] Test getter. --- tests/plugins.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/plugins.rs b/tests/plugins.rs index 3379b411..5331287b 100644 --- a/tests/plugins.rs +++ b/tests/plugins.rs @@ -7,6 +7,10 @@ use rhai::{Engine, EvalAltResult, INT}; mod special_array_package { use rhai::{Array, INT}; + #[rhai_fn(get = "foo", return_raw)] + pub fn foo(array: &mut Array) -> Result> { + Ok(array[0].clone()) + } #[rhai_fn(name = "test")] pub fn len(array: &mut Array, mul: INT) -> INT { (array.len() as INT) * mul @@ -53,6 +57,7 @@ fn test_plugins_package() -> Result<(), Box> { reg_functions!(engine += greet::single(INT, bool, char)); + assert_eq!(engine.eval::("let a = [1, 2, 3]; a.foo")?, 1); assert_eq!(engine.eval::("let a = [1, 2, 3]; test(a, 2)")?, 6); assert_eq!(engine.eval::("2 + 2")?, 5); assert_eq!(