diff options
| author | Teddy Wing | 2018-08-09 02:36:30 +0200 |
|---|---|---|
| committer | Teddy Wing | 2018-08-09 02:36:30 +0200 |
| commit | 4d651343069d344b0af668f898db63de475463a1 (patch) | |
| tree | 10c322cc1ddad46dd377b7b1f2fcc434ddda8353 /src | |
| parent | 38101cf31564884103000c33d224b4b5381c52c6 (diff) | |
| download | dome-key-map-4d651343069d344b0af668f898db63de475463a1.tar.bz2 | |
Parse a `Trigger`, or sequence of `HeadphoneButton`s
So cool! I love parser combinators.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib.rs | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -61,6 +61,14 @@ where ) } +fn trigger<I>() -> impl Parser<Input = I, Output = Trigger> +where + I: Stream<Item = char>, + I::Error: ParseError<I::Item, I::Range, I::Position>, +{ + many1(headphone_button()) +} + #[cfg(test)] mod tests { @@ -89,4 +97,16 @@ mod tests { 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); + + assert_eq!(result, Ok(vec![ + HeadphoneButton::Up, + HeadphoneButton::Down, + HeadphoneButton::Play, + ])); + } } |
