@Test(expected = NullPointerException.class) public void testCompleteDisallowsNullSpec() { AutoComplete.complete(null, new String[] {"-x"}, 0, 0, 0, new ArrayList<CharSequence>()); }
words = line.words().toArray(words); List<CharSequence> cs = new ArrayList<CharSequence>(); AutoComplete.complete(spec, words, line.wordIndex(),
@Override public int complete(String buffer, int cursor, List<CharSequence> candidates) { // use the jline internal parser to split the line into tokens ArgumentCompleter.ArgumentList list = new ArgumentCompleter.WhitespaceArgumentDelimiter().delimit(buffer, cursor); // let picocli generate completion candidates for the token where the cursor is at return AutoComplete.complete(commandSpec, list.getArguments(), list.getCursorArgumentIndex(), list.getArgumentPosition(), cursor, candidates); } }
private static void test(CommandSpec spec, String[] args, int argIndex, int positionInArg, int cursor, List<CharSequence> expected) { List<CharSequence> actual = new ArrayList<CharSequence>(); AutoComplete.complete(spec, args, argIndex, positionInArg, cursor, actual); Collections.sort(actual, new CharSequenceSort()); Collections.sort(expected, new CharSequenceSort()); assertEquals(expected, actual); }
/** * Populates the specified list with completion candidates for the specified buffer * based on the command specification that this shell was constructed with. * * @param buffer the command line string * @param cursor the position of the cursor in the command line string * @param candidates the list to populate with completion candidates that would produce * valid options, parameters or subcommands at the cursor position * in the command line * @return the cursor position in the buffer for which the completion will be relative, * or {@code -1} if no completions are found */ //@Override public int complete(String buffer, int cursor, List<CharSequence> candidates) { // use the jline internal parser to split the line into tokens ArgumentCompleter.ArgumentList list = new ArgumentCompleter.WhitespaceArgumentDelimiter().delimit(buffer, cursor); // let picocli generate completion candidates for the token where the cursor is at return AutoComplete.complete(spec, list.getArguments(), list.getCursorArgumentIndex(), list.getArgumentPosition(), cursor, candidates); } }
@Test public void testCompleteAllowsNormalValues() { List<CharSequence> candidates = new ArrayList<CharSequence>(); AutoComplete.complete(CommandSpec.create().addOption(OptionSpec.builder("-x").build()), new String[] {"-x"}, 0, 0, 0, candidates); assertFalse(candidates.isEmpty()); }
@Test(expected = IllegalArgumentException.class) public void testCompleteDisallowsNegativeArgIndex() { AutoComplete.complete(CommandSpec.create().addOption(OptionSpec.builder("-x").build()), new String[] {"-x"}, -1, 0, 0, new ArrayList<CharSequence>()); }
@Test(expected = IllegalArgumentException.class) public void testCompleteDisallowsTooLargeArgIndex() { AutoComplete.complete(CommandSpec.create().addOption(OptionSpec.builder("-x").build()), new String[] {"-x"}, 2, 0, 0, new ArrayList<CharSequence>()); }
@Test(expected = IllegalArgumentException.class) public void testCompleteDisallowsNegativePositionInArg() { AutoComplete.complete(CommandSpec.create().addOption(OptionSpec.builder("-x").build()), new String[] {"-x"}, 0, -1, 0, new ArrayList<CharSequence>()); }
@Test(expected = NullPointerException.class) public void testCompleteDisallowsNullArgs() { AutoComplete.complete(CommandSpec.create().addOption(OptionSpec.builder("-x").build()), null, 0, 0, 0, new ArrayList<CharSequence>()); }
@Test(expected = IllegalArgumentException.class) public void testCompleteDisallowsTooLargePositionInArg() { AutoComplete.complete(CommandSpec.create().addOption(OptionSpec.builder("-x").build()), new String[] {"-x"}, 0, 3, 0, new ArrayList<CharSequence>()); }
@Test(expected = NullPointerException.class) public void testCompleteDisallowsNullCandidates() { AutoComplete.complete(CommandSpec.create().addOption(OptionSpec.builder("-x").build()), new String[] {"-x"}, 0, 0, 0, null); }
@Test(expected = NullPointerException.class) public void testCompleteDisallowsNullSpec() { AutoComplete.complete(null, new String[] {"-x"}, 0, 0, 0, new ArrayList<CharSequence>()); }
private static void test(CommandSpec spec, String[] args, int argIndex, int positionInArg, int cursor, List<CharSequence> expected) { List<CharSequence> actual = new ArrayList<CharSequence>(); AutoComplete.complete(spec, args, argIndex, positionInArg, cursor, actual); Collections.sort(actual, new CharSequenceSort()); Collections.sort(expected, new CharSequenceSort()); assertEquals(expected, actual); }
@Test public void testCompleteAllowsNormalValues() { List<CharSequence> candidates = new ArrayList<CharSequence>(); AutoComplete.complete(CommandSpec.create().addOption(OptionSpec.builder("-x").build()), new String[] {"-x"}, 0, 0, 0, candidates); assertFalse(candidates.isEmpty()); }
@Test(expected = IllegalArgumentException.class) public void testCompleteDisallowsTooLargeArgIndex() { AutoComplete.complete(CommandSpec.create().addOption(OptionSpec.builder("-x").build()), new String[] {"-x"}, 2, 0, 0, new ArrayList<CharSequence>()); }
@Test(expected = NullPointerException.class) public void testCompleteDisallowsNullArgs() { AutoComplete.complete(CommandSpec.create().addOption(OptionSpec.builder("-x").build()), null, 0, 0, 0, new ArrayList<CharSequence>()); }
@Test(expected = IllegalArgumentException.class) public void testCompleteDisallowsNegativeArgIndex() { AutoComplete.complete(CommandSpec.create().addOption(OptionSpec.builder("-x").build()), new String[] {"-x"}, -1, 0, 0, new ArrayList<CharSequence>()); }
@Test(expected = IllegalArgumentException.class) public void testCompleteDisallowsTooLargePositionInArg() { AutoComplete.complete(CommandSpec.create().addOption(OptionSpec.builder("-x").build()), new String[] {"-x"}, 0, 3, 0, new ArrayList<CharSequence>()); }
@Test(expected = NullPointerException.class) public void testCompleteDisallowsNullCandidates() { AutoComplete.complete(CommandSpec.create().addOption(OptionSpec.builder("-x").build()), new String[] {"-x"}, 0, 0, 0, null); }