Skip to content

Commit

Permalink
[#1055] added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
remkop committed Jun 28, 2020
1 parent d1b2176 commit 03e7985
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/test/java/picocli/ArgGroupTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2099,7 +2099,7 @@ public void testIssue1054RegressionTest() {

//-f pattern -w text --> accepted --> ok
Issue1054 bean2 = new Issue1054();
new CommandLine(bean2).parseArgs("-f pattern -w text".split(" "));
new CommandLine(bean2).parseArgs("-f pattern -w text".split(" ")); // also mentioned in #1055
assertEquals(1, bean2.modifications.size());
assertEquals("pattern", bean2.modifications.get(0).findPattern.pattern());
assertFalse(bean2.modifications.get(0).change.delete);
Expand All @@ -2122,6 +2122,30 @@ public void testIssue1054RegressionTest() {
}
}

@Test // https://github.com/remkop/picocli/issues/1055
public void testIssue1055Case1() {
//-f -f -w text --> accepted --> wrong: findPattern = "-f", means, the second -f is treated as an option-parameter for the first -f
try {
Issue1054 bean = new Issue1054();
new CommandLine(bean).parseArgs("-f -f -w text".split(" "));
fail("Expected exception");
} catch (MissingParameterException ex) {
assertEquals("Expected parameter for option '--find' but found '-f'", ex.getMessage());
}
}

@Test // https://github.com/remkop/picocli/issues/1055
public void testIssue1055Case2() {
//-f pattern -w -d --> wrong: replacement = "-d", means -d is treated as an option-parameter for -w
try {
Issue1054 bean = new Issue1054();
new CommandLine(bean).parseArgs("-f pattern -w -d".split(" "));
fail("Expected exception");
} catch (MissingParameterException ex) {
assertEquals("Expected parameter for option '--replace-with' but found '-d'", ex.getMessage());
}
}

static class CompositeGroupSynopsisDemo {

@ArgGroup(exclusive = false, multiplicity = "2..*")
Expand Down

0 comments on commit 03e7985

Please sign in to comment.