Add test for #18908

This commit is contained in:
Tobias Bucher 2014-11-28 13:20:37 +01:00
parent fb52e69a50
commit 807066f8c9

View file

@ -2108,6 +2108,35 @@ mod tests {
assert_eq!(v.map_in_place(|_| ZeroSized).as_slice(), [ZeroSized, ZeroSized].as_slice());
}
#[test]
fn test_map_in_place_zero_drop_count() {
use std::sync::atomic;
use std::sync::atomic::AtomicUint;
#[deriving(Clone, PartialEq, Show)]
struct Nothing;
impl Drop for Nothing { fn drop(&mut self) { } }
#[deriving(Clone, PartialEq, Show)]
struct ZeroSized;
impl Drop for ZeroSized {
fn drop(&mut self) {
DROP_COUNTER.fetch_add(1, atomic::Relaxed);
}
}
const NUM_ELEMENTS: uint = 2;
static DROP_COUNTER: AtomicUint = atomic::INIT_ATOMIC_UINT;
let v = Vec::from_elem(NUM_ELEMENTS, Nothing);
DROP_COUNTER.store(0, atomic::Relaxed);
let v = v.map_in_place(|_| ZeroSized);
assert_eq!(DROP_COUNTER.load(atomic::Relaxed), 0);
drop(v);
assert_eq!(DROP_COUNTER.load(atomic::Relaxed), NUM_ELEMENTS);
}
#[test]
fn test_move_items() {
let vec = vec![1, 2, 3];