Fixes some problems with TabCompletionHelper.getStringList
All checks were successful
KnarCraft/KnarLib/pipeline/head This commit looks good

This commit is contained in:
Kristian Knarvik 2024-05-04 13:59:53 +02:00
parent 1d6a3f976e
commit 5427e2a401
2 changed files with 35 additions and 1 deletions

View File

@ -50,7 +50,7 @@ public final class TabCompletionHelper {
// Filter available values by the text after the last comma only
List<String> filtered;
if (filterer != null) {
if (filterer != null && !typedText.endsWith(",")) {
filtered = filterer.apply(new ArrayList<>(values), lastArgument);
} else {
filtered = values;

View File

@ -36,6 +36,15 @@ public class TabCompletionHelperTest {
assertEquals(expected, result);
}
@Test
public void getStringListContainsTest2() {
List<String> input = List.of("ape", "ball", "car", "donut");
List<String> result = TabCompletionHelper.getStringList(input, "ball,donut,",
TabCompletionHelper::filterMatchingContains);
List<String> expected = List.of("ball,donut,ape", "ball,donut,car");
assertEquals(expected, result);
}
@Test
public void getStringListStartsWithTest() {
List<String> input = List.of("ape", "ball", "car", "donut");
@ -45,4 +54,29 @@ public class TabCompletionHelperTest {
assertEquals(expected, result);
}
@Test
public void getStringListStartsWithTest2() {
List<String> input = List.of("ape", "ball", "car", "donut");
List<String> result = TabCompletionHelper.getStringList(input, "ball,donut,",
TabCompletionHelper::filterMatchingStartsWith);
List<String> expected = List.of("ball,donut,ape", "ball,donut,car");
assertEquals(expected, result);
}
@Test
public void filterMatchingContainsTest() {
List<String> input = List.of("fish", "ape", "banana", "toy", "human", "stick", "potato", "detergent", "magazine");
List<String> result = TabCompletionHelper.filterMatchingContains(input, "a");
List<String> expected = List.of("ape", "banana", "human", "potato", "magazine");
assertEquals(expected, result);
}
@Test
public void filterMatchingStartsWithTest() {
List<String> input = List.of("fish", "ape", "banana", "toy", "human", "stick", "potato", "detergent", "magazine");
List<String> result = TabCompletionHelper.filterMatchingStartsWith(input, "a");
List<String> expected = List.of("ape");
assertEquals(expected, result);
}
}