File tree Expand file tree Collapse file tree 3 files changed +26
-2
lines changed Expand file tree Collapse file tree 3 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -138,7 +138,8 @@ where
138
138
}
139
139
}
140
140
141
- /// Peek the next packet line without consuming it.
141
+ /// Peek the next packet line without consuming it. Returns `None` if a stop-packet or an error
142
+ /// was encountered.
142
143
///
143
144
/// Multiple calls to peek will return the same packet line, if there is one.
144
145
pub async fn peek_line ( & mut self ) -> Option < io:: Result < Result < PacketLineRef < ' _ > , decode:: Error > > > {
Original file line number Diff line number Diff line change @@ -132,7 +132,8 @@ where
132
132
}
133
133
}
134
134
135
- /// Peek the next packet line without consuming it.
135
+ /// Peek the next packet line without consuming it. Returns `None` if a stop-packet or an error
136
+ /// was encountered.
136
137
///
137
138
/// Multiple calls to peek will return the same packet line, if there is one.
138
139
pub fn peek_line ( & mut self ) -> Option < io:: Result < Result < PacketLineRef < ' _ > , decode:: Error > > > {
Original file line number Diff line number Diff line change @@ -72,6 +72,28 @@ pub mod streaming_peek_iter {
72
72
Ok ( ( ) )
73
73
}
74
74
75
+ #[ maybe_async:: test( feature = "blocking-io" , async ( feature = "async-io" , async_std:: test) ) ]
76
+ async fn peek_eof_is_none ( ) -> crate :: Result {
77
+ let mut rd =
78
+ gix_packetline:: StreamingPeekableIter :: new ( & b"0005a0009ERR e0000" [ ..] , & [ PacketLineRef :: Flush ] , false ) ;
79
+ rd. fail_on_err_lines ( false ) ;
80
+ let res = rd. peek_line ( ) . await ;
81
+ assert_eq ! ( res. expect( "line" ) ??, PacketLineRef :: Data ( b"a" ) ) ;
82
+ rd. read_line ( ) . await ;
83
+ let res = rd. peek_line ( ) . await ;
84
+ assert_eq ! (
85
+ res. expect( "line" ) ??,
86
+ PacketLineRef :: Data ( b"ERR e" ) ,
87
+ "we read the ERR but it's not interpreted as such"
88
+ ) ;
89
+ rd. read_line ( ) . await ;
90
+
91
+ let res = rd. peek_line ( ) . await ;
92
+ assert ! ( res. is_none( ) , "we peek into the flush packet, which is EOF" ) ;
93
+ assert_eq ! ( rd. stopped_at( ) , Some ( PacketLineRef :: Flush ) ) ;
94
+ Ok ( ( ) )
95
+ }
96
+
75
97
#[ maybe_async:: test( feature = "blocking-io" , async ( feature = "async-io" , async_std:: test) ) ]
76
98
async fn peek_non_data ( ) -> crate :: Result {
77
99
let mut rd =
You can’t perform that action at this time.
0 commit comments