From c53e98d3beacd8740acee310cfdbade9ea5fa1e0 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 1 Nov 2018 06:39:10 +0100 Subject: 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. --- src/parser.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src') 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, { or( + ( + blank(), + eof(), + ).map(|_| MapGroup::default()), definitions() .map(|definitions| { // MapGroup { @@ -679,7 +683,6 @@ where map_group }), - eof().map(|()| MapGroup::default()), ) } @@ -1372,6 +1375,19 @@ cmd /usr/bin/say hello assert_eq!(result, Ok(expected)); } + #[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 -- cgit v1.2.3