regression test for leaks in the the Filter::next_chunk implementation

previously next_chunk would forget items rejected by the filter
This commit is contained in:
The 8472 2024-06-25 23:22:27 +02:00
parent 2be2d77c50
commit 0d7aef9738

View File

@ -1,4 +1,5 @@
use core::iter::*;
use std::rc::Rc;
#[test]
fn test_iterator_filter_count() {
@ -50,3 +51,15 @@ fn test_double_ended_filter() {
assert_eq!(it.next().unwrap(), &2);
assert_eq!(it.next_back(), None);
}
#[test]
fn test_next_chunk_does_not_leak() {
let drop_witness: [_; 5] = std::array::from_fn(|_| Rc::new(()));
let v = (0..5).map(|i| drop_witness[i].clone()).collect::<Vec<_>>();
let _ = v.into_iter().filter(|_| false).next_chunk::<1>();
for ref w in drop_witness {
assert_eq!(Rc::strong_count(w), 1);
}
}