Skip to content

Commit a784833

Browse files
Add Entry test
1 parent f893b20 commit a784833

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/mapref/entry.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,42 @@ mod tests {
214214

215215
use super::*;
216216

217+
#[test]
218+
fn test_insert_into_vacant() {
219+
let map: DashMap<u32, u32> = DashMap::new();
220+
221+
let entry = map.entry(1);
222+
223+
assert!(matches!(entry, Entry::Vacant(_)));
224+
225+
let val = entry.insert(2);
226+
227+
assert_eq!(*val, 2);
228+
229+
drop(val);
230+
231+
assert_eq!(*map.get(&1).unwrap(), 2);
232+
}
233+
234+
#[test]
235+
fn test_insert_into_occupied() {
236+
let map: DashMap<u32, u32> = DashMap::new();
237+
238+
map.insert(1, 1000);
239+
240+
let entry = map.entry(1);
241+
242+
assert!(matches!(&entry, Entry::Occupied(entry) if *entry.get() == 1000));
243+
244+
let val = entry.insert(2);
245+
246+
assert_eq!(*val, 2);
247+
248+
drop(val);
249+
250+
assert_eq!(*map.get(&1).unwrap(), 2);
251+
}
252+
217253
#[test]
218254
fn test_insert_entry_into_vacant() {
219255
let map: DashMap<u32, u32> = DashMap::new();

0 commit comments

Comments
 (0)