Add fail on invalid property for maps.

This commit is contained in:
Stephen Chung
2022-02-09 13:12:43 +08:00
parent 6acc486e00
commit 340a047369
7 changed files with 175 additions and 130 deletions

View File

@@ -107,6 +107,23 @@ b`: 1}; y["a\nb"]
Ok(())
}
#[test]
fn test_map_prop() -> Result<(), Box<EvalAltResult>> {
let mut engine = Engine::new();
assert_eq!(engine.eval::<()>("let x = #{a: 42}; x.b")?, ());
engine.set_fail_on_invalid_map_property(true);
assert!(
matches!(*engine.eval::<()>("let x = #{a: 42}; x.b").expect_err("should error"),
EvalAltResult::ErrorPropertyNotFound(prop, _) if prop == "b"
)
);
Ok(())
}
#[test]
fn test_map_assign() -> Result<(), Box<EvalAltResult>> {
let engine = Engine::new();