Skip to content

Commit a7d60f6

Browse files
committed
Test [CLI-317]
Add ParserTestCase#testAmbiguousLongWithoutEqualSingleDash2()
1 parent 0140c52 commit a7d60f6

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

src/test/java/org/apache/commons/cli/ParserTestCase.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,20 @@ public void testAmbiguousLongWithoutEqualSingleDash() throws Exception {
7575
assertEquals("bar", cl.getOptionValue("foo"));
7676
}
7777

78+
public void testAmbiguousLongWithoutEqualSingleDash2() throws Exception {
79+
final String[] args = {"-b", "-foobar"};
80+
81+
final Options options = new Options();
82+
options.addOption(Option.builder().option("f").longOpt("foo").optionalArg(true).build());
83+
options.addOption(Option.builder().option("b").longOpt("bar").optionalArg(false).build());
84+
85+
final CommandLine cl = parser.parse(options, args);
86+
87+
assertTrue(cl.hasOption("b"));
88+
assertTrue(cl.hasOption("f"));
89+
assertEquals("bar", cl.getOptionValue("foo"));
90+
}
91+
7892
@Test
7993
public void testAmbiguousPartialLongOption1() throws Exception {
8094
final String[] args = {"--ver"};
@@ -471,7 +485,7 @@ public void testOptionAndRequiredOption() throws Exception {
471485
assertEquals("Confirm arg of -b", "file", cl.getOptionValue("b"));
472486
assertTrue("Confirm NO of extra args", cl.getArgList().isEmpty());
473487
}
474-
488+
475489
@Test
476490
public void testOptionGroup() throws Exception {
477491
final OptionGroup group = new OptionGroup();

0 commit comments

Comments
 (0)