|
9 | 9 | import dev.jorel.commandapi.arguments.StringArgument;
|
10 | 10 | import dev.jorel.commandapi.arguments.parseexceptions.ArgumentParseExceptionContext;
|
11 | 11 | import dev.jorel.commandapi.test.arguments.parseexceptions.ArgumentParseExceptionContextVerifier;
|
| 12 | +import dev.jorel.commandapi.test.arguments.parseexceptions.InitialParseExceptionTextArgumentVerifier; |
12 | 13 | import org.bukkit.Material;
|
13 | 14 | import org.bukkit.command.CommandSender;
|
14 | 15 | import org.junit.jupiter.api.AfterEach;
|
@@ -445,10 +446,10 @@ public ArgumentParseExceptionListArgumentVerifier(TestBase testBase) {
|
445 | 446 | }
|
446 | 447 |
|
447 | 448 | public void assertCorrectContext(
|
448 |
| - String exceptionMessage, CommandSender sender, String input, Map<String, Object> previousArgsMap, |
449 |
| - ListArgumentCommon.ArgumentParseExceptionInformation.Exceptions type, |
450 |
| - List<T> listSoFar, String rawItem, T currentItem, |
451 |
| - ArgumentParseExceptionContext<String, ListArgumentCommon.ArgumentParseExceptionInformation<T>, CommandSender> actual |
| 449 | + String exceptionMessage, CommandSender sender, String input, Map<String, Object> previousArgsMap, |
| 450 | + ListArgumentCommon.ArgumentParseExceptionInformation.Exceptions type, |
| 451 | + List<T> listSoFar, String rawItem, T currentItem, |
| 452 | + ArgumentParseExceptionContext<String, ListArgumentCommon.ArgumentParseExceptionInformation<T>, CommandSender> actual |
452 | 453 | ) {
|
453 | 454 | super.assertCorrectContext(exceptionMessage, sender, input, previousArgsMap, actual);
|
454 | 455 |
|
@@ -562,7 +563,97 @@ void argumentParseExceptionTestWithListArgument() {
|
562 | 563 | "1 2 3 a 5", Map.of("buffer", "b123456789012345"), List.of(1, 2, 3), "a"
|
563 | 564 | );
|
564 | 565 | }
|
565 |
| - |
| 566 | + |
| 567 | + @Test |
| 568 | + void initialParseExceptionTestWithListTextArgument() { |
| 569 | + PlayerMock player = server.addPlayer(); |
| 570 | + InitialParseExceptionTextArgumentVerifier verifier = new InitialParseExceptionTextArgumentVerifier(this); |
| 571 | + |
| 572 | + new CommandAPICommand("test") |
| 573 | + .withArguments( |
| 574 | + new StringArgument("buffer"), |
| 575 | + new ListArgumentBuilder<Integer>("list") |
| 576 | + .withList(1, 2, 3, 4, 5) |
| 577 | + .withStringMapper() |
| 578 | + .buildText() |
| 579 | + .withInitialParseExceptionHandler(verifier.getExceptionHandler()) |
| 580 | + ) |
| 581 | + .executesPlayer(P_EXEC) |
| 582 | + .register(); |
| 583 | + |
| 584 | + // Test INVALID_ESCAPE cases: Backslash not followed by backslash or the same quote that started argument |
| 585 | + verifier.testInvalidEscapeCase( |
| 586 | + player, "test b123 \"\\abc\"", |
| 587 | + "Invalid escape sequence '\\a' in quoted string at position 12: ...st b123 \"\\<--[HERE]", |
| 588 | + 10, 12 |
| 589 | + ); |
| 590 | + verifier.testInvalidEscapeCase( |
| 591 | + player, "test b123 \"ab\\c\"", |
| 592 | + "Invalid escape sequence '\\c' in quoted string at position 14: ... b123 \"ab\\<--[HERE]", |
| 593 | + 10, 14 |
| 594 | + ); |
| 595 | + |
| 596 | + verifier.testInvalidEscapeCase( |
| 597 | + player, "test b123 \"\\'bc\"", |
| 598 | + "Invalid escape sequence '\\'' in quoted string at position 12: ...st b123 \"\\<--[HERE]", |
| 599 | + 10, 12 |
| 600 | + ); |
| 601 | + verifier.testInvalidEscapeCase( |
| 602 | + player, "test b123 '\\\"bc'", |
| 603 | + "Invalid escape sequence '\\\"' in quoted string at position 12: ...st b123 '\\<--[HERE]", |
| 604 | + 10, 12 |
| 605 | + ); |
| 606 | + |
| 607 | + |
| 608 | + // Test EXPECTED_QUOTE_END cases: Quoted string never ended by same quote that started argument |
| 609 | + verifier.testExpectedQuoteEndCase( |
| 610 | + player, "test b123 \"abc", |
| 611 | + "Unclosed quoted string at position 14: ... b123 \"abc<--[HERE]", |
| 612 | + 10 |
| 613 | + ); |
| 614 | + verifier.testExpectedQuoteEndCase( |
| 615 | + player, "test b123 'abcde", |
| 616 | + "Unclosed quoted string at position 16: ...123 'abcde<--[HERE]", |
| 617 | + 10 |
| 618 | + ); |
| 619 | + |
| 620 | + verifier.testExpectedQuoteEndCase( |
| 621 | + player, "test b123 \"abc'", |
| 622 | + "Unclosed quoted string at position 15: ...b123 \"abc'<--[HERE]", |
| 623 | + 10 |
| 624 | + ); |
| 625 | + verifier.testExpectedQuoteEndCase( |
| 626 | + player, "test b123 'abcde\"", |
| 627 | + "Unclosed quoted string at position 17: ...23 'abcde\"<--[HERE]", |
| 628 | + 10 |
| 629 | + ); |
| 630 | + |
| 631 | + |
| 632 | + // Increasing characters in buffer argument increases cursor start |
| 633 | + verifier.testInvalidEscapeCase( |
| 634 | + player, "test b12345 '\\\"bc'", |
| 635 | + "Invalid escape sequence '\\\"' in quoted string at position 14: ... b12345 '\\<--[HERE]", |
| 636 | + 12, 14 |
| 637 | + ); |
| 638 | + verifier.testInvalidEscapeCase( |
| 639 | + player, "test b123456789012345 '\\\"bc'", |
| 640 | + "Invalid escape sequence '\\\"' in quoted string at position 24: ...9012345 '\\<--[HERE]", |
| 641 | + 22, 24 |
| 642 | + ); |
| 643 | + |
| 644 | + verifier.testExpectedQuoteEndCase( |
| 645 | + player, "test b12345 \"abc'", |
| 646 | + "Unclosed quoted string at position 17: ...2345 \"abc'<--[HERE]", |
| 647 | + 12 |
| 648 | + ); |
| 649 | + |
| 650 | + verifier.testExpectedQuoteEndCase( |
| 651 | + player, "test b123456789012345 \"abc'", |
| 652 | + "Unclosed quoted string at position 27: ...2345 \"abc'<--[HERE]", |
| 653 | + 22 |
| 654 | + ); |
| 655 | + } |
| 656 | + |
566 | 657 | /********************
|
567 | 658 | * Suggestion tests *
|
568 | 659 | ********************/
|
|
0 commit comments