aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2018-11-03 19:04:35 +0100
committerTeddy Wing2018-11-03 19:04:35 +0100
commitdf366366a1b318b6bc4b00b3829fcd1455d09d97 (patch)
tree006ba7b1e9a88b0fed03547d242e3975137f45d6
parent16d5b3f7c35859c58365a689b94383203497caef (diff)
downloaddome-key-map-df366366a1b318b6bc4b00b3829fcd1455d09d97.tar.bz2
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.
-rw-r--r--src/parser.rs46
1 files changed, 45 insertions, 1 deletions
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 <play> <Nop>
}
#[test]
- fn map_group_shows_error_in_middle_of_line() {
+ fn map_group_shows_error_in_trigger() {
let text = "map <up> <Up>
map <not-a-button> <Nop>
";
@@ -1560,4 +1560,48 @@ map <not-a-button> <Nop>
&easy::Error::Unexpected('n'.into()),
));
}
+
+ #[test]
+ fn map_group_shows_error_in_action() {
+ let text = "map <up> <Up>
+map <play> a<not-a-special-key>
+";
+ 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 <up> <Up>
+mode <play> {
+ map <up> <Down>
+";
+ 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()),
+ ));
+ }
}