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

@@ -1,4 +1,4 @@
use rhai::{Engine, EvalAltResult, INT};
use rhai::{Engine, EvalAltResult, ParseError, ParseErrorType, INT};
#[test]
fn test_loop() -> Result<(), Box<EvalAltResult>> {
@@ -26,5 +26,15 @@ fn test_loop() -> Result<(), Box<EvalAltResult>> {
21
);
assert!(matches!(
engine.compile("let x = 0; break;").expect_err("should error"),
ParseError(x, _) if *x == ParseErrorType::LoopBreak
));
assert!(matches!(
engine.compile("let x = 0; if x > 0 { continue; }").expect_err("should error"),
ParseError(x, _) if *x == ParseErrorType::LoopBreak
));
Ok(())
}