Do not error when a property is read-only.

This commit is contained in:
Stephen Chung
2020-05-04 18:06:09 +08:00
parent d83b829810
commit 798e1df298
2 changed files with 15 additions and 2 deletions

View File

@@ -7,6 +7,7 @@ fn test_get_set() -> Result<(), Box<EvalAltResult>> {
#[derive(Clone)]
struct TestStruct {
x: INT,
y: INT,
}
impl TestStruct {
@@ -18,8 +19,12 @@ fn test_get_set() -> Result<(), Box<EvalAltResult>> {
self.x = new_x;
}
fn get_y(&mut self) -> INT {
self.y
}
fn new() -> Self {
TestStruct { x: 1 }
TestStruct { x: 1, y: 0 }
}
}
@@ -28,9 +33,13 @@ fn test_get_set() -> Result<(), Box<EvalAltResult>> {
engine.register_type::<TestStruct>();
engine.register_get_set("x", TestStruct::get_x, TestStruct::set_x);
engine.register_get("y", TestStruct::get_y);
engine.register_fn("add", |value: &mut INT| *value += 41);
engine.register_fn("new_ts", TestStruct::new);
assert_eq!(engine.eval::<INT>("let a = new_ts(); a.x = 500; a.x")?, 500);
assert_eq!(engine.eval::<INT>("let a = new_ts(); a.x.add(); a.x")?, 42);
assert_eq!(engine.eval::<INT>("let a = new_ts(); a.y.add(); a.y")?, 0);
Ok(())
}