in neqo-transport/src/send_stream.rs [2287:2345]
fn tx_buffer_next_bytes_1() {
let mut txb = TxBuffer::new();
// Fill the buffer
let big_buf = vec![1; INITIAL_RECV_WINDOW_SIZE];
assert_eq!(txb.send(&big_buf), INITIAL_RECV_WINDOW_SIZE);
assert!(matches!(txb.next_bytes(),
Some((0, x)) if x.len() == INITIAL_RECV_WINDOW_SIZE
&& x.iter().all(|ch| *ch == 1)));
// Mark almost all as sent. Get what's left
let one_byte_from_end = INITIAL_RECV_WINDOW_SIZE as u64 - 1;
txb.mark_as_sent(0, usize::try_from(one_byte_from_end).unwrap());
assert!(matches!(txb.next_bytes(),
Some((start, x)) if x.len() == 1
&& start == one_byte_from_end
&& x.iter().all(|ch| *ch == 1)));
// Mark all as sent. Get nothing
txb.mark_as_sent(0, INITIAL_RECV_WINDOW_SIZE);
assert!(txb.next_bytes().is_none());
// Mark as lost. Get it again
txb.mark_as_lost(one_byte_from_end, 1);
assert!(matches!(txb.next_bytes(),
Some((start, x)) if x.len() == 1
&& start == one_byte_from_end
&& x.iter().all(|ch| *ch == 1)));
// Mark a larger range lost, including beyond what's in the buffer even.
// Get a little more
let five_bytes_from_end = INITIAL_RECV_WINDOW_SIZE as u64 - 5;
txb.mark_as_lost(five_bytes_from_end, 100);
assert!(matches!(txb.next_bytes(),
Some((start, x)) if x.len() == 5
&& start == five_bytes_from_end
&& x.iter().all(|ch| *ch == 1)));
// Contig acked range at start means it can be removed from buffer
// Impl of vecdeque should now result in a split buffer when more data
// is sent
txb.mark_as_acked(0, usize::try_from(five_bytes_from_end).unwrap());
assert_eq!(txb.send(&[2; 30]), 30);
// Just get 5 even though there is more
assert!(matches!(txb.next_bytes(),
Some((start, x)) if x.len() == 5
&& start == five_bytes_from_end
&& x.iter().all(|ch| *ch == 1)));
assert_eq!(txb.retired(), five_bytes_from_end);
assert_eq!(txb.buffered(), 35);
// Marking that bit as sent should let the last contig bit be returned
// when called again
txb.mark_as_sent(five_bytes_from_end, 5);
assert!(matches!(txb.next_bytes(),
Some((start, x)) if x.len() == 30
&& start == INITIAL_RECV_WINDOW_SIZE as u64
&& x.iter().all(|ch| *ch == 2)));
}