fix: make BooleanArgument suggestions lowercase (#336)

This commit is contained in:
Brian 2022-06-07 08:18:59 -04:00 committed by Jason
parent f0e9b80c77
commit 08a97b2c4f
2 changed files with 12 additions and 4 deletions

View file

@ -34,9 +34,11 @@ import cloud.commandframework.exceptions.parsing.NoInputProvidedException;
import cloud.commandframework.exceptions.parsing.ParserException;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.Queue;
import java.util.function.BiFunction;
import java.util.stream.Collectors;
import org.apiguardian.api.API;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
@ -162,10 +164,16 @@ public final class BooleanArgument<C> extends CommandArgument<C, Boolean> {
@API(status = API.Status.STABLE)
public static final class BooleanParser<C> implements ArgumentParser<C, Boolean> {
private static final List<String> STRICT = Arrays.asList("TRUE", "FALSE");
private static final List<String> LIBERAL = Arrays.asList("TRUE", "YES", "ON", "FALSE", "NO", "OFF");
private static final List<String> LIBERAL_TRUE = Arrays.asList("TRUE", "YES", "ON");
private static final List<String> LIBERAL_FALSE = Arrays.asList("FALSE", "NO", "OFF");
private static final List<String> STRICT_LOWER = STRICT
.stream().map(s -> s.toLowerCase(Locale.ROOT)).collect(Collectors.toList());
private static final List<String> LIBERAL_LOWER = LIBERAL
.stream().map(s -> s.toLowerCase(Locale.ROOT)).collect(Collectors.toList());
private final boolean liberal;
/**
@ -225,10 +233,10 @@ public final class BooleanArgument<C> extends CommandArgument<C, Boolean> {
final @NonNull String input
) {
if (!this.liberal) {
return Arrays.asList("TRUE", "FALSE");
return STRICT_LOWER;
}
return LIBERAL;
return LIBERAL_LOWER;
}
@Override

View file

@ -148,8 +148,8 @@ class BooleanParserTest {
static Stream<Arguments> Suggestions_ExpectedSuggestions_Source() {
return Stream.of(
Arguments.arguments(false, ArgumentTestHelper.linkedListOf("TRUE", "FALSE")),
Arguments.arguments(true, ArgumentTestHelper.linkedListOf("TRUE", "YES", "ON", "FALSE", "NO", "OFF"))
Arguments.arguments(false, ArgumentTestHelper.linkedListOf("true", "false")),
Arguments.arguments(true, ArgumentTestHelper.linkedListOf("true", "yes", "on", "false", "no", "off"))
);
}
}