Fixed literals with special characters
This commit is contained in:
@@ -125,7 +125,10 @@ public abstract class CommandNode<S> implements Comparable<CommandNode<S>> {
|
|||||||
public Collection<? extends CommandNode<S>> getRelevantNodes(final StringReader input) {
|
public Collection<? extends CommandNode<S>> getRelevantNodes(final StringReader input) {
|
||||||
if (literals.size() > 0) {
|
if (literals.size() > 0) {
|
||||||
final int cursor = input.getCursor();
|
final int cursor = input.getCursor();
|
||||||
final String text = input.readUnquotedString();
|
while (input.canRead() && input.peek() != ' ') {
|
||||||
|
input.skip();
|
||||||
|
}
|
||||||
|
final String text = input.getString().substring(cursor, input.getCursor());
|
||||||
input.setCursor(cursor);
|
input.setCursor(cursor);
|
||||||
final LiteralCommandNode<S> literal = literals.get(text);
|
final LiteralCommandNode<S> literal = literals.get(text);
|
||||||
if (literal != null) {
|
if (literal != null) {
|
||||||
|
|||||||
@@ -163,12 +163,12 @@ public class CommandDispatcherTest {
|
|||||||
subject.register(literal("foo").then(
|
subject.register(literal("foo").then(
|
||||||
literal("a")
|
literal("a")
|
||||||
).then(
|
).then(
|
||||||
literal("b").executes(subCommand)
|
literal("=").executes(subCommand)
|
||||||
).then(
|
).then(
|
||||||
literal("c")
|
literal("c")
|
||||||
).executes(command));
|
).executes(command));
|
||||||
|
|
||||||
assertThat(subject.execute("foo b", source), is(100));
|
assertThat(subject.execute("foo =", source), is(100));
|
||||||
verify(subCommand).run(any(CommandContext.class));
|
verify(subCommand).run(any(CommandContext.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,7 +281,7 @@ public class CommandDispatcherTest {
|
|||||||
when(modifier.apply(argThat(hasProperty("source", is(source))))).thenReturn(Lists.newArrayList(source1, source2));
|
when(modifier.apply(argThat(hasProperty("source", is(source))))).thenReturn(Lists.newArrayList(source1, source2));
|
||||||
|
|
||||||
subject.register(literal("actual").executes(command));
|
subject.register(literal("actual").executes(command));
|
||||||
subject.register(literal("redirected").redirect(subject.getRoot()));
|
subject.register(literal("redirected").fork(subject.getRoot(), modifier));
|
||||||
|
|
||||||
final String input = "redirected actual";
|
final String input = "redirected actual";
|
||||||
final ParseResults<Object> parse = subject.parse(input, source);
|
final ParseResults<Object> parse = subject.parse(input, source);
|
||||||
@@ -335,9 +335,9 @@ public class CommandDispatcherTest {
|
|||||||
subject.execute("foo$", source);
|
subject.execute("foo$", source);
|
||||||
fail();
|
fail();
|
||||||
} catch (final CommandSyntaxException ex) {
|
} catch (final CommandSyntaxException ex) {
|
||||||
assertThat(ex.getType(), is(CommandDispatcher.ERROR_EXPECTED_ARGUMENT_SEPARATOR));
|
assertThat(ex.getType(), is(CommandDispatcher.ERROR_UNKNOWN_COMMAND));
|
||||||
assertThat(ex.getData(), is(Collections.emptyMap()));
|
assertThat(ex.getData(), is(Collections.emptyMap()));
|
||||||
assertThat(ex.getCursor(), is(3));
|
assertThat(ex.getCursor(), is(0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user