|
4 | 4 | package com.mojang.brigadier;
|
5 | 5 |
|
6 | 6 | import com.google.common.collect.Lists;
|
| 7 | +import com.mojang.brigadier.arguments.StringArgumentType; |
7 | 8 | import com.mojang.brigadier.context.CommandContext;
|
8 | 9 | import com.mojang.brigadier.context.CommandContextBuilder;
|
9 | 10 | import com.mojang.brigadier.context.StringRange;
|
@@ -302,6 +303,47 @@ public void testExecuteAmbiguiousParentSubcommandViaRedirect() throws Exception
|
302 | 303 | verify(command, never()).run(any());
|
303 | 304 | }
|
304 | 305 |
|
| 306 | + @SuppressWarnings("unchecked") |
| 307 | + @Test |
| 308 | + public void testPreferExecuteLiteralOverArguments() throws Exception { |
| 309 | + final Command<Object> literalCommand = mock(Command.class); |
| 310 | + when(literalCommand.run(any())).thenReturn(100); |
| 311 | + |
| 312 | + subject.register( |
| 313 | + literal("test") |
| 314 | + .then( |
| 315 | + argument("incorrect", StringArgumentType.word()) |
| 316 | + .executes(command) |
| 317 | + ) |
| 318 | + .then( |
| 319 | + literal("hello") |
| 320 | + .executes(literalCommand) |
| 321 | + ) |
| 322 | + ); |
| 323 | + |
| 324 | + assertThat(subject.execute("test hello", source), is(100)); |
| 325 | + verify(literalCommand).run(any(CommandContext.class)); |
| 326 | + verify(command, never()).run(any()); |
| 327 | + } |
| 328 | + |
| 329 | + @SuppressWarnings("unchecked") |
| 330 | + @Test |
| 331 | + public void testExecuteAmbiguousArgumentIfImpermissibleLiteral() throws Exception { |
| 332 | + subject.register(literal("foo") |
| 333 | + .then( |
| 334 | + literal("bar") |
| 335 | + .requires(source -> false) |
| 336 | + ) |
| 337 | + .then( |
| 338 | + argument("argument", StringArgumentType.word()) |
| 339 | + .executes(command) |
| 340 | + ) |
| 341 | + ); |
| 342 | + |
| 343 | + assertThat(subject.execute("foo bar", source), is(42)); |
| 344 | + verify(command).run(any(CommandContext.class)); |
| 345 | + } |
| 346 | + |
305 | 347 | @SuppressWarnings("unchecked")
|
306 | 348 | @Test
|
307 | 349 | public void testExecuteRedirectedMultipleTimes() throws Exception {
|
|
0 commit comments