Skip to content

Commit 0ed8713

Browse files
committed
Modify test to expose issue #6492.
1 parent 576f395 commit 0ed8713

File tree

1 file changed

+31
-14
lines changed

1 file changed

+31
-14
lines changed

src/libextra/getopts.rs

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,24 +1318,41 @@ mod tests {
13181318
13191319
#[test]
13201320
fn test_multi() {
1321-
let args = ~[~"-e", ~"foo", ~"--encrypt", ~"foo"];
13221321
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) {
13241341
result::Ok(m) => m,
13251342
result::Err(_) => fail!()
13261343
};
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");
13391356
}
13401357
13411358
#[test]

0 commit comments

Comments
 (0)