From df366366a1b318b6bc4b00b3829fcd1455d09d97 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 3 Nov 2018 19:04:35 +0100 Subject: parser: Add tests for error message Check that the desired error messages appear for a couple extra invalid mapping definitions. Rename the existing `map_group_shows_error_in_middle_of_line()` test to use the naming pattern of the two new tests. The new tests check that the right errors appear in map actions, and for missing the closing brace on a mode definition. --- src/parser.rs | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/parser.rs b/src/parser.rs index a31f097..e198ee3 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1542,7 +1542,7 @@ not-a-kind } #[test] - fn map_group_shows_error_in_middle_of_line() { + fn map_group_shows_error_in_trigger() { let text = "map map "; @@ -1560,4 +1560,48 @@ map &easy::Error::Unexpected('n'.into()), )); } + + #[test] + fn map_group_shows_error_in_action() { + let text = "map +map a +"; + let result = map_group().easy_parse(State::new(text)).map(|t| t.0); + let error = result.unwrap_err(); + + assert_eq!( + error.position, + SourcePosition { + line: 2, + column: 14, + } + ); + assert!(error.errors.contains( + &easy::Error::Unexpected('n'.into()), + )); + } + + #[test] + fn map_group_shows_error_in_mode_close() { + let text = "map +mode { + map +"; + let result = map_group().easy_parse(State::new(text)).map(|t| t.0); + let error = result.unwrap_err(); + + assert_eq!( + error.position, + SourcePosition { + line: 4, + column: 1, + } + ); + assert!(error.errors.contains( + &easy::Error::Unexpected("end of input".into()), + )); + assert!(error.errors.contains( + &easy::Error::Message("missing closing '}'".into()), + )); + } } -- cgit v1.2.3