aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
authorTeddy Wing2018-08-09 02:53:50 +0200
committerTeddy Wing2018-08-09 02:53:50 +0200
commitd05b00eb8fa01a947fb1217b771444f43852499a (patch)
tree322838bc9264f2964ab901e84f904e2aad59235d /src/lib.rs
parent4d651343069d344b0af668f898db63de475463a1 (diff)
downloaddome-key-map-d05b00eb8fa01a947fb1217b771444f43852499a.tar.bz2
Ignore case when parsing `HeadphoneButton`
Should work with `<play>`, `<Play>`, `<PLAY>`, `<PlAy>`.
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/lib.rs b/src/lib.rs
index a8128c5..dc7b7bc 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -5,7 +5,7 @@ use std::collections::HashMap;
use combine::*;
use combine::parser::choice::or;
-use combine::parser::char::string;
+use combine::parser::char::{string, string_cmp};
#[derive(Debug, PartialEq)]
pub enum HeadphoneButton {
@@ -54,9 +54,12 @@ where
token('<'),
token('>'),
choice!(
- string("play").map(|_| HeadphoneButton::Play),
- string("up").map(|_| HeadphoneButton::Up),
- string("down").map(|_| HeadphoneButton::Down)
+ string_cmp("play", |l, r| l.eq_ignore_ascii_case(&r))
+ .map(|_| HeadphoneButton::Play),
+ string_cmp("up", |l, r| l.eq_ignore_ascii_case(&r))
+ .map(|_| HeadphoneButton::Up),
+ string_cmp("down", |l, r| l.eq_ignore_ascii_case(&r))
+ .map(|_| HeadphoneButton::Down)
),
)
}
@@ -99,6 +102,14 @@ mod tests {
}
#[test]
+ fn headphone_button_ignores_case() {
+ let text = "<Play>";
+ let result = headphone_button().parse(text).map(|t| t.0);
+
+ assert_eq!(result, Ok(HeadphoneButton::Play));
+ }
+
+ #[test]
fn trigger_parses_headphone_button_sequence() {
let text = "<up><down><play>";
let result = trigger().parse(text).map(|t| t.0);