Don't store string arguments in contexts, ranges are more useful
This commit is contained in:
@@ -7,6 +7,7 @@ import com.google.common.collect.Sets;
|
|||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
import com.mojang.brigadier.context.CommandContext;
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
import com.mojang.brigadier.context.CommandContextBuilder;
|
import com.mojang.brigadier.context.CommandContextBuilder;
|
||||||
|
import com.mojang.brigadier.context.StringRange;
|
||||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
|
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
|
||||||
import com.mojang.brigadier.tree.CommandNode;
|
import com.mojang.brigadier.tree.CommandNode;
|
||||||
@@ -70,7 +71,7 @@ public class CommandDispatcher<S> {
|
|||||||
if (parse.getReader().canRead()) {
|
if (parse.getReader().canRead()) {
|
||||||
if (parse.getExceptions().size() == 1) {
|
if (parse.getExceptions().size() == 1) {
|
||||||
throw parse.getExceptions().values().iterator().next();
|
throw parse.getExceptions().values().iterator().next();
|
||||||
} else if (parse.getContext().getInput().isEmpty()) {
|
} else if (parse.getContext().getRange().isEmpty()) {
|
||||||
throw ERROR_UNKNOWN_COMMAND.createWithContext(parse.getReader());
|
throw ERROR_UNKNOWN_COMMAND.createWithContext(parse.getReader());
|
||||||
} else {
|
} else {
|
||||||
throw ERROR_UNKNOWN_ARGUMENT.createWithContext(parse.getReader());
|
throw ERROR_UNKNOWN_ARGUMENT.createWithContext(parse.getReader());
|
||||||
@@ -111,7 +112,7 @@ public class CommandDispatcher<S> {
|
|||||||
|
|
||||||
public ParseResults<S> parse(final String command, final S source) {
|
public ParseResults<S> parse(final String command, final S source) {
|
||||||
final StringReader reader = new StringReader(command);
|
final StringReader reader = new StringReader(command);
|
||||||
final CommandContextBuilder<S> context = new CommandContextBuilder<>(this, source);
|
final CommandContextBuilder<S> context = new CommandContextBuilder<>(this, source, 0);
|
||||||
return parseNodes(root, reader, context);
|
return parseNodes(root, reader, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,8 +155,8 @@ public class CommandDispatcher<S> {
|
|||||||
if (reader.canRead()) {
|
if (reader.canRead()) {
|
||||||
reader.skip();
|
reader.skip();
|
||||||
if (child.getRedirect() != null) {
|
if (child.getRedirect() != null) {
|
||||||
final CommandContextBuilder<S> childContext = new CommandContextBuilder<>(this, source);
|
final CommandContextBuilder<S> childContext = new CommandContextBuilder<>(this, source, reader.getCursor());
|
||||||
childContext.withNode(child.getRedirect(), "");
|
childContext.withNode(child.getRedirect(), new StringRange(reader.getCursor(), reader.getCursor()));
|
||||||
final ParseResults<S> parse = parseNodes(child.getRedirect(), reader, childContext);
|
final ParseResults<S> parse = parseNodes(child.getRedirect(), reader, childContext);
|
||||||
context.withChild(parse.getContext());
|
context.withChild(parse.getContext());
|
||||||
return new ParseResults<>(context, parse.getReader(), parse.getExceptions());
|
return new ParseResults<>(context, parse.getReader(), parse.getExceptions());
|
||||||
@@ -317,7 +318,7 @@ public class CommandDispatcher<S> {
|
|||||||
|
|
||||||
public String[] getCompletionSuggestions(final String command, final S source) {
|
public String[] getCompletionSuggestions(final String command, final S source) {
|
||||||
final StringReader reader = new StringReader(command);
|
final StringReader reader = new StringReader(command);
|
||||||
final Set<String> nodes = findSuggestions(root, reader, new CommandContextBuilder<>(this, source), Sets.newLinkedHashSet());
|
final Set<String> nodes = findSuggestions(root, reader, new CommandContextBuilder<>(this, source, 0), Sets.newLinkedHashSet());
|
||||||
|
|
||||||
return nodes.toArray(new String[nodes.size()]);
|
return nodes.toArray(new String[nodes.size()]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,16 +11,16 @@ public class CommandContext<S> {
|
|||||||
private final S source;
|
private final S source;
|
||||||
private final Command<S> command;
|
private final Command<S> command;
|
||||||
private final Map<String, ParsedArgument<S, ?>> arguments;
|
private final Map<String, ParsedArgument<S, ?>> arguments;
|
||||||
private final Map<CommandNode<S>, String> nodes;
|
private final Map<CommandNode<S>, StringRange> nodes;
|
||||||
private final String input;
|
private final StringRange range;
|
||||||
private final CommandContext<S> child;
|
private final CommandContext<S> child;
|
||||||
|
|
||||||
public CommandContext(final S source, final Map<String, ParsedArgument<S, ?>> arguments, final Command<S> command, final Map<CommandNode<S>, String> nodes, final String input, final CommandContext<S> child) {
|
public CommandContext(final S source, final Map<String, ParsedArgument<S, ?>> arguments, final Command<S> command, final Map<CommandNode<S>, StringRange> nodes, final StringRange range, final CommandContext<S> child) {
|
||||||
this.source = source;
|
this.source = source;
|
||||||
this.arguments = arguments;
|
this.arguments = arguments;
|
||||||
this.command = command;
|
this.command = command;
|
||||||
this.nodes = nodes;
|
this.nodes = nodes;
|
||||||
this.input = input;
|
this.range = range;
|
||||||
this.child = child;
|
this.child = child;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,12 +78,11 @@ public class CommandContext<S> {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getInput() {
|
public StringRange getRange() {
|
||||||
return input;
|
return range;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<CommandNode<S>, String> getNodes() {
|
public Map<CommandNode<S>, StringRange> getNodes() {
|
||||||
return nodes;
|
return nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,15 +9,17 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class CommandContextBuilder<S> {
|
public class CommandContextBuilder<S> {
|
||||||
private final Map<String, ParsedArgument<S, ?>> arguments = Maps.newLinkedHashMap();
|
private final Map<String, ParsedArgument<S, ?>> arguments = Maps.newLinkedHashMap();
|
||||||
private final Map<CommandNode<S>, String> nodes = Maps.newLinkedHashMap();
|
private final Map<CommandNode<S>, StringRange> nodes = Maps.newLinkedHashMap();
|
||||||
private final CommandDispatcher<S> dispatcher;
|
private final CommandDispatcher<S> dispatcher;
|
||||||
private S source;
|
private S source;
|
||||||
private Command<S> command;
|
private Command<S> command;
|
||||||
private CommandContextBuilder<S> child;
|
private CommandContextBuilder<S> child;
|
||||||
|
private StringRange range;
|
||||||
|
|
||||||
public CommandContextBuilder(final CommandDispatcher<S> dispatcher, final S source) {
|
public CommandContextBuilder(final CommandDispatcher<S> dispatcher, final S source, final int start) {
|
||||||
this.dispatcher = dispatcher;
|
this.dispatcher = dispatcher;
|
||||||
this.source = source;
|
this.source = source;
|
||||||
|
this.range = new StringRange(start, start);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommandContextBuilder<S> withSource(final S source) {
|
public CommandContextBuilder<S> withSource(final S source) {
|
||||||
@@ -43,17 +45,19 @@ public class CommandContextBuilder<S> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommandContextBuilder<S> withNode(final CommandNode<S> node, final String raw) {
|
public CommandContextBuilder<S> withNode(final CommandNode<S> node, final StringRange range) {
|
||||||
nodes.put(node, raw);
|
nodes.put(node, range);
|
||||||
|
this.range = new StringRange(Math.min(this.range.getStart(), range.getStart()), Math.max(this.range.getEnd(), range.getEnd()));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommandContextBuilder<S> copy() {
|
public CommandContextBuilder<S> copy() {
|
||||||
final CommandContextBuilder<S> copy = new CommandContextBuilder<>(dispatcher, source);
|
final CommandContextBuilder<S> copy = new CommandContextBuilder<>(dispatcher, source, range.getStart());
|
||||||
copy.command = command;
|
copy.command = command;
|
||||||
copy.arguments.putAll(arguments);
|
copy.arguments.putAll(arguments);
|
||||||
copy.nodes.putAll(nodes);
|
copy.nodes.putAll(nodes);
|
||||||
copy.child = child;
|
copy.child = child;
|
||||||
|
copy.range = range;
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,31 +74,19 @@ public class CommandContextBuilder<S> {
|
|||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getInput() {
|
public Map<CommandNode<S>, StringRange> getNodes() {
|
||||||
final StringBuilder result = new StringBuilder();
|
|
||||||
boolean first = true;
|
|
||||||
for (final String node : nodes.values()) {
|
|
||||||
if (first) {
|
|
||||||
if (!node.isEmpty()) {
|
|
||||||
first = false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
result.append(CommandDispatcher.ARGUMENT_SEPARATOR);
|
|
||||||
}
|
|
||||||
result.append(node);
|
|
||||||
}
|
|
||||||
return result.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<CommandNode<S>, String> getNodes() {
|
|
||||||
return nodes;
|
return nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommandContext<S> build() {
|
public CommandContext<S> build() {
|
||||||
return new CommandContext<>(source, arguments, command, nodes, getInput(), child == null ? null : child.build());
|
return new CommandContext<>(source, arguments, command, nodes, range, child == null ? null : child.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommandDispatcher<S> getDispatcher() {
|
public CommandDispatcher<S> getDispatcher() {
|
||||||
return dispatcher;
|
return dispatcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public StringRange getRange() {
|
||||||
|
return range;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +1,18 @@
|
|||||||
package com.mojang.brigadier.context;
|
package com.mojang.brigadier.context;
|
||||||
|
|
||||||
import com.mojang.brigadier.ImmutableStringReader;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class ParsedArgument<S, T> {
|
public class ParsedArgument<S, T> {
|
||||||
private final int start;
|
private final StringRange range;
|
||||||
private final int end;
|
|
||||||
private final T result;
|
private final T result;
|
||||||
|
|
||||||
public ParsedArgument(final int start, final int end, final T result) {
|
public ParsedArgument(final int start, final int end, final T result) {
|
||||||
this.start = start;
|
this.range = new StringRange(start, end);
|
||||||
this.end = end;
|
|
||||||
this.result = result;
|
this.result = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRaw(final ImmutableStringReader reader) {
|
public StringRange getRange() {
|
||||||
return reader.getString().substring(start, end);
|
return range;
|
||||||
}
|
|
||||||
|
|
||||||
public int getStart() {
|
|
||||||
return start;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getEnd() {
|
|
||||||
return end;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public T getResult() {
|
public T getResult() {
|
||||||
@@ -31,24 +21,18 @@ public class ParsedArgument<S, T> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(final Object o) {
|
public boolean equals(final Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) {
|
||||||
if (!(o instanceof ParsedArgument)) return false;
|
return true;
|
||||||
|
}
|
||||||
final ParsedArgument that = (ParsedArgument) o;
|
if (!(o instanceof ParsedArgument)) {
|
||||||
|
return false;
|
||||||
if (start != that.start) return false;
|
}
|
||||||
if (end != that.end) return false;
|
final ParsedArgument<?, ?> that = (ParsedArgument<?, ?>) o;
|
||||||
if (!result.equals(that.result)) return false;
|
return Objects.equals(range, that.range) && Objects.equals(result, that.result);
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int result = start;
|
return Objects.hash(range, result);
|
||||||
result = 31 * result + end;
|
|
||||||
result = 31 * result + this.result.hashCode();
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package com.mojang.brigadier.context;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.ImmutableStringReader;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class StringRange {
|
||||||
|
private final int start;
|
||||||
|
private final int end;
|
||||||
|
|
||||||
|
public StringRange(final int start, final int end) {
|
||||||
|
this.start = start;
|
||||||
|
this.end = end;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStart() {
|
||||||
|
return start;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getEnd() {
|
||||||
|
return end;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String get(final ImmutableStringReader reader) {
|
||||||
|
return reader.getString().substring(start, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String get(final String string) {
|
||||||
|
return string.substring(start, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return start == end;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLength() {
|
||||||
|
return end - start;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(final Object o) {
|
||||||
|
if (this == o) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!(o instanceof StringRange)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final StringRange that = (StringRange) o;
|
||||||
|
return start == that.start && end == that.end;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(start, end);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -53,7 +53,7 @@ public class ArgumentCommandNode<S, T> extends CommandNode<S> {
|
|||||||
final ParsedArgument<S, T> parsed = new ParsedArgument<>(start, reader.getCursor(), result);
|
final ParsedArgument<S, T> parsed = new ParsedArgument<>(start, reader.getCursor(), result);
|
||||||
|
|
||||||
contextBuilder.withArgument(name, parsed);
|
contextBuilder.withArgument(name, parsed);
|
||||||
contextBuilder.withNode(this, parsed.getRaw(reader));
|
contextBuilder.withNode(this, parsed.getRange());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import com.mojang.brigadier.StringReader;
|
|||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
import com.mojang.brigadier.context.CommandContext;
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
import com.mojang.brigadier.context.CommandContextBuilder;
|
import com.mojang.brigadier.context.CommandContextBuilder;
|
||||||
|
import com.mojang.brigadier.context.StringRange;
|
||||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
import com.mojang.brigadier.exceptions.ParameterizedCommandExceptionType;
|
import com.mojang.brigadier.exceptions.ParameterizedCommandExceptionType;
|
||||||
|
|
||||||
@@ -45,7 +46,7 @@ public class LiteralCommandNode<S> extends CommandNode<S> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
contextBuilder.withNode(this, literal);
|
contextBuilder.withNode(this, new StringRange(start, reader.getCursor()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -233,18 +233,19 @@ public class CommandDispatcherTest {
|
|||||||
subject.register(literal("actual").executes(command));
|
subject.register(literal("actual").executes(command));
|
||||||
subject.register(literal("redirected").redirect(subject.getRoot(), Collections::singleton));
|
subject.register(literal("redirected").redirect(subject.getRoot(), Collections::singleton));
|
||||||
|
|
||||||
final ParseResults<Object> parse = subject.parse("redirected redirected actual", source);
|
final String input = "redirected redirected actual";
|
||||||
assertThat(parse.getContext().getInput(), equalTo("redirected"));
|
final ParseResults<Object> parse = subject.parse(input, source);
|
||||||
|
assertThat(parse.getContext().getRange().get(input), equalTo("redirected"));
|
||||||
assertThat(parse.getContext().getNodes().size(), is(1));
|
assertThat(parse.getContext().getNodes().size(), is(1));
|
||||||
|
|
||||||
final CommandContextBuilder<Object> child1 = parse.getContext().getChild();
|
final CommandContextBuilder<Object> child1 = parse.getContext().getChild();
|
||||||
assertThat(child1, is(notNullValue()));
|
assertThat(child1, is(notNullValue()));
|
||||||
assertThat(child1.getInput(), equalTo("redirected"));
|
assertThat(child1.getRange().get(input), equalTo("redirected"));
|
||||||
assertThat(child1.getNodes().size(), is(2));
|
assertThat(child1.getNodes().size(), is(2));
|
||||||
|
|
||||||
final CommandContextBuilder<Object> child2 = child1.getChild();
|
final CommandContextBuilder<Object> child2 = child1.getChild();
|
||||||
assertThat(child2, is(notNullValue()));
|
assertThat(child2, is(notNullValue()));
|
||||||
assertThat(child2.getInput(), equalTo("actual"));
|
assertThat(child2.getRange().get(input), equalTo("actual"));
|
||||||
assertThat(child2.getNodes().size(), is(2));
|
assertThat(child2.getNodes().size(), is(2));
|
||||||
|
|
||||||
assertThat(subject.execute(parse), is(42));
|
assertThat(subject.execute(parse), is(42));
|
||||||
@@ -263,14 +264,15 @@ public class CommandDispatcherTest {
|
|||||||
subject.register(literal("actual").executes(command));
|
subject.register(literal("actual").executes(command));
|
||||||
subject.register(literal("redirected").redirect(subject.getRoot(), modifier));
|
subject.register(literal("redirected").redirect(subject.getRoot(), modifier));
|
||||||
|
|
||||||
final ParseResults<Object> parse = subject.parse("redirected actual", source);
|
final String input = "redirected actual";
|
||||||
assertThat(parse.getContext().getInput(), equalTo("redirected"));
|
final ParseResults<Object> parse = subject.parse(input, source);
|
||||||
|
assertThat(parse.getContext().getRange().get(input), equalTo("redirected"));
|
||||||
assertThat(parse.getContext().getNodes().size(), is(1));
|
assertThat(parse.getContext().getNodes().size(), is(1));
|
||||||
assertThat(parse.getContext().getSource(), is(source));
|
assertThat(parse.getContext().getSource(), is(source));
|
||||||
|
|
||||||
final CommandContextBuilder<Object> parent = parse.getContext().getChild();
|
final CommandContextBuilder<Object> parent = parse.getContext().getChild();
|
||||||
assertThat(parent, is(notNullValue()));
|
assertThat(parent, is(notNullValue()));
|
||||||
assertThat(parent.getInput(), equalTo("actual"));
|
assertThat(parent.getRange().get(input), equalTo("actual"));
|
||||||
assertThat(parent.getNodes().size(), is(2));
|
assertThat(parent.getNodes().size(), is(2));
|
||||||
assertThat(parent.getSource(), is(source));
|
assertThat(parent.getSource(), is(source));
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public class CommandContextTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
builder = new CommandContextBuilder<>(dispatcher, source);
|
builder = new CommandContextBuilder<>(dispatcher, source, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
@@ -61,20 +61,13 @@ public class CommandContextTest {
|
|||||||
final CommandNode<Object> node = mock(CommandNode.class);
|
final CommandNode<Object> node = mock(CommandNode.class);
|
||||||
final CommandNode<Object> otherNode = mock(CommandNode.class);
|
final CommandNode<Object> otherNode = mock(CommandNode.class);
|
||||||
new EqualsTester()
|
new EqualsTester()
|
||||||
.addEqualityGroup(new CommandContextBuilder<>(dispatcher, source).build(), new CommandContextBuilder<>(dispatcher, source).build())
|
.addEqualityGroup(new CommandContextBuilder<>(dispatcher, source, 0).build(), new CommandContextBuilder<>(dispatcher, source, 0).build())
|
||||||
.addEqualityGroup(new CommandContextBuilder<>(dispatcher, otherSource).build(), new CommandContextBuilder<>(dispatcher, otherSource).build())
|
.addEqualityGroup(new CommandContextBuilder<>(dispatcher, otherSource, 0).build(), new CommandContextBuilder<>(dispatcher, otherSource, 0).build())
|
||||||
.addEqualityGroup(new CommandContextBuilder<>(dispatcher, source).withCommand(command).build(), new CommandContextBuilder<>(dispatcher, source).withCommand(command).build())
|
.addEqualityGroup(new CommandContextBuilder<>(dispatcher, source, 0).withCommand(command).build(), new CommandContextBuilder<>(dispatcher, source, 0).withCommand(command).build())
|
||||||
.addEqualityGroup(new CommandContextBuilder<>(dispatcher, source).withCommand(otherCommand).build(), new CommandContextBuilder<>(dispatcher, source).withCommand(otherCommand).build())
|
.addEqualityGroup(new CommandContextBuilder<>(dispatcher, source, 0).withCommand(otherCommand).build(), new CommandContextBuilder<>(dispatcher, source, 0).withCommand(otherCommand).build())
|
||||||
.addEqualityGroup(new CommandContextBuilder<>(dispatcher, source).withArgument("foo", new ParsedArgument<>(0, 1, 123)).build(), new CommandContextBuilder<>(dispatcher, source).withArgument("foo", new ParsedArgument<>(0, 1, 123)).build())
|
.addEqualityGroup(new CommandContextBuilder<>(dispatcher, source, 0).withArgument("foo", new ParsedArgument<>(0, 1, 123)).build(), new CommandContextBuilder<>(dispatcher, source, 0).withArgument("foo", new ParsedArgument<>(0, 1, 123)).build())
|
||||||
.addEqualityGroup(new CommandContextBuilder<>(dispatcher, source).withNode(node, "foo").withNode(otherNode, "bar").build(), new CommandContextBuilder<>(dispatcher, source).withNode(node, "foo").withNode(otherNode, "bar").build())
|
.addEqualityGroup(new CommandContextBuilder<>(dispatcher, source, 0).withNode(node, new StringRange(0, 3)).withNode(otherNode, new StringRange(4, 6)).build(), new CommandContextBuilder<>(dispatcher, source, 0).withNode(node, new StringRange(0, 3)).withNode(otherNode, new StringRange(4, 6)).build())
|
||||||
.addEqualityGroup(new CommandContextBuilder<>(dispatcher, source).withNode(otherNode, "bar").withNode(node, "foo").build(), new CommandContextBuilder<>(dispatcher, source).withNode(otherNode, "bar").withNode(node, "foo").build())
|
.addEqualityGroup(new CommandContextBuilder<>(dispatcher, source, 0).withNode(otherNode, new StringRange(0, 3)).withNode(node, new StringRange(4, 6)).build(), new CommandContextBuilder<>(dispatcher, source, 0).withNode(otherNode, new StringRange(0, 3)).withNode(node, new StringRange(4, 6)).build())
|
||||||
.testEquals();
|
.testEquals();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetInput() throws Exception {
|
|
||||||
final CommandContext<Object> context = builder.withNode(literal("foo").build(), "foo").withNode(argument("bar", integer()).build(), "100").withNode(literal("baz").build(), "baz").build();
|
|
||||||
|
|
||||||
assertThat(context.getInput(), is("foo 100 baz"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -22,6 +22,6 @@ public class ParsedArgumentTest {
|
|||||||
public void getRaw() throws Exception {
|
public void getRaw() throws Exception {
|
||||||
final StringReader reader = new StringReader("0123456789");
|
final StringReader reader = new StringReader("0123456789");
|
||||||
final ParsedArgument<Object, String> argument = new ParsedArgument<>(2, 5, "");
|
final ParsedArgument<Object, String> argument = new ParsedArgument<>(2, 5, "");
|
||||||
assertThat(argument.getRaw(reader), equalTo("234"));
|
assertThat(argument.getRange().get(reader), equalTo("234"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -34,7 +34,7 @@ public class ArgumentCommandNodeTest extends AbstractCommandNodeTest {
|
|||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
node = argument("foo", integer()).build();
|
node = argument("foo", integer()).build();
|
||||||
contextBuilder = new CommandContextBuilder<>(new CommandDispatcher<>(), new Object());
|
contextBuilder = new CommandContextBuilder<>(new CommandDispatcher<>(), new Object(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public class LiteralCommandNodeTest extends AbstractCommandNodeTest {
|
|||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
node = literal("foo").build();
|
node = literal("foo").build();
|
||||||
contextBuilder = new CommandContextBuilder<>(new CommandDispatcher<>(), new Object());
|
contextBuilder = new CommandContextBuilder<>(new CommandDispatcher<>(), new Object(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public class RootCommandNodeTest extends AbstractCommandNodeTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testParse() throws Exception {
|
public void testParse() throws Exception {
|
||||||
final StringReader reader = new StringReader("hello world");
|
final StringReader reader = new StringReader("hello world");
|
||||||
node.parse(reader, new CommandContextBuilder<>(new CommandDispatcher<>(), new Object()));
|
node.parse(reader, new CommandContextBuilder<>(new CommandDispatcher<>(), new Object(), 0));
|
||||||
assertThat(reader.getCursor(), is(0));
|
assertThat(reader.getCursor(), is(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user