Skip to content

Commit 49cc30d

Browse files
authored
Merge pull request #435 from newAM/history-buffer-clear-drop-test
HistoryBuffer: add drop test for clear
2 parents 03ef6c9 + cd29966 commit 49cc30d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/histbuf.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,4 +676,26 @@ mod tests {
676676
);
677677
}
678678
}
679+
680+
#[test]
681+
fn clear_drops_values() {
682+
static DROP_COUNT: AtomicUsize = AtomicUsize::new(0);
683+
684+
struct DropCheck {}
685+
686+
impl Drop for DropCheck {
687+
fn drop(&mut self) {
688+
DROP_COUNT.fetch_add(1, Ordering::SeqCst);
689+
}
690+
}
691+
692+
let mut x: HistoryBuffer<DropCheck, 3> = HistoryBuffer::new();
693+
x.write(DropCheck {});
694+
x.write(DropCheck {});
695+
x.write(DropCheck {});
696+
697+
assert_eq!(DROP_COUNT.load(Ordering::SeqCst), 0);
698+
x.clear();
699+
assert_eq!(DROP_COUNT.load(Ordering::SeqCst), 3);
700+
}
679701
}

0 commit comments

Comments
 (0)