fn tx_buffer_next_bytes_2()

in neqo-transport/src/send_stream.rs [2348:2408]


    fn tx_buffer_next_bytes_2() {
        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)));

        // As above
        let forty_bytes_from_end = INITIAL_RECV_WINDOW_SIZE as u64 - 40;

        txb.mark_as_acked(0, usize::try_from(forty_bytes_from_end).unwrap());
        assert!(matches!(txb.next_bytes(),
                 Some((start, x)) if x.len() == 40
                 && start == forty_bytes_from_end
        ));

        // Valid new data placed in split locations
        assert_eq!(txb.send(&[2; 100]), 100);

        // Mark a little more as sent
        txb.mark_as_sent(forty_bytes_from_end, 10);
        let thirty_bytes_from_end = forty_bytes_from_end + 10;
        assert!(matches!(txb.next_bytes(),
                         Some((start, x)) if x.len() == 30
                         && start == thirty_bytes_from_end
                         && x.iter().all(|ch| *ch == 1)));

        // Mark a range 'A' in second slice as sent. Should still return the same
        let range_a_start = INITIAL_RECV_WINDOW_SIZE as u64 + 30;
        let range_a_end = range_a_start + 10;
        txb.mark_as_sent(range_a_start, 10);
        assert!(matches!(txb.next_bytes(),
                         Some((start, x)) if x.len() == 30
                         && start == thirty_bytes_from_end
                         && x.iter().all(|ch| *ch == 1)));

        // Ack entire first slice and into second slice
        let ten_bytes_past_end = INITIAL_RECV_WINDOW_SIZE as u64 + 10;
        txb.mark_as_acked(0, usize::try_from(ten_bytes_past_end).unwrap());

        // Get up to marked range A
        assert!(matches!(txb.next_bytes(),
                         Some((start, x)) if x.len() == 20
                         && start == ten_bytes_past_end
                         && x.iter().all(|ch| *ch == 2)));

        txb.mark_as_sent(ten_bytes_past_end, 20);

        // Get bit after earlier marked range A
        assert!(matches!(txb.next_bytes(),
                         Some((start, x)) if x.len() == 60
                         && start == range_a_end
                         && x.iter().all(|ch| *ch == 2)));

        // No more bytes.
        txb.mark_as_sent(range_a_end, 60);
        assert!(txb.next_bytes().is_none());
    }