Skip to content

Commit

Permalink
Fix typo with optional.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rollczi committed Feb 26, 2022
1 parent 593028c commit 5746d04
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public List<String> resolveCompletion(ContextOfResolving data) {

Option<ArgumentHandler<?>> option = liteExecution.getExecutor().getArgumentHandler(lastArgumentIndex);

if (option.isEmpty()) {
if (option.isPresent()) {
ArgumentHandler<?> argumentHandler = option.get();

if (argumentHandler.isValid(currentContext, lastArgument)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ private LiteTestFactory() {}

public static LiteCommandsBuilder<Void, LiteTestPlatform> builder() {
return LiteFactory.<Void, LiteTestPlatform>builder()
.bind(LiteTestSender.class, new LiteTestSenderBind())
.argument(LiteTestSender.class, new LiteTestSenderArgument())
.platform(new LiteTestPlatform());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,8 @@ public List<String> suggestion(LiteTestSender liteSender, String command, String

return liteTestCommand.suggest(liteSender, liteTestCommand.getScope().getName(), command, args);
}
public List<String> suggestion(String command, String[] args) {
return suggestion(new LiteTestSender(), command, args);
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package dev.rollczi.litecommands;

import dev.rollczi.litecommands.argument.ArgumentName;
import dev.rollczi.litecommands.argument.SingleArgumentHandler;
import dev.rollczi.litecommands.valid.ValidationCommandException;

import java.util.Arrays;
import java.util.List;

@ArgumentName("test_sender")
public class LiteTestSenderArgument implements SingleArgumentHandler<LiteTestSender> {

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package dev.rollczi.litecommands;

import dev.rollczi.litecommands.bind.LiteBind;

public class LiteTestSenderBind implements LiteBind {

@Override
public Object apply(LiteInvocation invocation) {
return new LiteTestSender();
}

}
Original file line number Diff line number Diff line change
@@ -1,44 +1,50 @@
package dev.rollczi.litecommands.complete

import dev.rollczi.litecommands.LiteCommandsSpec
import dev.rollczi.litecommands.component.LiteComponent
import dev.rollczi.litecommands.LiteTestFactory
import dev.rollczi.litecommands.LiteTestPlatform
import org.junit.jupiter.api.Assertions.assertArrayEquals
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

class SuggestionTest : LiteCommandsSpec() {

private val section = factory.createSection(TestSuggestionCommand::class.java).get()
private val testSuggestionCommand = TestSuggestionCommand()
private val testSuggestionCommandWithJoiner = TestSuggestionCommandWithJoiner()
private val liteCommands = LiteTestFactory.builder()
.commandInstance(testSuggestionCommand)
.commandInstance(testSuggestionCommandWithJoiner)
.register()

private var invocationAc : LiteComponent.ContextOfResolving = contextCreator.apply("ac", arrayOf(""))
private val platform: LiteTestPlatform = liteCommands.getPlatformManager()

@Test
fun `without arg tabulation test`() {
assertArrayEquals(arrayOf("help", "manage"), section.resolveCompletion(invocationAc).toTypedArray())
assertArrayEquals(arrayOf("help", "manage"), platform.suggestion("ac", arrayOf("")).toTypedArray())
}

private var invocationAcHelp : LiteComponent.ContextOfResolving = contextCreator.apply("ac", arrayOf("help", ""))

@Test
fun `empty tabulation test`() {
assertArrayEquals(emptyArray<String>(), section.resolveCompletion(invocationAcHelp).toTypedArray())
assertArrayEquals(emptyArray<String>(), platform.suggestion("ac", arrayOf("help", "")).toTypedArray())
}

private var invocationAcManage : LiteComponent.ContextOfResolving = contextCreator.apply("ac", arrayOf("manage", ""))
private var invocationAcMove : LiteComponent.ContextOfResolving = contextCreator.apply("ac", arrayOf("manage", "move", ""))

@Test
fun `inner section tabulation test` () {
assertArrayEquals(arrayOf("move"), section.resolveCompletion(invocationAcManage).toTypedArray())
assertArrayEquals(arrayOf("test1", "test2", "test3"), section.resolveCompletion(invocationAcMove).toTypedArray())
assertArrayEquals(arrayOf("move"), platform.suggestion("ac", arrayOf("manage", "")).toTypedArray())
assertArrayEquals(arrayOf("test1", "test2", "test3"), platform.suggestion("ac", arrayOf("manage", "move", "")).toTypedArray())
}

private var invocationAcMoveBack : LiteComponent.ContextOfResolving = contextCreator.apply("ac", arrayOf("manage", "mo"))
private var invocationAcMoveIn : LiteComponent.ContextOfResolving = contextCreator.apply("ac", arrayOf("manage", "move"))

@Test
fun `back tabulation test` () {
assertArrayEquals(arrayOf("move"), section.resolveCompletion(invocationAcMoveBack).toTypedArray())
assertArrayEquals(arrayOf("move"), section.resolveCompletion(invocationAcMoveIn).toTypedArray())
assertArrayEquals(arrayOf("move"), platform.suggestion("ac", arrayOf("manage", "mo")).toTypedArray())
assertArrayEquals(arrayOf("move"), platform.suggestion("ac", arrayOf("manage", "move")).toTypedArray())
}

@Test
fun `completion with joiner` () {
assertEquals(0, platform.suggestion("joiner", arrayOf("test")).size)
assertEquals(0, platform.suggestion("joiner", arrayOf("test", "test")).size)
assertEquals(0, platform.suggestion("joiner", arrayOf("test", "test", "test")).size)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package dev.rollczi.litecommands.complete;

import dev.rollczi.litecommands.annotations.Execute;
import dev.rollczi.litecommands.annotations.Joiner;
import dev.rollczi.litecommands.annotations.MinArgs;
import dev.rollczi.litecommands.annotations.Section;

@Section(route = "joiner")
public class TestSuggestionCommandWithJoiner {

@Execute @MinArgs(1)
public void execute(@Joiner String text) {}

}

0 comments on commit 5746d04

Please sign in to comment.