diff options
| author | Tobias Bucher <tobiasbucher5991@gmail.com> | 2014-11-28 13:20:37 +0100 |
|---|---|---|
| committer | Tobias Bucher <tobiasbucher5991@gmail.com> | 2014-11-29 00:44:22 +0100 |
| commit | 807066f8c9cacf1f8acf3a7be25c14cc46d99f58 (patch) | |
| tree | 758cd6efdbefa0849ec54c2ab26434d3524daef9 | |
| parent | fb52e69a503fbe1c5f7641655bc45def875584b3 (diff) | |
| download | rust-807066f8c9cacf1f8acf3a7be25c14cc46d99f58.tar.gz rust-807066f8c9cacf1f8acf3a7be25c14cc46d99f58.zip | |
Add test for #18908
| -rw-r--r-- | src/libcollections/vec.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 5edd3d0b780..d3ebf74fa8a 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -2109,6 +2109,35 @@ mod tests { } #[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]; let mut vec2 : Vec<i32> = vec![]; |
