@@ -132,19 +132,41 @@ macro_rules! define_format_tests {
132132 ( covered, uncovered)
133133 } ) ;
134134
135- fn parse_input( input: & str ) -> Result <$piece_type, String > {
136- match terminated( $parser, eof) . parse_next( & mut input. as_bytes( ) ) {
137- Ok ( p) => Ok ( p) ,
138- Err ( e) => Err ( format!( "Failed to parse {}: {}" , input, e) ) ,
139- }
135+ fn parse_input<' i, Input >( input: & mut Input ) -> Result <$piece_type, String >
136+ where
137+ Input : StreamIsPartial
138+ + Stream
139+ + Compare <& ' i str >
140+ + AsBStr
141+ + Clone
142+ + std:: fmt:: Display ,
143+ <Input as Stream >:: Slice : AsBStr ,
144+ <Input as Stream >:: Token : AsChar + Clone ,
145+ {
146+ let o = $parser:: <Input , InputError <Input >>( input) . map_err( |e| {
147+ format!(
148+ "Failed to parse datetime: {}: {}" ,
149+ String :: from_utf8_lossy( input. as_bstr( ) ) ,
150+ e. to_string( )
151+ )
152+ } ) ?;
153+ let _ = eof:: <Input , InputError <Input >>( input) . map_err( |e| {
154+ format!(
155+ "Remaining input parsing datetime: {}: {}" ,
156+ String :: from_utf8_lossy( input. as_bstr( ) ) ,
157+ e. to_string( )
158+ )
159+ } ) ?;
160+
161+ Ok ( o)
140162 }
141163
142164 // Generate a trial for each assertion
143165 for assertion in covered {
144166 let name = format!( "parses - {}" , assertion. format) ;
145167 trials. push( Trial :: test( name, move || {
146168 // Parse the input
147- let result = parse_input( & assertion. input) ;
169+ let result = parse_input( & mut assertion. input. as_str ( ) ) ;
148170
149171 // If covered, the result must match the expected value
150172 if result != Ok ( assertion. expected) {
@@ -162,7 +184,7 @@ macro_rules! define_format_tests {
162184 let name = format!( "rejects - {}" , assertion. format) ;
163185 trials. push( Trial :: test( name, move || {
164186 // Parse the input
165- let result = parse_input( & assertion. input) ;
187+ let result = parse_input( & mut assertion. input. as_str ( ) ) ;
166188
167189 // If not covered, the result must be an error
168190 if result. is_ok( ) {
0 commit comments