-
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.
Fix broken TreeCompleter and RegexCompleter, fixes #224
- Loading branch information
Showing
2 changed files
with
61 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
54 changes: 54 additions & 0 deletions
54
builtins/src/test/java/org/jline/builtins/CompletersTest.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,54 @@ | ||
/* | ||
* Copyright (c) 2002-2018, 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. | ||
* | ||
* http://www.opensource.org/licenses/bsd-license.php | ||
*/ | ||
package org.jline.builtins; | ||
|
||
import org.jline.reader.Candidate; | ||
import org.jline.reader.Completer; | ||
import org.jline.reader.LineReader; | ||
import org.jline.reader.ParsedLine; | ||
import org.jline.reader.impl.DefaultParser; | ||
import org.junit.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.jline.builtins.Completers.TreeCompleter.node; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
public class CompletersTest { | ||
|
||
@Test | ||
public void testTreeCompleter() { | ||
List<String> words = new ArrayList<>(); | ||
Completer test = new Completer() { | ||
@Override | ||
public void complete(LineReader reader, ParsedLine line, List<Candidate> candidates) { | ||
words.add(line.word()); | ||
candidates.add(new Candidate("Param1")); | ||
candidates.add(new Candidate("Param2")); | ||
} | ||
}; | ||
Completer completer = new Completers.TreeCompleter( | ||
node("Command1", | ||
node("Option1", | ||
node(test)), | ||
node("Option2"), | ||
node("Option3"))); | ||
List<Candidate> candidates = new ArrayList<>(); | ||
completer.complete( | ||
null, | ||
new DefaultParser().parse("Command1 Option1 ", "Command1 Option1 ".length()), | ||
candidates); | ||
assertEquals(2, candidates.size()); | ||
assertEquals("Param1", candidates.get(0).value()); | ||
assertEquals("Param2", candidates.get(1).value()); | ||
assertEquals(1, words.size()); | ||
assertEquals("", words.get(0)); | ||
} | ||
} |