File tree 1 file changed +36
-0
lines changed
1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -214,6 +214,42 @@ mod tests {
214
214
215
215
use super :: * ;
216
216
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
+
217
253
#[ test]
218
254
fn test_insert_entry_into_vacant ( ) {
219
255
let map: DashMap < u32 , u32 > = DashMap :: new ( ) ;
You can’t perform that action at this time.
0 commit comments