Skip to content

Commit cfe078c

Browse files
committed
add another test to validate EOF behaviour
1 parent 613f018 commit cfe078c

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

gix-packetline/src/read/async_io.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ where
138138
}
139139
}
140140

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.
142143
///
143144
/// Multiple calls to peek will return the same packet line, if there is one.
144145
pub async fn peek_line(&mut self) -> Option<io::Result<Result<PacketLineRef<'_>, decode::Error>>> {

gix-packetline/src/read/blocking_io.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ where
132132
}
133133
}
134134

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.
136137
///
137138
/// Multiple calls to peek will return the same packet line, if there is one.
138139
pub fn peek_line(&mut self) -> Option<io::Result<Result<PacketLineRef<'_>, decode::Error>>> {

gix-packetline/tests/read/mod.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,28 @@ pub mod streaming_peek_iter {
7272
Ok(())
7373
}
7474

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+
7597
#[maybe_async::test(feature = "blocking-io", async(feature = "async-io", async_std::test))]
7698
async fn peek_non_data() -> crate::Result {
7799
let mut rd =

0 commit comments

Comments
 (0)