From 3091ebe0deb1ba832b4a5925263409ec5b651c62 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 3 Nov 2018 13:53:16 +0100 Subject: parser: Add a failing test for parse errors in the middle of lines We currently correctly report errors in the middle of the first line (problems with the trigger, problems with special keys in an action), but for all subsequent lines, the error message is limited to the first character on the line. This means that even if you write "map", "cmd", or "mode", which are all correct, the error message will refer to "column 1", even though the actual error is in a different part of the parser. Not sure why that's happening, nor why it doesn't happen for the first line. But at least we have a test for it now. The test will need to be modified once I can actually get the error messages propagating correctly, as the `Expected` lines are going to be wrong. They were just copy-pasted from the test above this one. --- src/parser.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/parser.rs') diff --git a/src/parser.rs b/src/parser.rs index 027c309..4bad78b 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1550,4 +1550,30 @@ not-a-kind ], })); } + + #[test] + fn map_group_shows_error_in_middle_of_line() { + let text = "map +map +"; + let result = map_group().easy_parse(State::new(text)).map(|t| t.0); + + assert_eq!(result, Err(easy::Errors { + position: SourcePosition { + line: 2, + column: 5, + }, + errors: vec![ + easy::Error::Unexpected('n'.into()), + easy::Error::Expected("map".into()), + easy::Error::Expected("cmd".into()), + easy::Error::Expected("mode".into()), + easy::Error::Expected("lf newline".into()), + easy::Error::Expected("whitespace".into()), + easy::Error::Expected("tab".into()), + easy::Error::Expected('#'.into()), + easy::Error::Expected("end of input".into()), + ], + })); + } } -- cgit v1.2.3