-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
initialParseExceptionTestWithListTextArgument
Also some test javadocs tweaks
- Loading branch information
1 parent
898d338
commit e25be0f
Showing
5 changed files
with
190 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
.../commandapi/test/arguments/parseexceptions/InitialParseExceptionTextArgumentVerifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package dev.jorel.commandapi.test.arguments.parseexceptions; | ||
|
||
import dev.jorel.commandapi.arguments.parseexceptions.InitialParseExceptionContext; | ||
import dev.jorel.commandapi.arguments.parseexceptions.InitialParseExceptionTextArgument; | ||
import dev.jorel.commandapi.test.TestBase; | ||
import org.bukkit.command.CommandSender; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
/** | ||
* A helper class for verifying {@link InitialParseExceptionContext} objects generated by | ||
* {@link InitialParseExceptionTextArgument}s. | ||
*/ | ||
public class InitialParseExceptionTextArgumentVerifier | ||
extends InitialParseExceptionContextVerifier<String, InitialParseExceptionTextArgument.ExceptionTypes> { | ||
/** | ||
* Creates a new {@link InitialParseExceptionTextArgumentVerifier}. | ||
* | ||
* @param testBase The {@link TestBase} object running the test. | ||
*/ | ||
public InitialParseExceptionTextArgumentVerifier(TestBase testBase) { | ||
super(testBase); | ||
} | ||
|
||
/** | ||
* Asserts that the given {@code actual} context has all the given expected attributes. | ||
* | ||
* @param exceptionMessage The message of the initial parse exception. | ||
* @param readerString The command string being parsed. | ||
* @param cursorStart The place where the StringReader started parsing the ArgumentType. | ||
* @param readerCursor The place where the StringReader ended when the exception was handled. | ||
* @param exceptionType The type of exception that occurred. | ||
* @param actual The actual {@link InitialParseExceptionContext} generated. | ||
*/ | ||
public void assertCorrectContext( | ||
String exceptionMessage, String readerString, int cursorStart, int readerCursor, | ||
InitialParseExceptionTextArgument.ExceptionTypes exceptionType, | ||
InitialParseExceptionContext<InitialParseExceptionTextArgument.ExceptionTypes> actual) { | ||
super.assertCorrectContext(exceptionMessage, readerString, cursorStart, readerCursor, actual); | ||
|
||
assertEquals(exceptionType, actual.exceptionInformation()); | ||
} | ||
|
||
/** | ||
* Tests a case where the {@code exceptionType} is {@code INVALID_ESCAPE}, when a quoted String contains the escape | ||
* character {@code \} (backslash) is followed by anything other than another backslash or the same character that | ||
* started the quoted string. | ||
* | ||
* @param sender The sender for the command. | ||
* @param command The command to execute. | ||
* @param exceptionMessage The message of the exception that should be thrown. | ||
* @param cursorStart The index where the StringReader's cursor should start and end. | ||
* @param readerCursor The place where the StringReader ended when the exception was handled. | ||
*/ | ||
public void testInvalidEscapeCase( | ||
CommandSender sender, String command, String exceptionMessage, | ||
int cursorStart, int readerCursor | ||
) { | ||
verifyGeneratedContext( | ||
sender, command, exceptionMessage, | ||
context -> assertCorrectContext( | ||
exceptionMessage, command, cursorStart, readerCursor, | ||
InitialParseExceptionTextArgument.ExceptionTypes.INVALID_ESCAPE, | ||
context | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Tests a case where the {@code exceptionType} is {@code EXPECTED_QUOTE_END}, when a quoted String reaches the end | ||
* of input before the String is closed. {@code readerCursor} should be at the end of the input command. | ||
* | ||
* @param sender The sender for the command. | ||
* @param command The command to execute. | ||
* @param exceptionMessage The message of the exception that should be thrown. | ||
* @param cursorStart The index where the StringReader's cursor should start and end. | ||
*/ | ||
public void testExpectedQuoteEndCase( | ||
CommandSender sender, String command, String exceptionMessage, | ||
int cursorStart | ||
) { | ||
verifyGeneratedContext( | ||
sender, command, exceptionMessage, | ||
context -> assertCorrectContext( | ||
exceptionMessage, command, cursorStart, command.length(), | ||
InitialParseExceptionTextArgument.ExceptionTypes.EXPECTED_QUOTE_END, | ||
context | ||
) | ||
); | ||
} | ||
} |