Refine position display in error messages.

This commit is contained in:
Stephen Chung
2020-06-12 18:04:16 +08:00
parent 6cc27eb9f4
commit 9d91349513
12 changed files with 256 additions and 238 deletions

View File

@@ -7,14 +7,16 @@ fn test_constant() -> Result<(), Box<EvalAltResult>> {
assert_eq!(engine.eval::<INT>("const x = 123; x")?, 123);
assert!(matches!(
*engine.eval::<INT>("const x = 123; x = 42;").expect_err("expects error"),
EvalAltResult::ErrorParsing(err) if err.error_type() == &ParseErrorType::AssignmentToConstant("x".to_string())
*engine
.eval::<INT>("const x = 123; x = 42;")
.expect_err("expects error"),
EvalAltResult::ErrorParsing(ParseErrorType::AssignmentToConstant(x), _) if x == "x"
));
#[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::ErrorParsing(err) if err.error_type() == &ParseErrorType::AssignmentToConstant("x".to_string())
EvalAltResult::ErrorParsing(ParseErrorType::AssignmentToConstant(x), _) if x == "x"
));
Ok(())