diff options
| author | Teddy Wing | 2018-11-01 06:39:10 +0100 |
|---|---|---|
| committer | Teddy Wing | 2018-11-01 06:39:10 +0100 |
| commit | c53e98d3beacd8740acee310cfdbade9ea5fa1e0 (patch) | |
| tree | 51903d98c2f8efb13d4b1728662208c91917c1ab | |
| parent | fca324396c762e034ee30aec3f7ffa0ce7de5516 (diff) | |
| download | dome-key-map-c53e98d3beacd8740acee310cfdbade9ea5fa1e0.tar.bz2 | |
map_group(): Parse input full of `blank()` to `MapGroup` default
An input with all mixed whitespace and comments should behave the same
as empty input.
| -rw-r--r-- | src/parser.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/parser.rs b/src/parser.rs index 1c21510..8df629d 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -646,6 +646,10 @@ where I::Error: ParseError<I::Item, I::Range, I::Position>, { or( + ( + blank(), + eof(), + ).map(|_| MapGroup::default()), definitions() .map(|definitions| { // MapGroup { @@ -679,7 +683,6 @@ where map_group }), - eof().map(|()| MapGroup::default()), ) } @@ -1373,6 +1376,19 @@ cmd <play> /usr/bin/say hello } #[test] + fn map_group_skipped_input_outputs_default_map_group() { + let text = " +# test + # a test + "; + let result = map_group().easy_parse(text).map(|t| t.0); + let expected = MapGroup::default(); + println!("{:?}", map_group().easy_parse(text).map(|t| t.1)); + + assert_eq!(result, Ok(expected)); + } + + #[test] fn map_group_with_invalid_input_fails() { let text = "not-a-kind <play> <Nop> "; |
