Treat any trailing space as "a yet to be finished command" instead of a maybe valid argument

This commit is contained in:
Nathan Adams 2017-11-08 09:35:27 +01:00
parent 6e61fef225
commit 4d91bc6e7e
3 changed files with 14 additions and 6 deletions

View file

@ -3,7 +3,7 @@ import groovy.io.FileType
apply plugin: 'java-library'
apply plugin: 'maven'
version = '0.1.2'
version = '0.1.3'
group = 'com.mojang'
task wrapper(type: Wrapper) {

View file

@ -152,10 +152,8 @@ public class CommandDispatcher<S> {
}
context.withCommand(child.getCommand());
if (reader.canRead()) {
if (reader.canRead(2)) {
reader.skip();
}
if (reader.canRead(2)) {
reader.skip();
if (child.getRedirect() != null) {
final CommandContextBuilder<S> childContext = new CommandContextBuilder<>(this, source, reader.getCursor());
childContext.withNode(child.getRedirect(), new StringRange(reader.getCursor(), reader.getCursor()));

View file

@ -175,7 +175,7 @@ public class CommandDispatcherTest {
@SuppressWarnings("unchecked")
@Test
public void testParseIncomplete() throws Exception {
public void testParseIncompleteLiteral() throws Exception {
subject.register(literal("foo").then(literal("bar").executes(command)));
final ParseResults<Object> parse = subject.parse("foo ", source);
@ -183,6 +183,16 @@ public class CommandDispatcherTest {
assertThat(parse.getContext().getNodes().size(), is(1));
}
@SuppressWarnings("unchecked")
@Test
public void testParseIncompleteArgument() throws Exception {
subject.register(literal("foo").then(argument("bar", integer()).executes(command)));
final ParseResults<Object> parse = subject.parse("foo ", source);
assertThat(parse.getReader().getRemaining(), equalTo(" "));
assertThat(parse.getContext().getNodes().size(), is(1));
}
@SuppressWarnings("unchecked")
@Test
public void testExecuteAmbiguiousParentSubcommand() throws Exception {