Catch more assignment errors at parse time.

This commit is contained in:
Stephen Chung
2020-05-07 12:25:09 +08:00
parent fb64adca93
commit f3c0609377
3 changed files with 56 additions and 20 deletions

View File

@@ -1,4 +1,4 @@
use rhai::{Engine, EvalAltResult, INT};
use rhai::{Engine, EvalAltResult, ParseErrorType, INT};
#[test]
fn test_constant() -> Result<(), Box<EvalAltResult>> {
@@ -8,13 +8,13 @@ fn test_constant() -> Result<(), Box<EvalAltResult>> {
assert!(matches!(
*engine.eval::<INT>("const x = 123; x = 42;").expect_err("expects error"),
EvalAltResult::ErrorAssignmentToConstant(var, _) if var == "x"
EvalAltResult::ErrorParsing(err) if err.error_type() == &ParseErrorType::AssignmentToConstant("x".to_string())
));
#[cfg(not(feature = "no_index"))]
assert!(matches!(
*engine.eval::<INT>("const x = [1, 2, 3, 4, 5]; x[2] = 42;").expect_err("expects error"),
EvalAltResult::ErrorAssignmentToConstant(var, _) if var == "x"
EvalAltResult::ErrorParsing(err) if err.error_type() == &ParseErrorType::AssignmentToConstant("x".to_string())
));
Ok(())