Skip to content

Commit 76dae7b

Browse files
committed
add a test for extending past lower limit
For #674 (review)
1 parent c040374 commit 76dae7b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/test_bytes.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,28 @@ fn extend_mut_from_bytes() {
598598
assert_eq!(*bytes, LONG[..]);
599599
}
600600

601+
#[test]
602+
fn extend_past_lower_limit_of_size_hint() {
603+
// See https://github.com/tokio-rs/bytes/pull/674#pullrequestreview-1913035700
604+
struct Iter<I>(I);
605+
606+
impl<I: Iterator<Item = u8>> Iterator for Iter<I> {
607+
type Item = u8;
608+
609+
fn next(&mut self) -> Option<Self::Item> {
610+
self.0.next()
611+
}
612+
613+
fn size_hint(&self) -> (usize, Option<usize>) {
614+
(5, None)
615+
}
616+
}
617+
618+
let mut bytes = BytesMut::with_capacity(5);
619+
bytes.extend(Iter(std::iter::repeat(0).take(10)));
620+
assert_eq!(bytes.len(), 10);
621+
}
622+
601623
#[test]
602624
fn extend_mut_without_size_hint() {
603625
let mut bytes = BytesMut::with_capacity(0);

0 commit comments

Comments
 (0)