@@ -1318,24 +1318,41 @@ mod tests {
1318
1318
1319
1319
#[test]
1320
1320
fn test_multi() {
1321
- let args = ~[~" -e", ~" foo", ~" --encrypt", ~" foo"];
1322
1321
let opts = ~[optopt(" e"), optopt(" encrypt"), optopt(" f")];
1323
- let matches = &match getopts(args, opts) {
1322
+
1323
+ let args_single = ~[~" -e", ~" foo"];
1324
+ let matches_single = &match getopts(args_single, opts) {
1325
+ result::Ok(m) => m,
1326
+ result::Err(_) => fail!()
1327
+ };
1328
+ assert!(opts_present(matches_single, [~" e"]));
1329
+ assert!(opts_present(matches_single, [~" encrypt", ~" e"]));
1330
+ assert!(opts_present(matches_single, [~" e", ~" encrypt"]));
1331
+ assert!(!opts_present(matches_single, [~" encrypt"]));
1332
+ assert!(!opts_present(matches_single, [~" thing"]));
1333
+ assert!(!opts_present(matches_single, []));
1334
+
1335
+ assert_eq!(opts_str(matches_single, [~" e"]), ~" foo");
1336
+ assert_eq!(opts_str(matches_single, [~" e", ~" encrypt"]), ~" foo");
1337
+ assert_eq!(opts_str(matches_single, [~" encrypt", ~" e"]), ~" foo");
1338
+
1339
+ let args_both = ~[~" -e", ~" foo", ~" --encrypt", ~" foo"];
1340
+ let matches_both = &match getopts(args_both, opts) {
1324
1341
result::Ok(m) => m,
1325
1342
result::Err(_) => fail!()
1326
1343
};
1327
- assert!(opts_present(matches , [~" e"]));
1328
- assert!(opts_present(matches , [~" encrypt"]));
1329
- assert!(opts_present(matches , [~" encrypt", ~" e"]));
1330
- assert!(opts_present(matches , [~" e", ~" encrypt"]));
1331
- assert!(!opts_present(matches , [~" f"]));
1332
- assert!(!opts_present(matches , [~" thing"]));
1333
- assert!(!opts_present(matches , []));
1334
-
1335
- assert_eq!(opts_str(matches , [~" e"]), ~" foo");
1336
- assert_eq!(opts_str(matches , [~" encrypt"]), ~" foo");
1337
- assert_eq!(opts_str(matches , [~" e", ~" encrypt"]), ~" foo");
1338
- assert_eq!(opts_str(matches , [~" encrypt", ~" e"]), ~" foo");
1344
+ assert!(opts_present(matches_both , [~" e"]));
1345
+ assert!(opts_present(matches_both , [~" encrypt"]));
1346
+ assert!(opts_present(matches_both , [~" encrypt", ~" e"]));
1347
+ assert!(opts_present(matches_both , [~" e", ~" encrypt"]));
1348
+ assert!(!opts_present(matches_both , [~" f"]));
1349
+ assert!(!opts_present(matches_both , [~" thing"]));
1350
+ assert!(!opts_present(matches_both , []));
1351
+
1352
+ assert_eq!(opts_str(matches_both , [~" e"]), ~" foo");
1353
+ assert_eq!(opts_str(matches_both , [~" encrypt"]), ~" foo");
1354
+ assert_eq!(opts_str(matches_both , [~" e", ~" encrypt"]), ~" foo");
1355
+ assert_eq!(opts_str(matches_both , [~" encrypt", ~" e"]), ~" foo");
1339
1356
}
1340
1357
1341
1358
#[test]
0 commit comments