Skip to content

Commit

Permalink
#571 add Interpreter.varargCanConsumeNextValue test 2
Browse files Browse the repository at this point in the history
  • Loading branch information
remkop committed Jan 1, 2019
1 parent 8fe03e7 commit 6ab58f3
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions src/test/java/picocli/CommandLineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4013,7 +4013,38 @@ public void testVarargCanConsumeNextValue() {
class App {
@Parameters(arity = "*") List<String> all;
}
App app = CommandLine.populateCommand(new App(), "--", "a", "b");
assertEquals(Arrays.asList("a", "b"), app.all);
App app1 = CommandLine.populateCommand(new App(), "--", "a", "b");
assertEquals(Arrays.asList("a", "b"), app1.all);
}

@Test
public void testVarargCanConsumeNextValue2() {
@Command(subcommands = HelpCommand.class)
class App {
@Option(names = "-x", arity = "*") List<String> x;
@Option(names = "-y", arity = "*") List<Integer> y;
@Unmatched List<String> unmatched;
}

App app = CommandLine.populateCommand(new App(), "--", "-x", "3", "a", "b");
assertEquals(Arrays.asList("-x", "3", "a", "b"), app.unmatched);

app = CommandLine.populateCommand(new App(), "-x", "3", "a", "b");
assertEquals(Arrays.asList("3", "a", "b"), app.x);

app = CommandLine.populateCommand(new App(), "-y", "3", "a", "b");
assertNull(app.x);
assertEquals(Arrays.asList(3), app.y);
assertEquals(Arrays.asList("a", "b"), app.unmatched);

app = CommandLine.populateCommand(new App(), "-y", "3", "-x", "a", "b");
assertEquals(Arrays.asList("a", "b"), app.x);
assertEquals(Arrays.asList(3), app.y);
assertNull(app.unmatched);

app = CommandLine.populateCommand(new App(), "-y", "3", "help", "a", "b");
assertNull(app.x);
assertEquals(Arrays.asList(3), app.y);
assertNull(app.unmatched);
}
}

0 comments on commit 6ab58f3

Please sign in to comment.