From 7968f6f83d17175683e04ce56aa48e44ed7d0d98 Mon Sep 17 00:00:00 2001 From: Brad Dunbar Date: Mon, 4 Mar 2024 03:04:40 -0500 Subject: Remove redundant reserve call (#674) --- tests/test_bytes.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tests/test_bytes.rs') diff --git a/tests/test_bytes.rs b/tests/test_bytes.rs index 76adfdb..e3820d7 100644 --- a/tests/test_bytes.rs +++ b/tests/test_bytes.rs @@ -598,6 +598,28 @@ fn extend_mut_from_bytes() { assert_eq!(*bytes, LONG[..]); } +#[test] +fn extend_past_lower_limit_of_size_hint() { + // See https://github.com/tokio-rs/bytes/pull/674#pullrequestreview-1913035700 + struct Iter(I); + + impl> Iterator for Iter { + type Item = u8; + + fn next(&mut self) -> Option { + self.0.next() + } + + fn size_hint(&self) -> (usize, Option) { + (5, None) + } + } + + let mut bytes = BytesMut::with_capacity(5); + bytes.extend(Iter(std::iter::repeat(0).take(10))); + assert_eq!(bytes.len(), 10); +} + #[test] fn extend_mut_without_size_hint() { let mut bytes = BytesMut::with_capacity(0); -- cgit v1.2.3