|
5 | 5 | import com.wizardlybump17.wlib.command.exception.InputParsingException; |
6 | 6 | import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; |
7 | 7 | import com.wizardlybump17.wlib.command.input.primitive.number.AllowedIntegerInputs; |
| 8 | +import com.wizardlybump17.wlib.command.input.string.AllowedStringInputs; |
8 | 9 | import com.wizardlybump17.wlib.command.node.CommandNode; |
9 | 10 | import com.wizardlybump17.wlib.command.node.LiteralCommandNode; |
10 | 11 | import com.wizardlybump17.wlib.command.node.primitive.number.IntegerCommandNode; |
| 12 | +import com.wizardlybump17.wlib.command.node.string.StringCommandNode; |
11 | 13 | import com.wizardlybump17.wlib.command.result.CommandResult; |
12 | 14 | import com.wizardlybump17.wlib.command.result.error.*; |
13 | 15 | import com.wizardlybump17.wlib.command.sender.BasicCommandSender; |
14 | 16 | import com.wizardlybump17.wlib.command.sender.CommandSender; |
| 17 | +import com.wizardlybump17.wlib.util.CollectionUtil; |
15 | 18 | import org.jetbrains.annotations.NotNull; |
16 | 19 | import org.junit.jupiter.api.Assertions; |
17 | 20 | import org.junit.jupiter.api.DisplayName; |
@@ -481,4 +484,64 @@ void testCommandArguments() { |
481 | 484 | Assertions.assertEquals(CommandResult.successful(2, test, "Hello 10 world"), result); |
482 | 485 | } |
483 | 486 | } |
| 487 | + |
| 488 | + @Test |
| 489 | + void testNullArgumentsSuccess() { |
| 490 | + Command command = new Command( |
| 491 | + new LiteralCommandNode( |
| 492 | + "test", |
| 493 | + List.of( |
| 494 | + new StringCommandNode( |
| 495 | + "nullable0", |
| 496 | + List.of(), |
| 497 | + AllowedStringInputs.anyNullable(), |
| 498 | + null, |
| 499 | + context -> CommandResult.successful(context, context.arguments().getArgumentData("nullable0").orElse(null)), |
| 500 | + null |
| 501 | + ) |
| 502 | + ), |
| 503 | + null, |
| 504 | + null |
| 505 | + ) |
| 506 | + ); |
| 507 | + |
| 508 | + Assertions.assertEquals( |
| 509 | + CommandResult.successful(1, command.findNode("nullable0"), "Hello World"), |
| 510 | + command.execute(CHAD_SENDER, List.of("test", "Hello World")) |
| 511 | + ); |
| 512 | + Assertions.assertEquals( |
| 513 | + CommandResult.successful(1, command.findNode("nullable0"), null), |
| 514 | + command.execute(CHAD_SENDER, CollectionUtil.listOf("test", null)) |
| 515 | + ); |
| 516 | + } |
| 517 | + |
| 518 | + @Test |
| 519 | + void testNullArgumentsError() { |
| 520 | + Command command = new Command( |
| 521 | + new LiteralCommandNode( |
| 522 | + "test", |
| 523 | + List.of( |
| 524 | + new StringCommandNode( |
| 525 | + "nullable0", |
| 526 | + List.of(), |
| 527 | + AllowedStringInputs.anyNotNull(), |
| 528 | + null, |
| 529 | + context -> CommandResult.successful(context, context.arguments().getArgumentData("nullable0").orElse(null)), |
| 530 | + null |
| 531 | + ) |
| 532 | + ), |
| 533 | + null, |
| 534 | + null |
| 535 | + ) |
| 536 | + ); |
| 537 | + |
| 538 | + Assertions.assertEquals( |
| 539 | + CommandResult.successful(1, command.findNode("nullable0"), "Hello World"), |
| 540 | + command.execute(CHAD_SENDER, List.of("test", "Hello World")) |
| 541 | + ); |
| 542 | + Assertions.assertEquals( |
| 543 | + CommandResult.outOfRangeInput(1, command.findNode("nullable0")), |
| 544 | + command.execute(CHAD_SENDER, CollectionUtil.listOf("test", null)) |
| 545 | + ); |
| 546 | + } |
484 | 547 | } |
0 commit comments