From d05b00eb8fa01a947fb1217b771444f43852499a Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 9 Aug 2018 02:53:50 +0200 Subject: Ignore case when parsing `HeadphoneButton` Should work with ``, ``, ``, ``. --- src/lib.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src') 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) ), ) } @@ -98,6 +101,14 @@ mod tests { assert_eq!(result, Ok(HeadphoneButton::Play)); } + #[test] + fn headphone_button_ignores_case() { + let text = ""; + 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 = ""; -- cgit v1.2.3