use of org.spongepowered.api.command.dispatcher.SimpleDispatcher in project SpongeAPI by SpongePowered.
the class ChildCommandsTest method testErrorOnNonExistentChildWithNoExecutor.
@Test
public void testErrorOnNonExistentChildWithNoExecutor() throws CommandException {
final CommandSpec spec = CommandSpec.builder().children(ImmutableMap.of(ImmutableList.of("child"), CommandSpec.builder().executor((src, args) -> CommandResult.builder().successCount(1).build()).build())).childArgumentParseExceptionFallback(false).build();
final SimpleDispatcher execute = new SimpleDispatcher();
execute.register(spec, "parent");
try {
execute.process(mock(CommandSource.class), "parent wrong");
} catch (ArgumentParseException ex) {
assertEquals("Input command wrong was not a valid subcommand!\nwrong\n^", ex.getMessage());
}
}
use of org.spongepowered.api.command.dispatcher.SimpleDispatcher in project SpongeAPI by SpongePowered.
the class ChildCommandsTest method testSimpleChildCommandIsSuppressedOnError.
@Test
public void testSimpleChildCommandIsSuppressedOnError() throws CommandException {
final AtomicBoolean parentExecuted = new AtomicBoolean();
final AtomicBoolean childExecuted = new AtomicBoolean();
final CommandSpec spec = CommandSpec.builder().children(ImmutableMap.of(ImmutableList.of("child"), CommandSpec.builder().arguments(GenericArguments.literal(Text.of("test"), "test")).executor((src, args) -> {
childExecuted.set(true);
return CommandResult.builder().successCount(1).build();
}).build())).arguments(GenericArguments.literal(Text.of("t"), "child")).executor((src, args) -> {
parentExecuted.set(true);
return CommandResult.success();
}).build();
final SimpleDispatcher execute = new SimpleDispatcher();
execute.register(spec, "parent");
execute.process(mock(CommandSource.class), "parent child");
assertFalse(childExecuted.get());
assertTrue(parentExecuted.get());
}
use of org.spongepowered.api.command.dispatcher.SimpleDispatcher in project SpongeAPI by SpongePowered.
the class ChildCommandsTest method testErrorOnNonExistentChildWithNoOtherParameters.
@Test
public void testErrorOnNonExistentChildWithNoOtherParameters() throws CommandException {
final CommandSpec spec = CommandSpec.builder().children(ImmutableMap.of(ImmutableList.of("child"), CommandSpec.builder().executor((src, args) -> CommandResult.builder().successCount(1).build()).build())).childArgumentParseExceptionFallback(false).executor((src, args) -> CommandResult.success()).build();
final SimpleDispatcher execute = new SimpleDispatcher();
execute.register(spec, "parent");
try {
execute.process(mock(CommandSource.class), "parent wrong");
} catch (ArgumentParseException ex) {
assertEquals("Input command wrong was not a valid subcommand!\nwrong\n^", ex.getMessage());
}
}
use of org.spongepowered.api.command.dispatcher.SimpleDispatcher in project SpongeAPI by SpongePowered.
the class ChildCommandsTest method testEmptyChildrenWorksWithArgument.
@Test
public void testEmptyChildrenWorksWithArgument() throws CommandException {
final AtomicBoolean parent = new AtomicBoolean();
final CommandSpec spec = CommandSpec.builder().arguments(GenericArguments.optional(GenericArguments.string(Text.of("a")))).children(ImmutableMap.<List<String>, CommandSpec>of()).executor((s, c) -> {
parent.set(true);
return CommandResult.success();
}).build();
final SimpleDispatcher execute = new SimpleDispatcher();
execute.register(spec, "emptyparentwith");
execute.process(mock(CommandSource.class), "emptyparentwith child");
assertTrue(parent.get());
}
Aggregations