Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add @Args annotation. Handle string argument validator. Add unit test…
…s for @Args and String suggestion.
- Loading branch information
Showing
15 changed files
with
174 additions
and
34 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
11 changes: 11 additions & 0 deletions
11
litecommands-core/src/main/java/dev/rollczi/litecommands/argument/Args.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,11 @@ | ||
package dev.rollczi.litecommands.argument; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target({ElementType.PARAMETER}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface Args { | ||
} |
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
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
6 changes: 4 additions & 2 deletions
6
litecommands-core/src/main/java/dev/rollczi/litecommands/injector/bind/AnnotationBind.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 |
---|---|---|
@@ -1,10 +1,12 @@ | ||
package dev.rollczi.litecommands.injector.bind; | ||
|
||
import dev.rollczi.litecommands.command.Invocation; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.Parameter; | ||
|
||
public interface AnnotationBind<T, A extends Annotation> { | ||
public interface AnnotationBind<TYPE, SENDER, ANNOTATION extends Annotation> { | ||
|
||
T extract(Parameter parameter, A annotation); | ||
TYPE extract(Invocation<SENDER> invocation, Parameter parameter, ANNOTATION annotation); | ||
|
||
} |
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
53 changes: 53 additions & 0 deletions
53
litecommands-core/src/test/java/dev/rollczi/litecommands/argument/ArgsAnnotationTest.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,53 @@ | ||
package dev.rollczi.litecommands.argument; | ||
|
||
import dev.rollczi.litecommands.AssertResult; | ||
import dev.rollczi.litecommands.TestFactory; | ||
import dev.rollczi.litecommands.TestPlatform; | ||
import dev.rollczi.litecommands.command.execute.Execute; | ||
import dev.rollczi.litecommands.command.section.Section; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertArrayEquals; | ||
|
||
class ArgsAnnotationTest { | ||
|
||
TestPlatform platform = TestFactory.withCommandsUniversalHandler(Command.class, CommandList.class); | ||
|
||
@Section(route = "test-primitive") | ||
private static class Command { | ||
@Execute | ||
String[] test(@Args String[] arguments) { | ||
return arguments; | ||
} | ||
} | ||
|
||
@Section(route = "test-list") | ||
private static class CommandList { | ||
@Execute | ||
List<String> test(@Args List<String> arguments) { | ||
return arguments; | ||
} | ||
} | ||
|
||
@Test | ||
void testPrimitive() { | ||
AssertResult success = platform.execute("test-primitive", "1", "2") | ||
.assertSuccess(); | ||
|
||
String[] result = success | ||
.assertResultIs(String[].class); | ||
|
||
assertArrayEquals(new String[]{"1", "2"}, result); | ||
} | ||
|
||
@Test | ||
void testList() { | ||
platform.execute("test-list", "1", "2") | ||
.assertSuccess() | ||
.assertResult(Arrays.asList("1", "2")); | ||
} | ||
|
||
} |
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
26 changes: 26 additions & 0 deletions
26
...commands-core/src/test/java/dev/rollczi/litecommands/suggestion/SuggestionStringTest.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,26 @@ | ||
package dev.rollczi.litecommands.suggestion; | ||
|
||
import dev.rollczi.litecommands.TestFactory; | ||
import dev.rollczi.litecommands.TestPlatform; | ||
import dev.rollczi.litecommands.argument.Arg; | ||
import dev.rollczi.litecommands.command.execute.Execute; | ||
import dev.rollczi.litecommands.command.section.Section; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class SuggestionStringTest { | ||
|
||
TestPlatform platform = TestFactory.withCommands(Command.class); | ||
|
||
@Section(route = "test") | ||
private static class Command { | ||
@Execute void test(@Arg String arg) {} | ||
} | ||
|
||
@Test | ||
void test() { | ||
platform.suggest("test", "").assertWith("text"); | ||
platform.suggest("test", "t").assertWith("t", "text"); | ||
platform.suggest("test", "siema").assertWith("siema"); | ||
} | ||
|
||
} |
Oops, something went wrong.