aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2018-11-05 03:39:50 +0100
committerTeddy Wing2018-11-05 03:39:50 +0100
commit2495cd60c34061b4e2b383beee6947787388f4cf (patch)
tree949010ce4c9c1702891dbe59f67948edb94f978a
parent0c6ad19a5e1c6b331df04f95b804de35cc2ef52e (diff)
downloaddome-key-map-2495cd60c34061b4e2b383beee6947787388f4cf.tar.bz2
parser: Add tests for initial whitespace and comments in mappings file
This broke recently I think. You can no longer have a mappings file that starts with blank lines or comment lines. Removing the empty and blank handler in `definitions()` fixes the tests added by this commit but fails these: parser::tests::map_group_empty_input_does_not_fail parser::tests::map_group_skipped_input_outputs_default_map_group Using this diff: diff --git a/src/parser.rs b/src/parser.rs index 3f3d7b9..d18b56a 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -629,11 +629,11 @@ where I: Stream<Item = char>, I::Error: ParseError<I::Item, I::Range, I::Position>, { - or( - ( - blank(), - eof(), - ).map(|_| MapGroup::default()), + // or( + // ( + // blank(), + // eof(), + // ).map(|_| MapGroup::default()), ( definitions(), eof(), @@ -661,8 +661,8 @@ where } map_group - }), - ) + }) + // ) } fn comment<I>() -> impl Parser<Input = I> Need to figure out some way to get both sets of tests to pass.
-rw-r--r--src/parser.rs100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/parser.rs b/src/parser.rs
index e198ee3..3f3d7b9 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -1495,6 +1495,106 @@ cmd <play> /usr/bin/say hello
}
#[test]
+ fn map_group_allows_initial_whitespace() {
+ let text = "
+map <play> x
+";
+ let result = map_group().easy_parse(text).map(|t| t.0);
+
+ let mut maps: MapCollection = HashMap::new();
+ maps.insert(
+ vec![HeadphoneButton::Up],
+ MapAction {
+ action: Action::Map(
+ vec![KeyboardKeyWithModifiers::new(
+ KeyboardKey::NXKey(key_code::NX_KEYTYPE_SOUND_UP),
+ vec![],
+ )]
+ ),
+ kind: MapKind::Map,
+ },
+ );
+ maps.insert(
+ vec![HeadphoneButton::Play],
+ MapAction {
+ action: Action::Map(
+ vec![KeyboardKeyWithModifiers::new(
+ KeyboardKey::Character(Character::new('x')),
+ vec![],
+ )]
+ ),
+ kind: MapKind::Map,
+ },
+ );
+ maps.insert(
+ vec![HeadphoneButton::Down],
+ MapAction {
+ action: Action::Map(
+ vec![KeyboardKeyWithModifiers::new(
+ KeyboardKey::NXKey(key_code::NX_KEYTYPE_SOUND_DOWN),
+ vec![],
+ )]
+ ),
+ kind: MapKind::Map,
+ },
+ );
+ let expected = MapGroup {
+ maps: maps,
+ modes: HashMap::new(),
+ };
+
+ assert_eq!(result, Ok(expected));
+ }
+
+ #[test]
+ fn map_group_allows_initial_comment_lines() {
+ let text = "# A comment
+
+cmd <down> echo test
+";
+ let result = map_group().easy_parse(text).map(|t| t.0);
+
+ let mut maps: MapCollection = HashMap::new();
+ maps.insert(
+ vec![HeadphoneButton::Up],
+ MapAction {
+ action: Action::Map(
+ vec![KeyboardKeyWithModifiers::new(
+ KeyboardKey::NXKey(key_code::NX_KEYTYPE_SOUND_UP),
+ vec![],
+ )]
+ ),
+ kind: MapKind::Map,
+ },
+ );
+ maps.insert(
+ vec![HeadphoneButton::Play],
+ MapAction {
+ action: Action::Map(
+ vec![KeyboardKeyWithModifiers::new(
+ KeyboardKey::NXKey(key_code::NX_KEYTYPE_PLAY),
+ vec![],
+ )]
+ ),
+ kind: MapKind::Map,
+ },
+ );
+ maps.insert(
+ vec![HeadphoneButton::Down],
+ MapAction {
+ action: Action::String("echo test".to_owned()),
+ kind: MapKind::Command,
+ },
+ );
+ let expected = MapGroup {
+ maps: maps,
+ modes: HashMap::new(),
+ };
+
+ assert_eq!(result, Ok(expected));
+ }
+
+ #[test]
fn map_group_empty_input_does_not_fail() {
let text = "";
let result = map_group().easy_parse(text).map(|t| t.0);