@@ -1066,6 +1066,7 @@ mod tests {
1066
1066
. arg ( Arg :: from_usage ( "--color [color] 'some other flag'" ) )
1067
1067
. get_matches_from ( vec ! [ "" , "--flag" , "some" , "--color" , "other" ] ) ;
1068
1068
assert ! ( m. is_present( "color" ) ) ;
1069
+ assert_eq ! ( m. value_of( "color" ) . unwrap( ) , "other" ) ;
1069
1070
assert ! ( !m. is_present( "flag" ) ) ;
1070
1071
1071
1072
let m = App :: new ( "posix" )
@@ -1074,6 +1075,7 @@ mod tests {
1074
1075
. get_matches_from ( vec ! [ "" , "--color" , "some" , "--flag" , "other" ] ) ;
1075
1076
assert ! ( !m. is_present( "color" ) ) ;
1076
1077
assert ! ( m. is_present( "flag" ) ) ;
1078
+ assert_eq ! ( m. value_of( "flag" ) . unwrap( ) , "other" ) ;
1077
1079
}
1078
1080
1079
1081
#[ test]
@@ -1083,6 +1085,7 @@ mod tests {
1083
1085
. arg ( Arg :: from_usage ( "--color [color] 'some other flag'" ) )
1084
1086
. get_matches_from ( vec ! [ "" , "--flag=some" , "--color=other" ] ) ;
1085
1087
assert ! ( m. is_present( "color" ) ) ;
1088
+ assert_eq ! ( m. value_of( "color" ) . unwrap( ) , "other" ) ;
1086
1089
assert ! ( !m. is_present( "flag" ) ) ;
1087
1090
1088
1091
let m = App :: new ( "posix" )
@@ -1091,6 +1094,7 @@ mod tests {
1091
1094
. get_matches_from ( vec ! [ "" , "--color=some" , "--flag=other" ] ) ;
1092
1095
assert ! ( !m. is_present( "color" ) ) ;
1093
1096
assert ! ( m. is_present( "flag" ) ) ;
1097
+ assert_eq ! ( m. value_of( "flag" ) . unwrap( ) , "other" ) ;
1094
1098
}
1095
1099
1096
1100
#[ test]
@@ -1100,6 +1104,7 @@ mod tests {
1100
1104
. arg ( Arg :: from_usage ( "-c [color] 'some other flag'" ) )
1101
1105
. get_matches_from ( vec ! [ "" , "-f" , "some" , "-c" , "other" ] ) ;
1102
1106
assert ! ( m. is_present( "color" ) ) ;
1107
+ assert_eq ! ( m. value_of( "color" ) . unwrap( ) , "other" ) ;
1103
1108
assert ! ( !m. is_present( "flag" ) ) ;
1104
1109
1105
1110
let m = App :: new ( "posix" )
@@ -1108,5 +1113,133 @@ mod tests {
1108
1113
. get_matches_from ( vec ! [ "" , "-c" , "some" , "-f" , "other" ] ) ;
1109
1114
assert ! ( !m. is_present( "color" ) ) ;
1110
1115
assert ! ( m. is_present( "flag" ) ) ;
1116
+ assert_eq ! ( m. value_of( "flag" ) . unwrap( ) , "other" ) ;
1111
1117
}
1118
+
1119
+ #[ test]
1120
+ fn opts_using_short ( ) {
1121
+ let m = App :: new ( "opts" )
1122
+ . args ( vec ! [
1123
+ Arg :: from_usage( "-f [flag] 'some flag'" ) ,
1124
+ Arg :: from_usage( "-c [color] 'some other flag'" )
1125
+ ] )
1126
+ . get_matches_from ( vec ! [ "" , "-f" , "some" , "-c" , "other" ] ) ;
1127
+ assert ! ( m. is_present( "flag" ) ) ;
1128
+ assert_eq ! ( m. value_of( "flag" ) . unwrap( ) , "some" ) ;
1129
+ assert ! ( m. is_present( "color" ) ) ;
1130
+ assert_eq ! ( m. value_of( "color" ) . unwrap( ) , "other" ) ;
1131
+ }
1132
+
1133
+ #[ test]
1134
+ fn opts_using_long_space ( ) {
1135
+ let m = App :: new ( "opts" )
1136
+ . args ( vec ! [
1137
+ Arg :: from_usage( "--flag [flag] 'some flag'" ) ,
1138
+ Arg :: from_usage( "--color [color] 'some other flag'" )
1139
+ ] )
1140
+ . get_matches_from ( vec ! [ "" , "--flag" , "some" , "--color" , "other" ] ) ;
1141
+ assert ! ( m. is_present( "flag" ) ) ;
1142
+ assert_eq ! ( m. value_of( "flag" ) . unwrap( ) , "some" ) ;
1143
+ assert ! ( m. is_present( "color" ) ) ;
1144
+ assert_eq ! ( m. value_of( "color" ) . unwrap( ) , "other" ) ;
1145
+ }
1146
+
1147
+ #[ test]
1148
+ fn opts_using_long_equals ( ) {
1149
+ let m = App :: new ( "opts" )
1150
+ . args ( vec ! [
1151
+ Arg :: from_usage( "--flag [flag] 'some flag'" ) ,
1152
+ Arg :: from_usage( "--color [color] 'some other flag'" )
1153
+ ] )
1154
+ . get_matches_from ( vec ! [ "" , "--flag=some" , "--color=other" ] ) ;
1155
+ assert ! ( m. is_present( "flag" ) ) ;
1156
+ assert_eq ! ( m. value_of( "flag" ) . unwrap( ) , "some" ) ;
1157
+ assert ! ( m. is_present( "color" ) ) ;
1158
+ assert_eq ! ( m. value_of( "color" ) . unwrap( ) , "other" ) ;
1159
+ }
1160
+
1161
+ #[ test]
1162
+ fn opts_using_mixed ( ) {
1163
+ let m = App :: new ( "opts" )
1164
+ . args ( vec ! [
1165
+ Arg :: from_usage( "-f, --flag [flag] 'some flag'" ) ,
1166
+ Arg :: from_usage( "-c, --color [color] 'some other flag'" )
1167
+ ] )
1168
+ . get_matches_from ( vec ! [ "" , "-f" , "some" , "--color" , "other" ] ) ;
1169
+ assert ! ( m. is_present( "flag" ) ) ;
1170
+ assert_eq ! ( m. value_of( "flag" ) . unwrap( ) , "some" ) ;
1171
+ assert ! ( m. is_present( "color" ) ) ;
1172
+ assert_eq ! ( m. value_of( "color" ) . unwrap( ) , "other" ) ;
1173
+
1174
+ let m = App :: new ( "opts" )
1175
+ . args ( vec ! [
1176
+ Arg :: from_usage( "-f, --flag [flag] 'some flag'" ) ,
1177
+ Arg :: from_usage( "-c, --color [color] 'some other flag'" )
1178
+ ] )
1179
+ . get_matches_from ( vec ! [ "" , "--flag=some" , "-c" , "other" ] ) ;
1180
+ assert ! ( m. is_present( "flag" ) ) ;
1181
+ assert_eq ! ( m. value_of( "flag" ) . unwrap( ) , "some" ) ;
1182
+ assert ! ( m. is_present( "color" ) ) ;
1183
+ assert_eq ! ( m. value_of( "color" ) . unwrap( ) , "other" ) ;
1184
+ }
1185
+
1186
+ #[ test]
1187
+ fn flag_using_short ( ) {
1188
+ let m = App :: new ( "flag" )
1189
+ . args ( vec ! [
1190
+ Arg :: from_usage( "-f, --flag 'some flag'" ) ,
1191
+ Arg :: from_usage( "-c, --color 'some other flag'" )
1192
+ ] )
1193
+ . get_matches_from ( vec ! [ "" , "-f" , "-c" ] ) ;
1194
+ assert ! ( m. is_present( "flag" ) ) ;
1195
+ assert ! ( m. is_present( "color" ) ) ;
1196
+ }
1197
+
1198
+ #[ test]
1199
+ fn flag_using_long ( ) {
1200
+ let m = App :: new ( "flag" )
1201
+ . args ( vec ! [
1202
+ Arg :: from_usage( "--flag 'some flag'" ) ,
1203
+ Arg :: from_usage( "--color 'some other flag'" )
1204
+ ] )
1205
+ . get_matches_from ( vec ! [ "" , "--flag" , "--color" ] ) ;
1206
+ assert ! ( m. is_present( "flag" ) ) ;
1207
+ assert ! ( m. is_present( "color" ) ) ;
1208
+ }
1209
+
1210
+ #[ test]
1211
+ fn flag_using_mixed ( ) {
1212
+ let m = App :: new ( "flag" )
1213
+ . args ( vec ! [
1214
+ Arg :: from_usage( "-f, --flag 'some flag'" ) ,
1215
+ Arg :: from_usage( "-c, --color 'some other flag'" )
1216
+ ] )
1217
+ . get_matches_from ( vec ! [ "" , "-f" , "--color" ] ) ;
1218
+ assert ! ( m. is_present( "flag" ) ) ;
1219
+ assert ! ( m. is_present( "color" ) ) ;
1220
+
1221
+ let m = App :: new ( "flag" )
1222
+ . args ( vec ! [
1223
+ Arg :: from_usage( "-f, --flag 'some flag'" ) ,
1224
+ Arg :: from_usage( "-c, --color 'some other flag'" )
1225
+ ] )
1226
+ . get_matches_from ( vec ! [ "" , "--flag" , "-c" ] ) ;
1227
+ assert ! ( m. is_present( "flag" ) ) ;
1228
+ assert ! ( m. is_present( "color" ) ) ;
1229
+ }
1230
+
1231
+ #[ test]
1232
+ fn multiple_flags_in_single ( ) {
1233
+ let m = App :: new ( "multe_flags" )
1234
+ . args ( vec ! [
1235
+ Arg :: from_usage( "-f, --flag 'some flag'" ) ,
1236
+ Arg :: from_usage( "-c, --color 'some other flag'" ) ,
1237
+ Arg :: from_usage( "-d, --debug 'another other flag'" )
1238
+ ] )
1239
+ . get_matches_from ( vec ! [ "" , "-fcd" ] ) ;
1240
+ assert ! ( m. is_present( "flag" ) ) ;
1241
+ assert ! ( m. is_present( "color" ) ) ;
1242
+ assert ! ( m. is_present( "debug" ) ) ;
1243
+ }
1244
+
1112
1245
}
0 commit comments