diff --git a/build.gradle b/build.gradle index 521a630c..b06823e3 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ import groovy.io.FileType apply plugin: 'java-library' apply plugin: 'maven' -version = '0.1.19' +version = '0.1.21' group = 'com.mojang' task wrapper(type: Wrapper) { diff --git a/src/main/java/com/mojang/brigadier/AmbiguityConsumer.java b/src/main/java/com/mojang/brigadier/AmbiguityConsumer.java new file mode 100644 index 00000000..09158fa0 --- /dev/null +++ b/src/main/java/com/mojang/brigadier/AmbiguityConsumer.java @@ -0,0 +1,10 @@ +package com.mojang.brigadier; + +import com.mojang.brigadier.tree.CommandNode; + +import java.util.Collection; + +@FunctionalInterface +public interface AmbiguityConsumer { + void ambiguous(final CommandNode parent, final CommandNode child, final CommandNode sibling, final Collection inputs); +} diff --git a/src/main/java/com/mojang/brigadier/CommandDispatcher.java b/src/main/java/com/mojang/brigadier/CommandDispatcher.java index 2be3124d..389f3452 100644 --- a/src/main/java/com/mojang/brigadier/CommandDispatcher.java +++ b/src/main/java/com/mojang/brigadier/CommandDispatcher.java @@ -427,6 +427,10 @@ public CommandNode findNode(final Collection path) { return node; } + public void findAmbiguities(final AmbiguityConsumer consumer) { + root.findAmbiguities(consumer); + } + private void addPaths(final CommandNode node, final List>> result, final List> parents) { final List> current = new ArrayList<>(parents); current.add(node); diff --git a/src/main/java/com/mojang/brigadier/arguments/ArgumentType.java b/src/main/java/com/mojang/brigadier/arguments/ArgumentType.java index 7798d106..e09036eb 100644 --- a/src/main/java/com/mojang/brigadier/arguments/ArgumentType.java +++ b/src/main/java/com/mojang/brigadier/arguments/ArgumentType.java @@ -7,12 +7,18 @@ import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.suggestion.SuggestionsBuilder; +import java.util.Collection; +import java.util.Collections; import java.util.concurrent.CompletableFuture; public interface ArgumentType { - T parse(StringReader reader, CommandContextBuilder contextBuilder) throws CommandSyntaxException; + T parse(StringReader reader) throws CommandSyntaxException; default CompletableFuture listSuggestions(final CommandContext context, final SuggestionsBuilder builder) { return Suggestions.empty(); } + + default Collection getExamples() { + return Collections.emptyList(); + } } diff --git a/src/main/java/com/mojang/brigadier/arguments/BoolArgumentType.java b/src/main/java/com/mojang/brigadier/arguments/BoolArgumentType.java index 2181c5b1..4c711321 100644 --- a/src/main/java/com/mojang/brigadier/arguments/BoolArgumentType.java +++ b/src/main/java/com/mojang/brigadier/arguments/BoolArgumentType.java @@ -7,9 +7,13 @@ import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.suggestion.SuggestionsBuilder; +import java.util.Arrays; +import java.util.Collection; import java.util.concurrent.CompletableFuture; public class BoolArgumentType implements ArgumentType { + private static final Collection EXAMPLES = Arrays.asList("true", "false"); + private BoolArgumentType() { } @@ -22,7 +26,7 @@ public static boolean getBool(final CommandContext context, final String name } @Override - public Boolean parse(final StringReader reader, final CommandContextBuilder contextBuilder) throws CommandSyntaxException { + public Boolean parse(final StringReader reader) throws CommandSyntaxException { return reader.readBoolean(); } @@ -36,4 +40,9 @@ public CompletableFuture listSuggestions(final CommandContext getExamples() { + return EXAMPLES; + } } diff --git a/src/main/java/com/mojang/brigadier/arguments/DoubleArgumentType.java b/src/main/java/com/mojang/brigadier/arguments/DoubleArgumentType.java index fb115c93..f77f61c0 100644 --- a/src/main/java/com/mojang/brigadier/arguments/DoubleArgumentType.java +++ b/src/main/java/com/mojang/brigadier/arguments/DoubleArgumentType.java @@ -6,9 +6,13 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.ParameterizedCommandExceptionType; +import java.util.Arrays; +import java.util.Collection; + public class DoubleArgumentType implements ArgumentType { public static final ParameterizedCommandExceptionType ERROR_TOO_SMALL = new ParameterizedCommandExceptionType("argument.double.low", "Double must not be less than ${minimum}, found ${found}", "found", "minimum"); public static final ParameterizedCommandExceptionType ERROR_TOO_BIG = new ParameterizedCommandExceptionType("argument.double.big", "Double must not be more than ${maximum}, found ${found}", "found", "maximum"); + private static final Collection EXAMPLES = Arrays.asList("0", "1.2", ".5", "-1", "-.5", "-1234.56"); private final double minimum; private final double maximum; @@ -43,7 +47,7 @@ public double getMaximum() { } @Override - public Double parse(final StringReader reader, final CommandContextBuilder contextBuilder) throws CommandSyntaxException { + public Double parse(final StringReader reader) throws CommandSyntaxException { final int start = reader.getCursor(); final double result = reader.readDouble(); if (result < minimum) { @@ -81,4 +85,9 @@ public String toString() { return "double(" + minimum + ", " + maximum + ")"; } } + + @Override + public Collection getExamples() { + return EXAMPLES; + } } diff --git a/src/main/java/com/mojang/brigadier/arguments/FloatArgumentType.java b/src/main/java/com/mojang/brigadier/arguments/FloatArgumentType.java index 9f719a9b..f7a57641 100644 --- a/src/main/java/com/mojang/brigadier/arguments/FloatArgumentType.java +++ b/src/main/java/com/mojang/brigadier/arguments/FloatArgumentType.java @@ -6,9 +6,13 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.ParameterizedCommandExceptionType; +import java.util.Arrays; +import java.util.Collection; + public class FloatArgumentType implements ArgumentType { public static final ParameterizedCommandExceptionType ERROR_TOO_SMALL = new ParameterizedCommandExceptionType("argument.float.low", "Float must not be less than ${minimum}, found ${found}", "found", "minimum"); public static final ParameterizedCommandExceptionType ERROR_TOO_BIG = new ParameterizedCommandExceptionType("argument.float.big", "Float must not be more than ${maximum}, found ${found}", "found", "maximum"); + private static final Collection EXAMPLES = Arrays.asList("0", "1.2", ".5", "-1", "-.5", "-1234.56"); private final float minimum; private final float maximum; @@ -43,7 +47,7 @@ public float getMaximum() { } @Override - public Float parse(final StringReader reader, final CommandContextBuilder contextBuilder) throws CommandSyntaxException { + public Float parse(final StringReader reader) throws CommandSyntaxException { final int start = reader.getCursor(); final float result = reader.readFloat(); if (result < minimum) { @@ -81,4 +85,9 @@ public String toString() { return "float(" + minimum + ", " + maximum + ")"; } } + + @Override + public Collection getExamples() { + return EXAMPLES; + } } diff --git a/src/main/java/com/mojang/brigadier/arguments/IntegerArgumentType.java b/src/main/java/com/mojang/brigadier/arguments/IntegerArgumentType.java index fc2b6815..757e9f31 100644 --- a/src/main/java/com/mojang/brigadier/arguments/IntegerArgumentType.java +++ b/src/main/java/com/mojang/brigadier/arguments/IntegerArgumentType.java @@ -6,9 +6,13 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.ParameterizedCommandExceptionType; +import java.util.Arrays; +import java.util.Collection; + public class IntegerArgumentType implements ArgumentType { public static final ParameterizedCommandExceptionType ERROR_TOO_SMALL = new ParameterizedCommandExceptionType("argument.integer.low", "Integer must not be less than ${minimum}, found ${found}", "found", "minimum"); public static final ParameterizedCommandExceptionType ERROR_TOO_BIG = new ParameterizedCommandExceptionType("argument.integer.big", "Integer must not be more than ${maximum}, found ${found}", "found", "maximum"); + private static final Collection EXAMPLES = Arrays.asList("0", "123", "-123"); private final int minimum; private final int maximum; @@ -43,7 +47,7 @@ public int getMaximum() { } @Override - public Integer parse(final StringReader reader, final CommandContextBuilder contextBuilder) throws CommandSyntaxException { + public Integer parse(final StringReader reader) throws CommandSyntaxException { final int start = reader.getCursor(); final int result = reader.readInt(); if (result < minimum) { diff --git a/src/main/java/com/mojang/brigadier/arguments/StringArgumentType.java b/src/main/java/com/mojang/brigadier/arguments/StringArgumentType.java index a494b14d..9f572e54 100644 --- a/src/main/java/com/mojang/brigadier/arguments/StringArgumentType.java +++ b/src/main/java/com/mojang/brigadier/arguments/StringArgumentType.java @@ -1,11 +1,13 @@ package com.mojang.brigadier.arguments; -import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.StringReader; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.context.CommandContextBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; +import java.util.Arrays; +import java.util.Collection; + public class StringArgumentType implements ArgumentType { private final StringType type; @@ -34,7 +36,7 @@ public StringType getType() { } @Override - public String parse(final StringReader reader, final CommandContextBuilder contextBuilder) throws CommandSyntaxException { + public String parse(final StringReader reader) throws CommandSyntaxException { if (type == StringType.GREEDY_PHRASE) { final String text = reader.getRemaining(); reader.setCursor(reader.getTotalLength()); @@ -51,6 +53,11 @@ public String toString() { return "string()"; } + @Override + public Collection getExamples() { + return type.getExamples(); + } + public static String escapeIfRequired(final String input) { for (final char c : input.toCharArray()) { if (!StringReader.isAllowedInUnquotedString(c)) { @@ -76,8 +83,18 @@ private static String escape(final String input) { } public enum StringType { - SINGLE_WORD, - QUOTABLE_PHRASE, - GREEDY_PHRASE, + SINGLE_WORD("word", "words_with_underscores"), + QUOTABLE_PHRASE("\"quoted phrase\"", "word", "\"\""), + GREEDY_PHRASE("word", "words with spaces", "\"and symbols\""),; + + private final Collection examples; + + StringType(final String... examples) { + this.examples = Arrays.asList(examples); + } + + public Collection getExamples() { + return examples; + } } } diff --git a/src/main/java/com/mojang/brigadier/tree/ArgumentCommandNode.java b/src/main/java/com/mojang/brigadier/tree/ArgumentCommandNode.java index e6d8820c..db154072 100644 --- a/src/main/java/com/mojang/brigadier/tree/ArgumentCommandNode.java +++ b/src/main/java/com/mojang/brigadier/tree/ArgumentCommandNode.java @@ -13,6 +13,7 @@ import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.suggestion.SuggestionsBuilder; +import java.util.Collection; import java.util.concurrent.CompletableFuture; import java.util.function.Predicate; @@ -52,7 +53,7 @@ public SuggestionProvider getCustomSuggestions() { @Override public void parse(final StringReader reader, final CommandContextBuilder contextBuilder) throws CommandSyntaxException { final int start = reader.getCursor(); - final T result = type.parse(reader, contextBuilder); + final T result = type.parse(reader); final ParsedArgument parsed = new ParsedArgument<>(start, reader.getCursor(), result); contextBuilder.withArgument(name, parsed); @@ -80,6 +81,17 @@ public RequiredArgumentBuilder createBuilder() { return builder; } + @Override + public boolean isValidInput(final String input) { + try { + final StringReader reader = new StringReader(input); + type.parse(reader); + return !reader.canRead() || reader.peek() == ' '; + } catch (final CommandSyntaxException ignored) { + return false; + } + } + @Override public boolean equals(final Object o) { if (this == o) return true; @@ -103,4 +115,9 @@ public int hashCode() { protected String getSortedKey() { return name; } + + @Override + public Collection getExamples() { + return type.getExamples(); + } } diff --git a/src/main/java/com/mojang/brigadier/tree/CommandNode.java b/src/main/java/com/mojang/brigadier/tree/CommandNode.java index 723a2f84..23477166 100644 --- a/src/main/java/com/mojang/brigadier/tree/CommandNode.java +++ b/src/main/java/com/mojang/brigadier/tree/CommandNode.java @@ -2,6 +2,8 @@ import com.google.common.collect.ComparisonChain; import com.google.common.collect.Maps; +import com.google.common.collect.Sets; +import com.mojang.brigadier.AmbiguityConsumer; import com.mojang.brigadier.Command; import com.mojang.brigadier.RedirectModifier; import com.mojang.brigadier.StringReader; @@ -16,6 +18,7 @@ import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; +import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -77,6 +80,18 @@ public void addChild(final CommandNode node) { child.addChild(grandchild); } } else { + for (final CommandNode sibling : children.values()) { + for (final String example : node.getExamples()) { + if (sibling.isValidInput(example)) { + System.out.println("Ambiguity detected in " + getName() + ", siblings " + sibling.getName() + " and " + node.getName() + " can both parse '" + example + "' successfully"); + } + } + for (final String example : sibling.getExamples()) { + if (node.isValidInput(example)) { + System.out.println("Ambiguity detected in " + getName() + ", siblings " + sibling.getName() + " and " + node.getName() + " can both parse '" + example + "' successfully"); + } + } + } children.put(node.getName(), node); if (node instanceof LiteralCommandNode) { literals.put(node.getName(), (LiteralCommandNode) node); @@ -88,6 +103,33 @@ public void addChild(final CommandNode node) { children = children.entrySet().stream().sorted(Map.Entry.comparingByValue()).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new)); } + public void findAmbiguities(final AmbiguityConsumer consumer) { + Set matches = Sets.newHashSet(); + + for (final CommandNode child : children.values()) { + for (final CommandNode sibling : children.values()) { + if (child == sibling) { + continue; + } + + for (final String input : child.getExamples()) { + if (sibling.isValidInput(input)) { + matches.add(input); + } + } + + if (matches.size() > 0) { + consumer.ambiguous(this, child, sibling, matches); + matches = Sets.newHashSet(); + } + } + + child.findAmbiguities(consumer); + } + } + + protected abstract boolean isValidInput(final String input); + @Override public boolean equals(final Object o) { if (this == o) return true; @@ -153,4 +195,6 @@ public int compareTo(final CommandNode o) { public boolean isFork() { return forks; } + + public abstract Collection getExamples(); } diff --git a/src/main/java/com/mojang/brigadier/tree/LiteralCommandNode.java b/src/main/java/com/mojang/brigadier/tree/LiteralCommandNode.java index 3c202979..705c9f32 100644 --- a/src/main/java/com/mojang/brigadier/tree/LiteralCommandNode.java +++ b/src/main/java/com/mojang/brigadier/tree/LiteralCommandNode.java @@ -12,6 +12,8 @@ import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.suggestion.SuggestionsBuilder; +import java.util.Collection; +import java.util.Collections; import java.util.concurrent.CompletableFuture; import java.util.function.Predicate; @@ -36,18 +38,30 @@ public String getName() { @Override public void parse(final StringReader reader, final CommandContextBuilder contextBuilder) throws CommandSyntaxException { + final int start = reader.getCursor(); + final int end = parse(reader); + if (end > -1) { + contextBuilder.withNode(this, StringRange.between(start, end)); + return; + } + + throw ERROR_INCORRECT_LITERAL.createWithContext(reader, literal); + } + + private int parse(final StringReader reader) { final int start = reader.getCursor(); if (reader.canRead(literal.length())) { final int end = start + literal.length(); if (reader.getString().substring(start, end).equals(literal)) { reader.setCursor(end); - contextBuilder.withNode(this, StringRange.between(start, end)); - return; + if (!reader.canRead() || reader.peek() == ' ') { + return end; + } else { + reader.setCursor(start); + } } } - - reader.setCursor(start); - throw ERROR_INCORRECT_LITERAL.createWithContext(reader, literal); + return -1; } @Override @@ -59,6 +73,11 @@ public CompletableFuture listSuggestions(final CommandContext co } } + @Override + public boolean isValidInput(final String input) { + return parse(new StringReader(input)) > -1; + } + @Override public boolean equals(final Object o) { if (this == o) return true; @@ -97,4 +116,9 @@ public LiteralArgumentBuilder createBuilder() { protected String getSortedKey() { return literal; } + + @Override + public Collection getExamples() { + return Collections.singleton(literal); + } } diff --git a/src/main/java/com/mojang/brigadier/tree/RootCommandNode.java b/src/main/java/com/mojang/brigadier/tree/RootCommandNode.java index a0ac6090..12fcbf5b 100644 --- a/src/main/java/com/mojang/brigadier/tree/RootCommandNode.java +++ b/src/main/java/com/mojang/brigadier/tree/RootCommandNode.java @@ -8,6 +8,7 @@ import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.suggestion.SuggestionsBuilder; +import java.util.Collection; import java.util.Collections; import java.util.concurrent.CompletableFuture; @@ -35,6 +36,11 @@ public CompletableFuture listSuggestions(final CommandContext co return Suggestions.empty(); } + @Override + public boolean isValidInput(final String input) { + return false; + } + @Override public boolean equals(final Object o) { if (this == o) return true; @@ -51,4 +57,9 @@ public boolean equals(final Object o) { protected String getSortedKey() { return ""; } + + @Override + public Collection getExamples() { + return Collections.emptyList(); + } } diff --git a/src/test/java/com/mojang/brigadier/arguments/BoolArgumentTypeTest.java b/src/test/java/com/mojang/brigadier/arguments/BoolArgumentTypeTest.java index 7b0cfae4..42de17ea 100644 --- a/src/test/java/com/mojang/brigadier/arguments/BoolArgumentTypeTest.java +++ b/src/test/java/com/mojang/brigadier/arguments/BoolArgumentTypeTest.java @@ -9,7 +9,6 @@ import org.mockito.runners.MockitoJUnitRunner; import static com.mojang.brigadier.arguments.BoolArgumentType.bool; -import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; import static org.mockito.Mockito.mock; @@ -31,7 +30,7 @@ public void setUp() throws Exception { public void parse() throws Exception { final StringReader reader = mock(StringReader.class); when(reader.readBoolean()).thenReturn(true); - assertThat(type.parse(reader, context), is(true)); + assertThat(type.parse(reader), is(true)); verify(reader).readBoolean(); } } \ No newline at end of file diff --git a/src/test/java/com/mojang/brigadier/arguments/DoubleArgumentTypeTest.java b/src/test/java/com/mojang/brigadier/arguments/DoubleArgumentTypeTest.java index 148f714a..3578f489 100644 --- a/src/test/java/com/mojang/brigadier/arguments/DoubleArgumentTypeTest.java +++ b/src/test/java/com/mojang/brigadier/arguments/DoubleArgumentTypeTest.java @@ -32,7 +32,7 @@ public void setUp() throws Exception { @Test public void parse() throws Exception { final StringReader reader = new StringReader("15"); - assertThat(doubleArg().parse(reader, context), is(15.0)); + assertThat(doubleArg().parse(reader), is(15.0)); assertThat(reader.canRead(), is(false)); } @@ -40,7 +40,7 @@ public void parse() throws Exception { public void parse_tooSmall() throws Exception { final StringReader reader = new StringReader("-5"); try { - doubleArg(0, 100).parse(reader, context); + doubleArg(0, 100).parse(reader); fail(); } catch (final CommandSyntaxException ex) { assertThat(ex.getType(), is(DoubleArgumentType.ERROR_TOO_SMALL)); @@ -53,7 +53,7 @@ public void parse_tooSmall() throws Exception { public void parse_tooBig() throws Exception { final StringReader reader = new StringReader("5"); try { - doubleArg(-100, 0).parse(reader, context); + doubleArg(-100, 0).parse(reader); fail(); } catch (final CommandSyntaxException ex) { assertThat(ex.getType(), is(DoubleArgumentType.ERROR_TOO_BIG)); diff --git a/src/test/java/com/mojang/brigadier/arguments/FloatArgumentTypeTest.java b/src/test/java/com/mojang/brigadier/arguments/FloatArgumentTypeTest.java index d0cef81b..8a359857 100644 --- a/src/test/java/com/mojang/brigadier/arguments/FloatArgumentTypeTest.java +++ b/src/test/java/com/mojang/brigadier/arguments/FloatArgumentTypeTest.java @@ -1,7 +1,6 @@ package com.mojang.brigadier.arguments; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Sets; import com.google.common.testing.EqualsTester; import com.mojang.brigadier.StringReader; import com.mojang.brigadier.context.CommandContextBuilder; @@ -10,13 +9,9 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.runners.MockitoJUnitRunner; -import java.util.Set; - import static com.mojang.brigadier.arguments.FloatArgumentType.floatArg; -import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasToString; import static org.hamcrest.Matchers.is; @@ -37,7 +32,7 @@ public void setUp() throws Exception { @Test public void parse() throws Exception { final StringReader reader = new StringReader("15"); - assertThat(floatArg().parse(reader, context), is(15f)); + assertThat(floatArg().parse(reader), is(15f)); assertThat(reader.canRead(), is(false)); } @@ -45,7 +40,7 @@ public void parse() throws Exception { public void parse_tooSmall() throws Exception { final StringReader reader = new StringReader("-5"); try { - floatArg(0, 100).parse(reader, context); + floatArg(0, 100).parse(reader); fail(); } catch (final CommandSyntaxException ex) { assertThat(ex.getType(), is(FloatArgumentType.ERROR_TOO_SMALL)); @@ -58,7 +53,7 @@ public void parse_tooSmall() throws Exception { public void parse_tooBig() throws Exception { final StringReader reader = new StringReader("5"); try { - floatArg(-100, 0).parse(reader, context); + floatArg(-100, 0).parse(reader); fail(); } catch (final CommandSyntaxException ex) { assertThat(ex.getType(), is(FloatArgumentType.ERROR_TOO_BIG)); diff --git a/src/test/java/com/mojang/brigadier/arguments/IntegerArgumentTypeTest.java b/src/test/java/com/mojang/brigadier/arguments/IntegerArgumentTypeTest.java index 20f05c59..ba218a73 100644 --- a/src/test/java/com/mojang/brigadier/arguments/IntegerArgumentTypeTest.java +++ b/src/test/java/com/mojang/brigadier/arguments/IntegerArgumentTypeTest.java @@ -32,7 +32,7 @@ public void setUp() throws Exception { @Test public void parse() throws Exception { final StringReader reader = new StringReader("15"); - assertThat(integer().parse(reader, context), is(15)); + assertThat(integer().parse(reader), is(15)); assertThat(reader.canRead(), is(false)); } @@ -40,7 +40,7 @@ public void parse() throws Exception { public void parse_tooSmall() throws Exception { final StringReader reader = new StringReader("-5"); try { - integer(0, 100).parse(reader, context); + integer(0, 100).parse(reader); fail(); } catch (final CommandSyntaxException ex) { assertThat(ex.getType(), is(IntegerArgumentType.ERROR_TOO_SMALL)); @@ -53,7 +53,7 @@ public void parse_tooSmall() throws Exception { public void parse_tooBig() throws Exception { final StringReader reader = new StringReader("5"); try { - integer(-100, 0).parse(reader, context); + integer(-100, 0).parse(reader); fail(); } catch (final CommandSyntaxException ex) { assertThat(ex.getType(), is(IntegerArgumentType.ERROR_TOO_BIG)); diff --git a/src/test/java/com/mojang/brigadier/arguments/StringArgumentTypeTest.java b/src/test/java/com/mojang/brigadier/arguments/StringArgumentTypeTest.java index 5c74d19b..f03c791d 100644 --- a/src/test/java/com/mojang/brigadier/arguments/StringArgumentTypeTest.java +++ b/src/test/java/com/mojang/brigadier/arguments/StringArgumentTypeTest.java @@ -1,6 +1,5 @@ package com.mojang.brigadier.arguments; -import com.google.common.collect.Sets; import com.mojang.brigadier.StringReader; import com.mojang.brigadier.context.CommandContextBuilder; import org.junit.Test; @@ -8,13 +7,10 @@ import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; -import java.util.Set; - import static com.mojang.brigadier.arguments.StringArgumentType.escapeIfRequired; import static com.mojang.brigadier.arguments.StringArgumentType.greedyString; import static com.mojang.brigadier.arguments.StringArgumentType.string; import static com.mojang.brigadier.arguments.StringArgumentType.word; -import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasToString; import static org.hamcrest.Matchers.is; @@ -32,7 +28,7 @@ public class StringArgumentTypeTest { public void testParseWord() throws Exception { final StringReader reader = mock(StringReader.class); when(reader.readUnquotedString()).thenReturn("hello"); - assertThat(word().parse(reader, context), equalTo("hello")); + assertThat(word().parse(reader), equalTo("hello")); verify(reader).readUnquotedString(); } @@ -40,14 +36,14 @@ public void testParseWord() throws Exception { public void testParseString() throws Exception { final StringReader reader = mock(StringReader.class); when(reader.readString()).thenReturn("hello world"); - assertThat(string().parse(reader, context), equalTo("hello world")); + assertThat(string().parse(reader), equalTo("hello world")); verify(reader).readString(); } @Test public void testParseGreedyString() throws Exception { final StringReader reader = new StringReader("Hello world! This is a test."); - assertThat(greedyString().parse(reader, context), equalTo("Hello world! This is a test.")); + assertThat(greedyString().parse(reader), equalTo("Hello world! This is a test.")); assertThat(reader.canRead(), is(false)); }