@@ -4,6 +4,30 @@ use git_packetline::PacketLine;
4
4
#[ cfg( feature = "blocking-io" ) ]
5
5
use std:: io:: { BufRead , Read } ;
6
6
7
+ #[ maybe_async:: test( feature = "blocking-io" , async ( feature = "async-io" , async_std:: test) ) ]
8
+ async fn peek_past_an_actual_eof_is_an_error ( ) -> crate :: Result {
9
+ let input = b"0009ERR e" ;
10
+ let mut rd = git_packetline:: StreamingPeekableIter :: new ( & input[ ..] , & [ ] ) ;
11
+ let mut reader = rd. as_read ( ) ;
12
+ let res = reader. peek_data_line ( ) . await ;
13
+ assert_eq ! ( res. expect( "one line" ) ??, b"ERR e" ) ;
14
+
15
+ let mut buf = String :: new ( ) ;
16
+ reader. read_line ( & mut buf) . await ?;
17
+ assert_eq ! (
18
+ buf, "ERR e" ,
19
+ "by default ERR lines won't propagate as failure but are merely text"
20
+ ) ;
21
+
22
+ let res = reader. peek_data_line ( ) . await ;
23
+ assert_eq ! (
24
+ res. expect( "an err" ) . expect_err( "foo" ) . kind( ) ,
25
+ std:: io:: ErrorKind :: UnexpectedEof ,
26
+ "peeking past the end is not an error as the caller should make sure we dont try 'invalid' reads"
27
+ ) ;
28
+ Ok ( ( ) )
29
+ }
30
+
7
31
#[ maybe_async:: test( feature = "blocking-io" , async ( feature = "async-io" , async_std:: test) ) ]
8
32
async fn peek_past_a_delimiter_is_no_error ( ) -> crate :: Result {
9
33
let input = b"0009hello0000" ;
@@ -14,6 +38,7 @@ async fn peek_past_a_delimiter_is_no_error() -> crate::Result {
14
38
15
39
let mut buf = String :: new ( ) ;
16
40
reader. read_line ( & mut buf) . await ?;
41
+ assert_eq ! ( buf, "hello" ) ;
17
42
18
43
let res = reader. peek_data_line ( ) . await ;
19
44
assert ! (
0 commit comments