Fix tests.
This commit is contained in:
parent
4100645512
commit
25fde7dbed
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "rhai_codegen"
|
name = "rhai_codegen"
|
||||||
version = "1.4.2"
|
version = "1.4.3"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
authors = ["jhwgh1968", "Stephen Chung"]
|
authors = ["jhwgh1968", "Stephen Chung"]
|
||||||
@ -22,5 +22,5 @@ syn = { version = "1.0", features = ["full", "parsing", "printing", "proc-macro"
|
|||||||
quote = "1"
|
quote = "1"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
rhai = { path = "..", version = "1.6", features = ["metadata"] }
|
rhai = { path = "..", version = "1.11", features = ["metadata"] }
|
||||||
trybuild = "1"
|
trybuild = "1"
|
||||||
|
@ -239,6 +239,17 @@ impl<'a> Target<'a> {
|
|||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// Convert a shared or reference [`Target`] into a target with an owned value.
|
||||||
|
#[inline(always)]
|
||||||
|
#[must_use]
|
||||||
|
pub fn into_owned(self) -> Self {
|
||||||
|
match self {
|
||||||
|
Self::RefMut(r) => Self::TempValue(r.clone()),
|
||||||
|
#[cfg(not(feature = "no_closure"))]
|
||||||
|
Self::SharedValue { value, .. } => Self::TempValue(value),
|
||||||
|
_ => self,
|
||||||
|
}
|
||||||
|
}
|
||||||
/// Get the source [`Dynamic`] of the [`Target`].
|
/// Get the source [`Dynamic`] of the [`Target`].
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -1234,9 +1234,13 @@ impl Engine {
|
|||||||
.map(|(value, ..)| arg_values.push(value.flatten()))
|
.map(|(value, ..)| arg_values.push(value.flatten()))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let (target, _pos) =
|
let (mut target, _pos) =
|
||||||
self.search_namespace(scope, global, lib, this_ptr, first_expr, level)?;
|
self.search_namespace(scope, global, lib, this_ptr, first_expr, level)?;
|
||||||
|
|
||||||
|
if target.is_read_only() {
|
||||||
|
target = target.into_owned();
|
||||||
|
}
|
||||||
|
|
||||||
self.track_operation(global, _pos)?;
|
self.track_operation(global, _pos)?;
|
||||||
|
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
|
@ -87,7 +87,7 @@ fn test_constant_mut() -> Result<(), Box<EvalAltResult>> {
|
|||||||
"
|
"
|
||||||
)
|
)
|
||||||
.expect_err("should error"),
|
.expect_err("should error"),
|
||||||
EvalAltResult::ErrorAssignmentToConstant(..)
|
EvalAltResult::ErrorNonPureMethodCallOnConstant(..)
|
||||||
));
|
));
|
||||||
|
|
||||||
let mut scope = Scope::new();
|
let mut scope = Scope::new();
|
||||||
@ -120,7 +120,7 @@ fn test_constant_mut() -> Result<(), Box<EvalAltResult>> {
|
|||||||
*engine
|
*engine
|
||||||
.run_with_scope(&mut scope, "MY_NUMBER.value = 42;")
|
.run_with_scope(&mut scope, "MY_NUMBER.value = 42;")
|
||||||
.expect_err("should error"),
|
.expect_err("should error"),
|
||||||
EvalAltResult::ErrorAssignmentToConstant(..)
|
EvalAltResult::ErrorNonPureMethodCallOnConstant(..)
|
||||||
));
|
));
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -119,7 +119,7 @@ fn test_plugins_package() -> Result<(), Box<EvalAltResult>> {
|
|||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
matches!(*engine.run("const A = [1, 2, 3]; A.test(42);").expect_err("should error"),
|
matches!(*engine.run("const A = [1, 2, 3]; A.test(42);").expect_err("should error"),
|
||||||
EvalAltResult::ErrorAssignmentToConstant(x, ..) if x == "array")
|
EvalAltResult::ErrorNonPureMethodCallOnConstant(x, ..) if x == "test")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user