Skip to content

Commit a360fd8

Browse files
committed
test(parser): Verify value terminator precedence
1 parent d5bea65 commit a360fd8

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

tests/builder/multiple_values.rs

+90
Original file line numberDiff line numberDiff line change
@@ -1456,6 +1456,96 @@ fn multiple_positional_multiple_values() {
14561456
assert_eq!(&cmd2, &["/home/clap", "foo"]);
14571457
}
14581458

1459+
#[test]
1460+
fn value_terminator_has_higher_precedence_than_allow_hyphen_values() {
1461+
let res = Command::new("do")
1462+
.arg(
1463+
Arg::new("cmd1")
1464+
.action(ArgAction::Set)
1465+
.num_args(1..)
1466+
.allow_hyphen_values(true)
1467+
.value_terminator("--foo"),
1468+
)
1469+
.arg(
1470+
Arg::new("cmd2")
1471+
.action(ArgAction::Set)
1472+
.num_args(1..)
1473+
.allow_hyphen_values(true)
1474+
.value_terminator(";"),
1475+
)
1476+
.try_get_matches_from(vec![
1477+
"do",
1478+
"find",
1479+
"-type",
1480+
"f",
1481+
"-name",
1482+
"special",
1483+
"--foo",
1484+
"/home/clap",
1485+
"foo",
1486+
]);
1487+
assert!(res.is_ok(), "{:?}", res.unwrap_err().kind());
1488+
1489+
let m = res.unwrap();
1490+
let cmd1: Vec<_> = m
1491+
.get_many::<String>("cmd1")
1492+
.unwrap()
1493+
.map(|v| v.as_str())
1494+
.collect();
1495+
assert_eq!(&cmd1, &["find", "-type", "f", "-name", "special"]);
1496+
let cmd2: Vec<_> = m
1497+
.get_many::<String>("cmd2")
1498+
.unwrap()
1499+
.map(|v| v.as_str())
1500+
.collect();
1501+
assert_eq!(&cmd2, &["/home/clap", "foo"]);
1502+
}
1503+
1504+
#[test]
1505+
fn value_terminator_restores_escaping_disabled_by_allow_hyphen_values() {
1506+
let res = Command::new("do")
1507+
.arg(
1508+
Arg::new("cmd1")
1509+
.action(ArgAction::Set)
1510+
.num_args(1..)
1511+
.allow_hyphen_values(true)
1512+
.value_terminator("--"),
1513+
)
1514+
.arg(
1515+
Arg::new("cmd2")
1516+
.action(ArgAction::Set)
1517+
.num_args(1..)
1518+
.allow_hyphen_values(true)
1519+
.value_terminator(";"),
1520+
)
1521+
.try_get_matches_from(vec![
1522+
"do",
1523+
"find",
1524+
"-type",
1525+
"f",
1526+
"-name",
1527+
"special",
1528+
"--",
1529+
"/home/clap",
1530+
"foo",
1531+
]);
1532+
assert!(res.is_ok(), "{:?}", res.unwrap_err().kind());
1533+
1534+
let m = res.unwrap();
1535+
let cmd1: Vec<_> = m
1536+
.get_many::<String>("cmd1")
1537+
.unwrap()
1538+
.map(|v| v.as_str())
1539+
.collect();
1540+
assert_eq!(&cmd1, &["find", "-type", "f", "-name", "special"]);
1541+
let cmd2: Vec<_> = m
1542+
.get_many::<String>("cmd2")
1543+
.unwrap()
1544+
.map(|v| v.as_str())
1545+
.collect();
1546+
assert_eq!(&cmd2, &["/home/clap", "foo"]);
1547+
}
1548+
14591549
#[test]
14601550
fn issue_1480_max_values_consumes_extra_arg_1() {
14611551
let res = Command::new("prog")

0 commit comments

Comments
 (0)