Skip to content

Commit

Permalink
Add ColonCommandCompletionTest, #654
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed Feb 23, 2021
1 parent 620b187 commit d22d576
Showing 1 changed file with 45 additions and 0 deletions.
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));
}
}
}
}

0 comments on commit d22d576

Please sign in to comment.