Fix bug in property setter op-assignment.

This commit is contained in:
Stephen Chung
2021-04-03 11:12:35 +08:00
parent a738f750f9
commit b089d5b8f4
7 changed files with 306 additions and 226 deletions

View File

@@ -1,8 +1,24 @@
use rhai::{Dynamic, Engine, EvalAltResult, NativeCallContext, INT};
use std::any::TypeId;
#[cfg(not(feature = "no_module"))]
#[cfg(not(feature = "unchecked"))]
#[test]
fn test_native_context() -> Result<(), Box<EvalAltResult>> {
let mut engine = Engine::new();
engine.set_max_modules(40);
engine.register_fn("test", |context: NativeCallContext, x: INT| {
context.engine().max_modules() as INT + x
});
assert_eq!(engine.eval::<INT>("test(2)")?, 42);
Ok(())
}
#[test]
fn test_native_context_fn_name() -> Result<(), Box<EvalAltResult>> {
fn add_double(
context: NativeCallContext,
args: &mut [&mut Dynamic],
@@ -21,14 +37,14 @@ fn test_native_context() -> Result<(), Box<EvalAltResult>> {
add_double,
)
.register_raw_fn(
"adbl",
"append_x2",
&[TypeId::of::<INT>(), TypeId::of::<INT>()],
add_double,
);
assert_eq!(engine.eval::<String>("add_double(40, 1)")?, "add_double_42");
assert_eq!(engine.eval::<String>("adbl(40, 1)")?, "adbl_42");
assert_eq!(engine.eval::<String>("append_x2(40, 1)")?, "append_x2_42");
Ok(())
}