@@ -981,6 +981,161 @@ a_pos,c_pos"
981981 ) ;
982982}
983983
984+ #[ test]
985+ fn suggest_allow_hyhpen ( ) {
986+ let mut cmd = Command :: new ( "exhaustive" )
987+ . arg (
988+ clap:: Arg :: new ( "format" )
989+ . long ( "format" )
990+ . short ( 'F' )
991+ . allow_hyphen_values ( true )
992+ . value_parser ( [ "--json" , "--toml" , "--yaml" ] ) ,
993+ )
994+ . arg ( clap:: Arg :: new ( "json" ) . long ( "json" ) ) ;
995+
996+ assert_data_eq ! ( complete!( cmd, "--format --j[TAB]" ) , snapbox:: str ![ "--json" ] ) ;
997+ assert_data_eq ! ( complete!( cmd, "-F --j[TAB]" ) , snapbox:: str ![ "--json" ] ) ;
998+ assert_data_eq ! ( complete!( cmd, "--format --t[TAB]" ) , snapbox:: str ![ "--toml" ] ) ;
999+ assert_data_eq ! ( complete!( cmd, "-F --t[TAB]" ) , snapbox:: str ![ "--toml" ] ) ;
1000+
1001+ assert_data_eq ! (
1002+ complete!( cmd, "--format --[TAB]" ) ,
1003+ snapbox:: str ![
1004+ "--json
1005+ --toml
1006+ --yaml"
1007+ ]
1008+ ) ;
1009+
1010+ assert_data_eq ! (
1011+ complete!( cmd, "-F --[TAB]" ) ,
1012+ snapbox:: str ![
1013+ "--json
1014+ --toml
1015+ --yaml"
1016+ ]
1017+ ) ;
1018+
1019+ assert_data_eq ! (
1020+ complete!( cmd, "--format --json --j[TAB]" ) ,
1021+ snapbox:: str ![ "" ]
1022+ ) ;
1023+
1024+ assert_data_eq ! ( complete!( cmd, "-F --json --j[TAB]" ) , snapbox:: str ![ "" ] ) ;
1025+ }
1026+
1027+ #[ test]
1028+ fn suggest_positional_long_allow_hyhpen ( ) {
1029+ let mut cmd = Command :: new ( "exhaustive" )
1030+ . arg (
1031+ clap:: Arg :: new ( "format" )
1032+ . long ( "format" )
1033+ . short ( 'F' )
1034+ . allow_hyphen_values ( true )
1035+ . value_parser ( [ "--json" , "--toml" , "--yaml" ] ) ,
1036+ )
1037+ . arg (
1038+ clap:: Arg :: new ( "positional_a" )
1039+ . value_parser ( [ "--pos_a" ] )
1040+ . index ( 1 )
1041+ . allow_hyphen_values ( true ) ,
1042+ )
1043+ . arg (
1044+ clap:: Arg :: new ( "positional_b" )
1045+ . index ( 2 )
1046+ . value_parser ( [ "pos_b" ] ) ,
1047+ ) ;
1048+
1049+ assert_data_eq ! (
1050+ complete!( cmd, "--format --json --pos[TAB]" ) ,
1051+ snapbox:: str ![ "--pos_a" ]
1052+ ) ;
1053+ assert_data_eq ! (
1054+ complete!( cmd, "-F --json --pos[TAB]" ) ,
1055+ snapbox:: str ![ "--pos_a" ]
1056+ ) ;
1057+
1058+ assert_data_eq ! (
1059+ complete!( cmd, "--format --json --pos_a [TAB]" ) ,
1060+ snapbox:: str ![
1061+ "--format
1062+ --help Print help
1063+ -F
1064+ -h Print help
1065+ --pos_a"
1066+ ]
1067+ ) ;
1068+ assert_data_eq ! (
1069+ complete!( cmd, "-F --json --pos_a [TAB]" ) ,
1070+ snapbox:: str ![
1071+ "--format
1072+ --help Print help
1073+ -F
1074+ -h Print help
1075+ --pos_a"
1076+ ]
1077+ ) ;
1078+
1079+ assert_data_eq ! (
1080+ complete!( cmd, "--format --json --pos_a p[TAB]" ) ,
1081+ snapbox:: str ![ "" ]
1082+ ) ;
1083+ assert_data_eq ! (
1084+ complete!( cmd, "-F --json --pos_a p[TAB]" ) ,
1085+ snapbox:: str ![ "" ]
1086+ ) ;
1087+ }
1088+
1089+ #[ test]
1090+ fn suggest_positional_short_allow_hyhpen ( ) {
1091+ let mut cmd = Command :: new ( "exhaustive" )
1092+ . arg (
1093+ clap:: Arg :: new ( "format" )
1094+ . long ( "format" )
1095+ . short ( 'F' )
1096+ . allow_hyphen_values ( true )
1097+ . value_parser ( [ "--json" , "--toml" , "--yaml" ] ) ,
1098+ )
1099+ . arg (
1100+ clap:: Arg :: new ( "positional_a" )
1101+ . value_parser ( [ "-a" ] )
1102+ . index ( 1 )
1103+ . allow_hyphen_values ( true ) ,
1104+ )
1105+ . arg (
1106+ clap:: Arg :: new ( "positional_b" )
1107+ . index ( 2 )
1108+ . value_parser ( [ "pos_b" ] ) ,
1109+ ) ;
1110+
1111+ assert_data_eq ! (
1112+ complete!( cmd, "--format --json -a [TAB]" ) ,
1113+ snapbox:: str ![
1114+ "--format
1115+ --help Print help
1116+ -F
1117+ -h Print help
1118+ -a"
1119+ ]
1120+ ) ;
1121+ assert_data_eq ! (
1122+ complete!( cmd, "-F --json -a [TAB]" ) ,
1123+ snapbox:: str ![
1124+ "--format
1125+ --help Print help
1126+ -F
1127+ -h Print help
1128+ -a"
1129+ ]
1130+ ) ;
1131+
1132+ assert_data_eq ! (
1133+ complete!( cmd, "--format --json -a p[TAB]" ) ,
1134+ snapbox:: str ![ "" ]
1135+ ) ;
1136+ assert_data_eq ! ( complete!( cmd, "-F --json -a p[TAB]" ) , snapbox:: str ![ "" ] ) ;
1137+ }
1138+
9841139fn complete ( cmd : & mut Command , args : impl AsRef < str > , current_dir : Option < & Path > ) -> String {
9851140 let input = args. as_ref ( ) ;
9861141 let mut args = vec ! [ std:: ffi:: OsString :: from( cmd. get_name( ) ) ] ;
0 commit comments