fix dead end error with executable literal nodes

This commit is contained in:
Bixilon 2022-05-29 19:51:59 +02:00
parent 7191fdcb76
commit d1451bd863
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
2 changed files with 18 additions and 1 deletions

View File

@ -48,6 +48,18 @@ abstract class ExecutableNode(
super.execute(reader, stack)
}
override fun getSuggestions(reader: CommandReader, stack: CommandStack): List<Any?> {
if (!reader.canPeek()) {
// empty string
if (executable) {
return emptyList()
} else {
checkForDeadEnd(reader)
}
}
return super.getSuggestions(reader, stack)
}
override fun executeChild(child: CommandNode, reader: CommandReader, stack: CommandStack) {
super.executeChild(child, reader, stack)
if (!onlyDirectExecution) {

View File

@ -35,7 +35,7 @@ internal class SuggestionChildReadingTest {
.addChild(
LiteralNode("1_literal")
.addChild(LiteralNode("1_literal_2"))
.addChild(LiteralNode("2_literal_2"))
.addChild(LiteralNode("2_literal_2", executable = true))
)
.addChild(LiteralNode("2_literal"))
.addChild(
@ -152,4 +152,9 @@ internal class SuggestionChildReadingTest {
fun testStringOptionalArguments() {
assertDoesNotThrow { createCommand().getSuggestions(CommandReader("3_literal string"), CommandStack()) }
}
@Test
fun testNoSuggestionsErrors() {
assertEquals(createCommand().getSuggestions(CommandReader("1_literal 2_literal_2"), CommandStack()), emptyList())
}
}