fix: make BooleanArgument suggestions lowercase (#336)
This commit is contained in:
parent
f0e9b80c77
commit
08a97b2c4f
2 changed files with 12 additions and 4 deletions
|
|
@ -34,9 +34,11 @@ import cloud.commandframework.exceptions.parsing.NoInputProvidedException;
|
||||||
import cloud.commandframework.exceptions.parsing.ParserException;
|
import cloud.commandframework.exceptions.parsing.ParserException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import org.apiguardian.api.API;
|
import org.apiguardian.api.API;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
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)
|
@API(status = API.Status.STABLE)
|
||||||
public static final class BooleanParser<C> implements ArgumentParser<C, Boolean> {
|
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 = 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_TRUE = Arrays.asList("TRUE", "YES", "ON");
|
||||||
private static final List<String> LIBERAL_FALSE = Arrays.asList("FALSE", "NO", "OFF");
|
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;
|
private final boolean liberal;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -225,10 +233,10 @@ public final class BooleanArgument<C> extends CommandArgument<C, Boolean> {
|
||||||
final @NonNull String input
|
final @NonNull String input
|
||||||
) {
|
) {
|
||||||
if (!this.liberal) {
|
if (!this.liberal) {
|
||||||
return Arrays.asList("TRUE", "FALSE");
|
return STRICT_LOWER;
|
||||||
}
|
}
|
||||||
|
|
||||||
return LIBERAL;
|
return LIBERAL_LOWER;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -148,8 +148,8 @@ class BooleanParserTest {
|
||||||
|
|
||||||
static Stream<Arguments> Suggestions_ExpectedSuggestions_Source() {
|
static Stream<Arguments> Suggestions_ExpectedSuggestions_Source() {
|
||||||
return Stream.of(
|
return Stream.of(
|
||||||
Arguments.arguments(false, ArgumentTestHelper.linkedListOf("TRUE", "FALSE")),
|
Arguments.arguments(false, ArgumentTestHelper.linkedListOf("true", "false")),
|
||||||
Arguments.arguments(true, ArgumentTestHelper.linkedListOf("TRUE", "YES", "ON", "FALSE", "NO", "OFF"))
|
Arguments.arguments(true, ArgumentTestHelper.linkedListOf("true", "yes", "on", "false", "no", "off"))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue