From d1451bd86390de53d570b3bb9d7196aa3740568b Mon Sep 17 00:00:00 2001 From: Bixilon Date: Sun, 29 May 2022 19:51:59 +0200 Subject: [PATCH] fix dead end error with executable literal nodes --- .../minosoft/commands/nodes/ExecutableNode.kt | 12 ++++++++++++ .../commands/nodes/SuggestionChildReadingTest.kt | 7 ++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/bixilon/minosoft/commands/nodes/ExecutableNode.kt b/src/main/java/de/bixilon/minosoft/commands/nodes/ExecutableNode.kt index b297aaa0e..7a447e13b 100644 --- a/src/main/java/de/bixilon/minosoft/commands/nodes/ExecutableNode.kt +++ b/src/main/java/de/bixilon/minosoft/commands/nodes/ExecutableNode.kt @@ -48,6 +48,18 @@ abstract class ExecutableNode( super.execute(reader, stack) } + override fun getSuggestions(reader: CommandReader, stack: CommandStack): List { + 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) { diff --git a/src/test/java/de/bixilon/minosoft/commands/nodes/SuggestionChildReadingTest.kt b/src/test/java/de/bixilon/minosoft/commands/nodes/SuggestionChildReadingTest.kt index e2b22677f..461f24f44 100644 --- a/src/test/java/de/bixilon/minosoft/commands/nodes/SuggestionChildReadingTest.kt +++ b/src/test/java/de/bixilon/minosoft/commands/nodes/SuggestionChildReadingTest.kt @@ -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()) + } }