-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OptionCompleter: added a test, script and improved comment
- Loading branch information
Showing
5 changed files
with
95 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
builtins/src/test/java/org/jline/builtins/OptionCompleterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright (c) 2002-2020, the original author or authors. | ||
* | ||
* This software is distributable under the BSD license. See the terms of the | ||
* BSD license in the documentation provided with this software. | ||
* | ||
* https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
package org.jline.builtins; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.ArrayList; | ||
|
||
import org.jline.builtins.Completers.OptionCompleter; | ||
import org.jline.builtins.Completers.OptDesc; | ||
import org.jline.reader.LineReader; | ||
import org.jline.reader.impl.completer.NullCompleter; | ||
import org.jline.reader.impl.completer.StringsCompleter; | ||
import org.jline.reader.impl.completer.ArgumentCompleter; | ||
import org.jline.reader.Completer; | ||
import org.junit.Test; | ||
|
||
|
||
public class OptionCompleterTest extends ReaderTestSupport { | ||
|
||
@Test | ||
public void testOptions() throws Exception { | ||
List<Completer> argsCompleters = new ArrayList<>(); | ||
List<OptDesc> options = new ArrayList<>(); | ||
argsCompleters.add(new StringsCompleter("bar", "rab")); | ||
argsCompleters.add(new StringsCompleter("foo", "oof")); | ||
argsCompleters.add(NullCompleter.INSTANCE); | ||
options.add(new OptDesc("-s", "--sopt", new StringsCompleter("val", "lav"))); | ||
options.add(new OptDesc(null, "--option", NullCompleter.INSTANCE)); | ||
|
||
reader.setCompleter(new ArgumentCompleter(new StringsCompleter("command"), | ||
new OptionCompleter(argsCompleters, options, 1)) | ||
); | ||
|
||
assertBuffer("command ", new TestBuffer("c").tab()); | ||
assertBuffer("command -s", new TestBuffer("command -").tab()); | ||
assertBuffer("command -s val ", new TestBuffer("command -s v").tab()); | ||
assertBuffer("command -s val bar ", new TestBuffer("command -s val b").tab()); | ||
assertBuffer("command -s val bar --option ", new TestBuffer("command -s val bar --o").tab()); | ||
assertBuffer("command -s val bar --option foo ", new TestBuffer("command -s val bar --option f").tab()); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import org.jline.reader.impl.completer.* | ||
import org.jline.reader.* | ||
import org.jline.builtins.Completers.OptionCompleter | ||
import org.jline.builtins.SystemRegistry | ||
|
||
def complete(commandLine) { | ||
candidates = [] | ||
completer.complete(reader, parser.parse(commandLine, commandLine.length(), Parser.ParseContext.ACCEPT_LINE), candidates) | ||
candidates.each { println it.value()} | ||
} | ||
|
||
reader=null // reader is not really needed here! | ||
parser=SystemRegistry.get().parser | ||
|
||
options=['--opt1','--opt2'] | ||
optionValues=['--option':['val1','val2'],'--option2':['val3','val4']] | ||
optionCompleter = new OptionCompleter(Arrays.asList(new StringsCompleter("p1", "p11") | ||
, new StringsCompleter("p2", "p22"), NullCompleter.INSTANCE) | ||
, optionValues, options, 1) | ||
completer = new ArgumentCompleter(new StringsCompleter("Command1"), optionCompleter) | ||
# | ||
# test completer... | ||
# | ||
complete('Comm') | ||
complete('Command1 --') | ||
complete('Command1 --option=') | ||
complete('Command1 --option=val1 ') | ||
complete('Command1 p1 ') |
This file was deleted.
Oops, something went wrong.
09f14e5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#502