@@ -2385,3 +2385,67 @@ fn test_cursor_mut() {
23852385 assert_eq ! ( cur. key( ) , Some ( & 4 ) ) ;
23862386 assert_eq ! ( map, BTreeMap :: from( [ ( 0 , '?' ) , ( 1 , 'a' ) , ( 3 , 'c' ) , ( 4 , 'd' ) ] ) ) ;
23872387}
2388+
2389+ #[ should_panic( expected = "key must be ordered above the previous element" ) ]
2390+ #[ test]
2391+ fn test_cursor_mut_insert_before_1 ( ) {
2392+ let mut map = BTreeMap :: from ( [ ( 1 , 'a' ) , ( 2 , 'b' ) , ( 3 , 'c' ) ] ) ;
2393+ let mut cur = map. upper_bound_mut ( Bound :: Included ( & 2 ) ) ;
2394+ cur. insert_before ( 0 , 'd' ) ;
2395+ }
2396+
2397+ #[ should_panic( expected = "key must be ordered above the previous element" ) ]
2398+ #[ test]
2399+ fn test_cursor_mut_insert_before_2 ( ) {
2400+ let mut map = BTreeMap :: from ( [ ( 1 , 'a' ) , ( 2 , 'b' ) , ( 3 , 'c' ) ] ) ;
2401+ let mut cur = map. upper_bound_mut ( Bound :: Included ( & 2 ) ) ;
2402+ cur. insert_before ( 1 , 'd' ) ;
2403+ }
2404+
2405+ #[ should_panic( expected = "key must be ordered below the current element" ) ]
2406+ #[ test]
2407+ fn test_cursor_mut_insert_before_3 ( ) {
2408+ let mut map = BTreeMap :: from ( [ ( 1 , 'a' ) , ( 2 , 'b' ) , ( 3 , 'c' ) ] ) ;
2409+ let mut cur = map. upper_bound_mut ( Bound :: Included ( & 2 ) ) ;
2410+ cur. insert_before ( 2 , 'd' ) ;
2411+ }
2412+
2413+ #[ should_panic( expected = "key must be ordered below the current element" ) ]
2414+ #[ test]
2415+ fn test_cursor_mut_insert_before_4 ( ) {
2416+ let mut map = BTreeMap :: from ( [ ( 1 , 'a' ) , ( 2 , 'b' ) , ( 3 , 'c' ) ] ) ;
2417+ let mut cur = map. upper_bound_mut ( Bound :: Included ( & 2 ) ) ;
2418+ cur. insert_before ( 3 , 'd' ) ;
2419+ }
2420+
2421+ #[ should_panic( expected = "key must be ordered above the current element" ) ]
2422+ #[ test]
2423+ fn test_cursor_mut_insert_after_1 ( ) {
2424+ let mut map = BTreeMap :: from ( [ ( 1 , 'a' ) , ( 2 , 'b' ) , ( 3 , 'c' ) ] ) ;
2425+ let mut cur = map. upper_bound_mut ( Bound :: Included ( & 2 ) ) ;
2426+ cur. insert_after ( 1 , 'd' ) ;
2427+ }
2428+
2429+ #[ should_panic( expected = "key must be ordered above the current element" ) ]
2430+ #[ test]
2431+ fn test_cursor_mut_insert_after_2 ( ) {
2432+ let mut map = BTreeMap :: from ( [ ( 1 , 'a' ) , ( 2 , 'b' ) , ( 3 , 'c' ) ] ) ;
2433+ let mut cur = map. upper_bound_mut ( Bound :: Included ( & 2 ) ) ;
2434+ cur. insert_after ( 2 , 'd' ) ;
2435+ }
2436+
2437+ #[ should_panic( expected = "key must be ordered below the next element" ) ]
2438+ #[ test]
2439+ fn test_cursor_mut_insert_after_3 ( ) {
2440+ let mut map = BTreeMap :: from ( [ ( 1 , 'a' ) , ( 2 , 'b' ) , ( 3 , 'c' ) ] ) ;
2441+ let mut cur = map. upper_bound_mut ( Bound :: Included ( & 2 ) ) ;
2442+ cur. insert_after ( 3 , 'd' ) ;
2443+ }
2444+
2445+ #[ should_panic( expected = "key must be ordered below the next element" ) ]
2446+ #[ test]
2447+ fn test_cursor_mut_insert_after_4 ( ) {
2448+ let mut map = BTreeMap :: from ( [ ( 1 , 'a' ) , ( 2 , 'b' ) , ( 3 , 'c' ) ] ) ;
2449+ let mut cur = map. upper_bound_mut ( Bound :: Included ( & 2 ) ) ;
2450+ cur. insert_after ( 4 , 'd' ) ;
2451+ }
0 commit comments