Add ParseError:err_type and ParseError::position.

This commit is contained in:
Stephen Chung
2022-07-29 09:42:30 +08:00
parent 6fab9f5b63
commit ea38185cac
19 changed files with 147 additions and 104 deletions

View File

@@ -115,10 +115,10 @@ fn test_switch_errors() -> Result<(), Box<EvalAltResult>> {
let engine = Engine::new();
assert!(matches!(
*engine
engine
.compile("switch x { _ => 123, 1 => 42 }")
.expect_err("should error")
.0,
.err_type(),
ParseErrorType::WrongSwitchDefaultCase
));
@@ -179,10 +179,10 @@ fn test_switch_condition() -> Result<(), Box<EvalAltResult>> {
);
assert!(matches!(
*engine
engine
.compile("switch x { 1 => 123, _ if true => 42 }")
.expect_err("should error")
.0,
.err_type(),
ParseErrorType::WrongSwitchCaseCondition
));
@@ -274,8 +274,9 @@ fn test_switch_ranges() -> Result<(), Box<EvalAltResult>> {
'x'
);
assert!(matches!(
*engine.compile("switch x { 10..20 => (), 20..=42 => 'a', 25..45 => 'z', 42 => 'x', 30..100 => true }")
.expect_err("should error").0,
engine.compile(
"switch x { 10..20 => (), 20..=42 => 'a', 25..45 => 'z', 42 => 'x', 30..100 => true }"
).expect_err("should error").err_type(),
ParseErrorType::WrongSwitchIntegerCase
));
assert_eq!(