Skip to content

Commit d8c4475

Browse files
committed
Add test that every value is dropped exactly once
1 parent 3020945 commit d8c4475

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/test.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,36 @@ fn test_consuming_iter_with_free_list() {
222222
assert_eq!(None, iter.next());
223223
}
224224

225+
#[test]
226+
fn test_into_iter_drop() {
227+
struct Counter<'a>(&'a mut usize);
228+
229+
impl<'a> Drop for Counter<'a> {
230+
fn drop(&mut self) {
231+
*self.0 += 1;
232+
}
233+
}
234+
235+
let mut a = 0;
236+
let mut b = 0;
237+
let mut c = 0;
238+
239+
{
240+
let mut map = LinkedHashMap::new();
241+
map.insert("a", Counter(&mut a));
242+
map.insert("b", Counter(&mut b));
243+
map.insert("c", Counter(&mut c));
244+
245+
let mut iter = map.into_iter();
246+
iter.next();
247+
iter.next_back();
248+
}
249+
250+
assert_eq!(a, 1);
251+
assert_eq!(b, 1);
252+
assert_eq!(c, 1);
253+
}
254+
225255
#[test]
226256
fn test_borrow() {
227257
#[derive(PartialEq, Eq, Hash)] struct Foo(Bar);

0 commit comments

Comments
 (0)