Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pczarn committed Mar 5, 2016
1 parent c20cd8f commit 0adcd64
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions src/libstd/collections/hash/map.rs
Expand Up @@ -1706,6 +1706,20 @@ mod test_map {
assert_eq!(*m.get(&2).unwrap(), 4);
}

#[test]
fn test_clone() {
let mut m = HashMap::new();
assert_eq!(m.len(), 0);
assert!(m.insert(1, 2).is_none());
assert_eq!(m.len(), 1);
assert!(m.insert(2, 4).is_none());
assert_eq!(m.len(), 2);
let m2 = m.clone();
assert_eq!(*m2.get(&1).unwrap(), 2);
assert_eq!(*m2.get(&2).unwrap(), 4);
assert_eq!(m2.len(), 2);
}

thread_local! { static DROP_VECTOR: RefCell<Vec<isize>> = RefCell::new(Vec::new()) }

#[derive(Hash, PartialEq, Eq)]
Expand Down Expand Up @@ -1797,7 +1811,7 @@ mod test_map {
}

#[test]
fn test_move_iter_drops() {
fn test_into_iter_drops() {
DROP_VECTOR.with(|v| {
*v.borrow_mut() = vec![0; 200];
});
Expand Down Expand Up @@ -1862,11 +1876,35 @@ mod test_map {
}

#[test]
fn test_empty_pop() {
fn test_empty_remove() {
let mut m: HashMap<isize, bool> = HashMap::new();
assert_eq!(m.remove(&0), None);
}

#[test]
fn test_empty_entry() {
let mut m: HashMap<isize, bool> = HashMap::new();
match m.entry(0) {
Occupied(_) => panic!(),
Vacant(_) => {}
}
assert!(*m.entry(0).or_insert(true));
assert_eq!(m.len(), 1);
}

#[test]
fn test_empty_iter() {
let mut m: HashMap<isize, bool> = HashMap::new();
assert_eq!(m.drain().next(), None);
assert_eq!(m.keys().next(), None);
assert_eq!(m.values().next(), None);
assert_eq!(m.iter().next(), None);
assert_eq!(m.iter_mut().next(), None);
assert_eq!(m.len(), 0);
assert!(m.is_empty());
assert_eq!(m.into_iter().next(), None);
}

#[test]
fn test_lots_of_insertions() {
let mut m = HashMap::new();
Expand Down

0 comments on commit 0adcd64

Please sign in to comment.