|
4 | 4 | package com.mojang.brigadier; |
5 | 5 |
|
6 | 6 | import com.google.common.collect.Lists; |
| 7 | +import com.mojang.brigadier.arguments.IntegerArgumentType; |
7 | 8 | import com.mojang.brigadier.context.CommandContext; |
8 | 9 | import com.mojang.brigadier.context.CommandContextBuilder; |
9 | 10 | import com.mojang.brigadier.exceptions.CommandSyntaxException; |
|
14 | 15 | import org.mockito.Mock; |
15 | 16 | import org.mockito.runners.MockitoJUnitRunner; |
16 | 17 |
|
| 18 | +import java.util.Collections; |
| 19 | +import java.util.concurrent.atomic.AtomicBoolean; |
| 20 | + |
17 | 21 | import static com.mojang.brigadier.arguments.IntegerArgumentType.integer; |
18 | 22 | import static com.mojang.brigadier.builder.LiteralArgumentBuilder.literal; |
19 | 23 | import static com.mojang.brigadier.builder.RequiredArgumentBuilder.argument; |
@@ -326,6 +330,37 @@ public void testExecuteRedirected() throws Exception { |
326 | 330 | verify(command).run(argThat(hasProperty("source", is(source2)))); |
327 | 331 | } |
328 | 332 |
|
| 333 | + @Test |
| 334 | + public void testIncompleteRedirectShouldThrow() { |
| 335 | + final LiteralCommandNode<Object> foo = subject.register(literal("foo") |
| 336 | + .then(literal("bar") |
| 337 | + .then(argument("value", integer()).executes(context -> IntegerArgumentType.getInteger(context, "value")))) |
| 338 | + .then(literal("awa").executes(context -> 2))); |
| 339 | + final LiteralCommandNode<Object> baz = subject.register(literal("baz").redirect(foo)); |
| 340 | + try { |
| 341 | + int result = subject.execute("baz bar", source); |
| 342 | + fail("Should have thrown an exception"); |
| 343 | + } catch (CommandSyntaxException e) { |
| 344 | + assertThat(e.getType(), is(CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownCommand())); |
| 345 | + } |
| 346 | + } |
| 347 | + |
| 348 | + @Test |
| 349 | + public void testRedirectModifierEmptyResult() { |
| 350 | + final LiteralCommandNode<Object> foo = subject.register(literal("foo") |
| 351 | + .then(literal("bar") |
| 352 | + .then(argument("value", integer()).executes(context -> IntegerArgumentType.getInteger(context, "value")))) |
| 353 | + .then(literal("awa").executes(context -> 2))); |
| 354 | + final RedirectModifier<Object> emptyModifier = context -> Collections.emptyList(); |
| 355 | + final LiteralCommandNode<Object> baz = subject.register(literal("baz").fork(foo, emptyModifier)); |
| 356 | + try { |
| 357 | + int result = subject.execute("baz bar 100", source); |
| 358 | + assertThat(result, is(0)); // No commands executed, so result is 0 |
| 359 | + } catch (CommandSyntaxException e) { |
| 360 | + fail("Should not throw an exception"); |
| 361 | + } |
| 362 | + } |
| 363 | + |
329 | 364 | @Test |
330 | 365 | public void testExecuteOrphanedSubcommand() throws Exception { |
331 | 366 | subject.register(literal("foo").then( |
|
0 commit comments