@@ -828,3 +828,181 @@ move_index_oob!(test_move_index_out_of_bounds_0_10, 0, 10);
828828move_index_oob ! ( test_move_index_out_of_bounds_0_max, 0 , usize :: MAX ) ;
829829move_index_oob ! ( test_move_index_out_of_bounds_10_0, 10 , 0 ) ;
830830move_index_oob ! ( test_move_index_out_of_bounds_max_0, usize :: MAX , 0 ) ;
831+
832+ #[ test]
833+ fn disjoint_mut_empty_map ( ) {
834+ let mut map: IndexMap < u32 , u32 > = IndexMap :: default ( ) ;
835+ assert_eq ! (
836+ map. get_disjoint_mut( [ & 0 , & 1 , & 2 , & 3 ] ) ,
837+ [ None , None , None , None ]
838+ ) ;
839+ }
840+
841+ #[ test]
842+ fn disjoint_mut_empty_param ( ) {
843+ let mut map: IndexMap < u32 , u32 > = IndexMap :: default ( ) ;
844+ map. insert ( 1 , 10 ) ;
845+ assert_eq ! ( map. get_disjoint_mut( [ ] as [ & u32 ; 0 ] ) , [ ] ) ;
846+ }
847+
848+ #[ test]
849+ fn disjoint_mut_single_fail ( ) {
850+ let mut map: IndexMap < u32 , u32 > = IndexMap :: default ( ) ;
851+ map. insert ( 1 , 10 ) ;
852+ assert_eq ! ( map. get_disjoint_mut( [ & 0 ] ) , [ None ] ) ;
853+ }
854+
855+ #[ test]
856+ fn disjoint_mut_single_success ( ) {
857+ let mut map: IndexMap < u32 , u32 > = IndexMap :: default ( ) ;
858+ map. insert ( 1 , 10 ) ;
859+ assert_eq ! ( map. get_disjoint_mut( [ & 1 ] ) , [ Some ( & mut 10 ) ] ) ;
860+ }
861+
862+ #[ test]
863+ fn disjoint_mut_multi_success ( ) {
864+ let mut map: IndexMap < u32 , u32 > = IndexMap :: default ( ) ;
865+ map. insert ( 1 , 100 ) ;
866+ map. insert ( 2 , 200 ) ;
867+ map. insert ( 3 , 300 ) ;
868+ map. insert ( 4 , 400 ) ;
869+ assert_eq ! (
870+ map. get_disjoint_mut( [ & 1 , & 2 ] ) ,
871+ [ Some ( & mut 100 ) , Some ( & mut 200 ) ]
872+ ) ;
873+ assert_eq ! (
874+ map. get_disjoint_mut( [ & 1 , & 3 ] ) ,
875+ [ Some ( & mut 100 ) , Some ( & mut 300 ) ]
876+ ) ;
877+ assert_eq ! (
878+ map. get_disjoint_mut( [ & 3 , & 1 , & 4 , & 2 ] ) ,
879+ [
880+ Some ( & mut 300 ) ,
881+ Some ( & mut 100 ) ,
882+ Some ( & mut 400 ) ,
883+ Some ( & mut 200 )
884+ ]
885+ ) ;
886+ }
887+
888+ #[ test]
889+ fn disjoint_mut_multi_success_unsized_key ( ) {
890+ let mut map: IndexMap < & ' static str , u32 > = IndexMap :: default ( ) ;
891+ map. insert ( "1" , 100 ) ;
892+ map. insert ( "2" , 200 ) ;
893+ map. insert ( "3" , 300 ) ;
894+ map. insert ( "4" , 400 ) ;
895+
896+ assert_eq ! (
897+ map. get_disjoint_mut( [ "1" , "2" ] ) ,
898+ [ Some ( & mut 100 ) , Some ( & mut 200 ) ]
899+ ) ;
900+ assert_eq ! (
901+ map. get_disjoint_mut( [ "1" , "3" ] ) ,
902+ [ Some ( & mut 100 ) , Some ( & mut 300 ) ]
903+ ) ;
904+ assert_eq ! (
905+ map. get_disjoint_mut( [ "3" , "1" , "4" , "2" ] ) ,
906+ [
907+ Some ( & mut 300 ) ,
908+ Some ( & mut 100 ) ,
909+ Some ( & mut 400 ) ,
910+ Some ( & mut 200 )
911+ ]
912+ ) ;
913+ }
914+
915+ #[ test]
916+ fn disjoint_mut_multi_success_borrow_key ( ) {
917+ let mut map: IndexMap < String , u32 > = IndexMap :: default ( ) ;
918+ map. insert ( "1" . into ( ) , 100 ) ;
919+ map. insert ( "2" . into ( ) , 200 ) ;
920+ map. insert ( "3" . into ( ) , 300 ) ;
921+ map. insert ( "4" . into ( ) , 400 ) ;
922+
923+ assert_eq ! (
924+ map. get_disjoint_mut( [ "1" , "2" ] ) ,
925+ [ Some ( & mut 100 ) , Some ( & mut 200 ) ]
926+ ) ;
927+ assert_eq ! (
928+ map. get_disjoint_mut( [ "1" , "3" ] ) ,
929+ [ Some ( & mut 100 ) , Some ( & mut 300 ) ]
930+ ) ;
931+ assert_eq ! (
932+ map. get_disjoint_mut( [ "3" , "1" , "4" , "2" ] ) ,
933+ [
934+ Some ( & mut 300 ) ,
935+ Some ( & mut 100 ) ,
936+ Some ( & mut 400 ) ,
937+ Some ( & mut 200 )
938+ ]
939+ ) ;
940+ }
941+
942+ #[ test]
943+ fn disjoint_mut_multi_fail_missing ( ) {
944+ let mut map: IndexMap < u32 , u32 > = IndexMap :: default ( ) ;
945+ map. insert ( 1 , 100 ) ;
946+ map. insert ( 2 , 200 ) ;
947+ map. insert ( 3 , 300 ) ;
948+ map. insert ( 4 , 400 ) ;
949+
950+ assert_eq ! ( map. get_disjoint_mut( [ & 1 , & 5 ] ) , [ Some ( & mut 100 ) , None ] ) ;
951+ assert_eq ! ( map. get_disjoint_mut( [ & 5 , & 6 ] ) , [ None , None ] ) ;
952+ assert_eq ! (
953+ map. get_disjoint_mut( [ & 1 , & 5 , & 4 ] ) ,
954+ [ Some ( & mut 100 ) , None , Some ( & mut 400 ) ]
955+ ) ;
956+ }
957+
958+ #[ test]
959+ #[ should_panic]
960+ fn disjoint_mut_multi_fail_duplicate_panic ( ) {
961+ let mut map: IndexMap < u32 , u32 > = IndexMap :: default ( ) ;
962+ map. insert ( 1 , 100 ) ;
963+ map. get_disjoint_mut ( [ & 1 , & 2 , & 1 ] ) ;
964+ }
965+
966+ #[ test]
967+ fn disjoint_indices_mut_fail_oob ( ) {
968+ let mut map: IndexMap < u32 , u32 > = IndexMap :: default ( ) ;
969+ map. insert ( 1 , 10 ) ;
970+ map. insert ( 321 , 20 ) ;
971+ assert_eq ! (
972+ map. get_disjoint_indices_mut( [ 1 , 3 ] ) ,
973+ Err ( crate :: GetDisjointMutError :: IndexOutOfBounds )
974+ ) ;
975+ }
976+
977+ #[ test]
978+ fn disjoint_indices_mut_empty ( ) {
979+ let mut map: IndexMap < u32 , u32 > = IndexMap :: default ( ) ;
980+ map. insert ( 1 , 10 ) ;
981+ map. insert ( 321 , 20 ) ;
982+ assert_eq ! ( map. get_disjoint_indices_mut( [ ] ) , Ok ( [ ] ) ) ;
983+ }
984+
985+ #[ test]
986+ fn disjoint_indices_mut_success ( ) {
987+ let mut map: IndexMap < u32 , u32 > = IndexMap :: default ( ) ;
988+ map. insert ( 1 , 10 ) ;
989+ map. insert ( 321 , 20 ) ;
990+ assert_eq ! ( map. get_disjoint_indices_mut( [ 0 ] ) , Ok ( [ ( & 1 , & mut 10 ) ] ) ) ;
991+
992+ assert_eq ! ( map. get_disjoint_indices_mut( [ 1 ] ) , Ok ( [ ( & 321 , & mut 20 ) ] ) ) ;
993+ assert_eq ! (
994+ map. get_disjoint_indices_mut( [ 0 , 1 ] ) ,
995+ Ok ( [ ( & 1 , & mut 10 ) , ( & 321 , & mut 20 ) ] )
996+ ) ;
997+ }
998+
999+ #[ test]
1000+ fn disjoint_indices_mut_fail_duplicate ( ) {
1001+ let mut map: IndexMap < u32 , u32 > = IndexMap :: default ( ) ;
1002+ map. insert ( 1 , 10 ) ;
1003+ map. insert ( 321 , 20 ) ;
1004+ assert_eq ! (
1005+ map. get_disjoint_indices_mut( [ 1 , 0 , 1 ] ) ,
1006+ Err ( crate :: GetDisjointMutError :: OverlappingIndices )
1007+ ) ;
1008+ }
0 commit comments