diff options
Diffstat (limited to 'src/lib.rs')
| -rw-r--r-- | src/lib.rs | 35 |
1 files changed, 35 insertions, 0 deletions
@@ -35,6 +35,7 @@ pub struct MapAction { pub kind: MapKind, } +#[derive(Debug, PartialEq)] struct Map { trigger: Trigger, action: Action, @@ -103,6 +104,26 @@ where skip_many1(space().or(tab())) } +fn map<I>() -> impl Parser<Input = I, Output = Map> +where + I: Stream<Item = char>, + I::Error: ParseError<I::Item, I::Range, I::Position>, +{ + ( + map_kind(), + whitespace_separator(), + trigger(), + whitespace_separator(), + action() + ).map(|(kind, _, trigger, _, action)| + Map { + trigger: trigger, + action: action, + kind: kind, + } + ) +} + fn map_collection<I>() -> impl Parser<Input = I, Output = MapCollection> where I: Stream<Item = char>, @@ -196,6 +217,20 @@ mod tests { } #[test] + fn map_parses_map_line() { + let text = "map <play><down> test +"; + let expected = Map { + trigger: vec![HeadphoneButton::Play, HeadphoneButton::Down], + action: "test".to_owned(), + kind: MapKind::Map, + }; + let result = map().parse(text).map(|t| t.0); + + assert_eq!(result, Ok(expected)); + } + + #[test] fn map_collection_parses_maps() { let text = " map <up><down> test |
