:sparkes: Add @Suggestions annotated methods

This commit is contained in:
Alexander Söderberg 2020-12-15 02:03:30 +01:00 committed by Alexander Söderberg
parent 3efd9bfffb
commit ab366be24d
6 changed files with 207 additions and 0 deletions

View file

@ -26,7 +26,9 @@ package cloud.commandframework.annotations;
import cloud.commandframework.Command;
import cloud.commandframework.CommandManager;
import cloud.commandframework.annotations.specifier.Range;
import cloud.commandframework.annotations.suggestions.Suggestions;
import cloud.commandframework.arguments.standard.StringArgument;
import cloud.commandframework.context.CommandContext;
import cloud.commandframework.meta.SimpleCommandMeta;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
@ -43,6 +45,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletionException;
import java.util.function.BiFunction;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class AnnotationParserTest {
@ -129,6 +132,20 @@ class AnnotationParserTest {
manager.executeCommand(new TestCommandSender(), "inject").join();
}
@Test
void testAnnotatedSuggestionsProviders() {
final BiFunction<CommandContext<TestCommandSender>, String, List<String>> suggestionsProvider =
this.manager.getParserRegistry().getSuggestionProvider("cows").orElse(null);
Assertions.assertNotNull(suggestionsProvider);
Assertions.assertTrue(suggestionsProvider.apply(new CommandContext<>(new TestCommandSender(), manager), "")
.contains("Stella"));
}
@Suggestions("cows")
public List<String> cowSuggestions(final CommandContext<TestCommandSender> context, final String input) {
return Arrays.asList("Stella", "Bella", "Agda");
}
@ProxiedBy("proxycommand")
@CommandMethod("test|t literal <int> [string]")
public void testCommand(