-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ColonCommandCompletionTest, #654
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
reader/src/test/java/org/jline/reader/impl/ColonCommandCompletionTest.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,45 @@ | ||
/* | ||
* Copyright (c) 2002-2021, 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.reader.impl; | ||
|
||
import org.jline.reader.Candidate; | ||
import org.jline.reader.Completer; | ||
import org.jline.reader.LineReader; | ||
import org.jline.reader.ParsedLine; | ||
import org.jline.utils.AttributedString; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
public class ColonCommandCompletionTest extends ReaderTestSupport { | ||
|
||
@Test | ||
public void testColonCommandCompletion() throws IOException { | ||
reader.setCompleter(new ColonCommandCompleter("power", "paste")); | ||
assertBuffer(":paste", new TestBuffer(":p\t\t")); | ||
assertBuffer(":power ", new TestBuffer(":po\t")); | ||
} | ||
|
||
private static class ColonCommandCompleter implements Completer { | ||
String[] commands; | ||
|
||
public ColonCommandCompleter(String... commands) { | ||
this.commands = commands; | ||
} | ||
|
||
@Override | ||
public void complete(LineReader reader, ParsedLine line, List<Candidate> candidates) { | ||
for (String c : commands) { | ||
candidates.add(new Candidate(":" + AttributedString.stripAnsi(c), c, null, null | ||
, null, null, true)); | ||
} | ||
} | ||
} | ||
} |