-
-
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.
- Loading branch information
1 parent
a24bab4
commit 07a4ba5
Showing
2 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
134 changes: 134 additions & 0 deletions
134
...est-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentListabilityTests.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,134 @@ | ||
package dev.jorel.commandapi.test.arguments; | ||
|
||
import com.mojang.brigadier.tree.CommandNode; | ||
import dev.jorel.commandapi.CommandAPICommand; | ||
import dev.jorel.commandapi.arguments.*; | ||
import dev.jorel.commandapi.test.Mut; | ||
import dev.jorel.commandapi.test.TestBase; | ||
import org.bukkit.entity.Player; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Tests for the effects of the {@link AbstractArgument#setListed(boolean)} method. | ||
* Arguments may use different {@link CommandNode} implementation that implement this with separate code. | ||
*/ | ||
public class ArgumentListabilityTests extends TestBase { | ||
|
||
/********* | ||
* Setup * | ||
*********/ | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
super.setUp(); | ||
} | ||
|
||
@AfterEach | ||
public void tearDown() { | ||
super.tearDown(); | ||
} | ||
|
||
/********* | ||
* Tests * | ||
*********/ | ||
|
||
@Test | ||
void testUnlistedRequiredArguments() { | ||
Mut<Integer> results = Mut.of(); | ||
Player sender = server.addPlayer(); | ||
|
||
// Unlisted arguments before or after should not interfere with parsing | ||
new CommandAPICommand("test") | ||
.withArguments( | ||
new StringArgument("number").setListed(false), | ||
new IntegerArgument("number"), | ||
new StringArgument("number").setListed(false) | ||
) | ||
.executes(info -> { | ||
results.set(info.args().getUnchecked("number")); | ||
}) | ||
.register(); | ||
|
||
assertStoresResult(sender, "test abc 10 def", results, 10); | ||
assertStoresResult(sender, "test 0 1 2", results, 1); | ||
|
||
assertNoMoreResults(results); | ||
} | ||
|
||
@Test | ||
void testUnlistedLiterals() { | ||
Mut<Integer> results = Mut.of(); | ||
|
||
// Default unlisted literals should not overwrite parsed results | ||
new CommandAPICommand("test") | ||
.withArguments( | ||
new LiteralArgument("number"), | ||
new IntegerArgument("number"), | ||
new LiteralArgument("number") | ||
) | ||
.executesPlayer(info -> { | ||
results.set(info.args().getUnchecked("number")); | ||
}) | ||
.register(); | ||
|
||
Player player = server.addPlayer(); | ||
|
||
// Unlisted MultiLiterals before or after should not affect the result given | ||
assertStoresResult(player, "test number 0 number", results, 0); | ||
assertStoresResult(player, "test number 10 number", results, 10); | ||
|
||
assertNoMoreResults(results); | ||
} | ||
|
||
@Test | ||
void testUnlistedMultiLiterals() { | ||
Mut<String> results = Mut.of(); | ||
|
||
// This command is valid because the listed arguments do not repeat names | ||
new CommandAPICommand("test") | ||
.withArguments( | ||
new MultiLiteralArgument("literal", "a", "b", "c").setListed(false), | ||
new MultiLiteralArgument("literal", "c", "d", "e"), | ||
new MultiLiteralArgument("literal", "f", "g", "h").setListed(false) | ||
) | ||
.executesPlayer(info -> { | ||
results.set(info.args().getUnchecked("literal")); | ||
}) | ||
.register(); | ||
|
||
Player player = server.addPlayer(); | ||
|
||
// Unlisted MultiLiterals before or after should not affect the result given | ||
assertStoresResult(player, "test a c f", results, "c"); | ||
assertStoresResult(player, "test b d g", results, "d"); | ||
assertStoresResult(player, "test c e h", results, "e"); | ||
|
||
assertNoMoreResults(results); | ||
} | ||
|
||
@Test | ||
void testUnlistedPreviewableArguments() { | ||
Mut<Integer> results = Mut.of(); | ||
Player sender = server.addPlayer(); | ||
|
||
// Unlisted arguments before or after should not interfere with parsing | ||
// Though all current Previewable arguments are also Greedy, so you can't | ||
// have an argument after it anyway ¯\_(ツ)_/¯ | ||
new CommandAPICommand("test") | ||
.withArguments( | ||
new IntegerArgument("number"), | ||
new ChatArgument("number").setListed(false) | ||
) | ||
.executes(info -> { | ||
results.set(info.args().getUnchecked("number")); | ||
}) | ||
.register(); | ||
|
||
assertStoresResult(sender, "test 10 def", results, 10); | ||
assertStoresResult(sender, "test 1 2", results, 1); | ||
|
||
assertNoMoreResults(results); | ||
} | ||
} |
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