Skip to content

Commit 32ce516

Browse files
author
Gianmarco Garrisi
committed
Added test coverage for the Entry API
1 parent e7903e7 commit 32ce516

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/lib.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,4 +1741,27 @@ mod tests {
17411741
map.extend(vec![(5, 6)]);
17421742
assert_eq!(map.into_iter().collect::<Vec<_>>(), vec![(1, 2), (3, 4), (5, 6)]);
17431743
}
1744+
1745+
#[test]
1746+
fn entry() {
1747+
let mut map = OrderMap::new();
1748+
1749+
map.insert(1, "1");
1750+
map.insert(2, "2");
1751+
{
1752+
let e = map.entry(3);
1753+
assert_eq!(e.index(), 2);
1754+
let e = e.or_insert("3");
1755+
assert_eq!(e, &"3");
1756+
}
1757+
1758+
let e = map.entry(2);
1759+
assert_eq!(e.index(), 1);
1760+
assert_eq!(e.key(), &2);
1761+
match e {
1762+
Entry::Occupied(ref e) => assert_eq!(e.get(), &"2"),
1763+
Entry::Vacant(_) => panic!()
1764+
}
1765+
assert_eq!(e.or_insert("4"), &"2");
1766+
}
17441767
}

0 commit comments

Comments
 (0)