use of org.spongepowered.api.command.spec.CommandSpec in project SpongeAPI by SpongePowered.
the class CommandSpecTest method testNoArgsFunctional.
@Test
public void testNoArgsFunctional() throws CommandException, NoSuchFieldException, IllegalAccessException {
CommandManager cm = mock(CommandManager.class);
TestHooks.setInstance("commandManager", cm);
CommandSpec cmd = CommandSpec.builder().executor((src, args) -> CommandResult.empty()).build();
final SimpleDispatcher dispatcher = new SimpleDispatcher();
dispatcher.register(cmd, "cmd");
dispatcher.process(Mockito.mock(CommandSource.class), "cmd");
}
use of org.spongepowered.api.command.spec.CommandSpec in project SpongeAPI by SpongePowered.
the class GenericArgumentsTest method parseForInput.
private static CommandContext parseForInput(String input, CommandElement element) throws ArgumentParseException {
CommandSpec spec = CommandSpec.builder().arguments(element).executor(NULL_EXECUTOR).build();
final CommandArgs args = new CommandArgs(input, spec.getInputTokenizer().tokenize(input, false));
final CommandContext context = new CommandContext();
spec.populateContext(MOCK_SOURCE, args, context);
return context;
}
use of org.spongepowered.api.command.spec.CommandSpec in project SpongeAPI by SpongePowered.
the class ChildCommandsTest method testSimpleChildCommand.
@Test
public void testSimpleChildCommand() throws CommandException {
final AtomicBoolean childExecuted = new AtomicBoolean();
final CommandSpec spec = CommandSpec.builder().children(ImmutableMap.of(ImmutableList.of("child"), CommandSpec.builder().executor((src, args) -> {
childExecuted.set(true);
return CommandResult.builder().successCount(1).build();
}).build())).build();
final SimpleDispatcher execute = new SimpleDispatcher();
execute.register(spec, "parent");
execute.process(mock(CommandSource.class), "parent child");
assertTrue(childExecuted.get());
}
use of org.spongepowered.api.command.spec.CommandSpec in project SpongeAPI by SpongePowered.
the class ChildCommandsTest method testEmptyChildrenWorksWithOptionalArgument.
@Test
public void testEmptyChildrenWorksWithOptionalArgument() throws CommandException {
final AtomicBoolean parent = new AtomicBoolean();
final CommandSpec spec = CommandSpec.builder().arguments(GenericArguments.optional(GenericArguments.string(Text.of("b")))).children(ImmutableMap.<List<String>, CommandSpec>builder().put(Lists.newArrayList("aaa"), CommandSpec.builder().executor((s, c) -> CommandResult.empty()).build()).build()).executor((s, c) -> {
parent.set(true);
return CommandResult.success();
}).build();
final SimpleDispatcher execute = new SimpleDispatcher();
execute.register(spec, "emptyparentwithopt");
execute.process(mock(CommandSource.class), "emptyparentwithopt");
assertTrue(parent.get());
}
use of org.spongepowered.api.command.spec.CommandSpec 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());
}
}
Aggregations