Add plugins test.

This commit is contained in:
Stephen Chung 2020-08-02 15:39:16 +08:00
parent 73cda2d4f9
commit 675c4eb606

24
tests/plugins.rs Normal file
View File

@ -0,0 +1,24 @@
use rhai::{export_module, exported_module};
use rhai::{Engine, EvalAltResult, INT};
#[export_module]
pub mod array_package {
use rhai::{Array, INT};
pub fn len(array: &mut Array, mul: INT) -> INT {
(array.len() as INT) * mul
}
}
#[test]
fn test_plugins() -> Result<(), Box<EvalAltResult>> {
let mut engine = Engine::new();
let m = exported_module!(array_package);
engine.load_package(m.into());
assert_eq!(engine.eval::<INT>("let a = [1, 2, 3]; a.len(2)")?, 6);
Ok(())
}