-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a few tests for CompletionMatcher
- Loading branch information
Showing
3 changed files
with
49 additions
and
9 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
46 changes: 46 additions & 0 deletions
46
reader/src/test/java/org/jline/reader/impl/CompletionMatcherTest.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,46 @@ | ||
/* | ||
* 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.*; | ||
import org.junit.Test; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class CompletionMatcherTest { | ||
|
||
private CompletionMatcher compileCompletionMatcher(String line) { | ||
CompletionMatcher completionMatcher = new CompletionMatcherImpl(); | ||
Parser parser = new DefaultParser(); | ||
completionMatcher.compile(new HashMap<>(), false, LineReaderImpl.wrap(parser.parse(line, line.length())) | ||
, true, 0, ""); | ||
return completionMatcher; | ||
} | ||
|
||
@Test | ||
public void uniqueCandidates() { | ||
Candidate c = new Candidate("foo"); | ||
assertEquals("Expected only one element", 1, compileCompletionMatcher("").matches(Arrays.asList(c, c)).size()); | ||
} | ||
|
||
@Test | ||
public void test() { | ||
List<Candidate> candidates = Arrays.asList(new Candidate("foo"), new Candidate("foobar"), new Candidate("bar")); | ||
CompletionMatcher completionMatcher = compileCompletionMatcher("foo"); | ||
List<Candidate> matches = completionMatcher.matches(candidates); | ||
assertEquals("Number of matches", 2, matches.size()); | ||
Candidate candidate = completionMatcher.exactMatch(); | ||
assertEquals("Exact match", "foo", (candidate != null ? candidate.value() : null)); | ||
assertEquals("Common prefix", "foo", completionMatcher.getCommonPrefix()); | ||
} | ||
} |
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