From 047abe8b7b87731509bf7caa01289a1faeeb829c Mon Sep 17 00:00:00 2001 From: jan-vcapgemini Date: Tue, 7 Nov 2023 12:30:53 +0100 Subject: [PATCH] #56: moved tests to cli --- .../{context => cli}/AutoCompletionTest.java | 51 ++++--------------- .../{context => cli}/ReaderTestSupport.java | 4 +- 2 files changed, 13 insertions(+), 42 deletions(-) rename cli/src/test/java/com/devonfw/tools/ide/{context => cli}/AutoCompletionTest.java (56%) rename cli/src/test/java/com/devonfw/tools/ide/{context => cli}/ReaderTestSupport.java (98%) diff --git a/cli/src/test/java/com/devonfw/tools/ide/context/AutoCompletionTest.java b/cli/src/test/java/com/devonfw/tools/ide/cli/AutoCompletionTest.java similarity index 56% rename from cli/src/test/java/com/devonfw/tools/ide/context/AutoCompletionTest.java rename to cli/src/test/java/com/devonfw/tools/ide/cli/AutoCompletionTest.java index eda9342f8..cfb0fa771 100644 --- a/cli/src/test/java/com/devonfw/tools/ide/context/AutoCompletionTest.java +++ b/cli/src/test/java/com/devonfw/tools/ide/cli/AutoCompletionTest.java @@ -1,53 +1,18 @@ -package com.devonfw.tools.ide.context; - -import static com.devonfw.tools.ide.context.AbstractIdeContextTest.newContext; -import static org.junit.jupiter.api.Assertions.assertEquals; +package com.devonfw.tools.ide.cli; import java.io.IOException; import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.List; - -import org.jline.builtins.Completers; -import org.jline.reader.Completer; -import org.jline.reader.impl.completer.ArgumentCompleter; -import org.jline.reader.impl.completer.NullCompleter; -import org.jline.reader.impl.completer.StringsCompleter; + import org.junit.jupiter.api.Test; -import com.devonfw.tools.ide.cli.IdeCompleter; import com.devonfw.tools.ide.commandlet.ContextCommandlet; +import com.devonfw.tools.ide.context.IdeTestContext; -public class AutoCompletionTest extends ReaderTestSupport{ - - @Test - public void testOptions() throws Exception { - List argsCompleters = new ArrayList<>(); - List options = new ArrayList<>(); - argsCompleters.add(new StringsCompleter("bar", "rab")); - argsCompleters.add(new StringsCompleter("foo", "oof")); - argsCompleters.add(NullCompleter.INSTANCE); - options.add(new Completers.OptDesc("-s", "--sopt", new StringsCompleter("val", "lav"))); - options.add(new Completers.OptDesc(null, "--option", NullCompleter.INSTANCE)); - - reader.setCompleter(new ArgumentCompleter( - new StringsCompleter("command"), new Completers.OptionCompleter(argsCompleters, options, 1))); - - assertBuffer("command ", new TestBuffer("c").tab()); - assertBuffer("command -s", new TestBuffer("command -").tab()); - assertBuffer("command -s val ", new TestBuffer("command -s v").tab()); - assertBuffer("command -sval ", new TestBuffer("command -sv").tab()); - assertBuffer("command --sopt val ", new TestBuffer("command --sopt v").tab()); - assertBuffer("command --sopt=", new TestBuffer("command --sop").tab()); - assertBuffer("command --sopt=val ", new TestBuffer("command --sopt=v").tab()); - assertBuffer("command -sval ", new TestBuffer("command -sv").tab()); - assertBuffer("command -s val bar ", new TestBuffer("command -s val b").tab()); - assertBuffer("command -s val bar --option ", new TestBuffer("command -s val bar --o").tab()); - assertBuffer("command -s val bar --option foo ", new TestBuffer("command -s val bar --option f").tab()); - } +public class AutoCompletionTest extends ReaderTestSupport { @Test public void testIdeCompleterHelp() throws IOException { + ContextCommandlet contextCommandlet = new ContextCommandlet(); IdeTestContext ideContext = new IdeTestContext(Paths.get(""), ""); reader.setCompleter(new IdeCompleter(contextCommandlet, ideContext)); @@ -56,6 +21,7 @@ public void testIdeCompleterHelp() throws IOException { @Test public void testIdeCompleterInstall() throws IOException { + ContextCommandlet contextCommandlet = new ContextCommandlet(); IdeTestContext ideContext = new IdeTestContext(Paths.get(""), ""); reader.setCompleter(new IdeCompleter(contextCommandlet, ideContext)); @@ -64,6 +30,7 @@ public void testIdeCompleterInstall() throws IOException { @Test public void testIdeCompleterHelpWithToolCompletion() throws IOException { + ContextCommandlet contextCommandlet = new ContextCommandlet(); IdeTestContext ideContext = new IdeTestContext(Paths.get(""), ""); reader.setCompleter(new IdeCompleter(contextCommandlet, ideContext)); @@ -72,6 +39,7 @@ public void testIdeCompleterHelpWithToolCompletion() throws IOException { @Test public void testIdeCompleterOptions() throws IOException { + ContextCommandlet contextCommandlet = new ContextCommandlet(); IdeTestContext ideContext = new IdeTestContext(Paths.get(""), ""); reader.setCompleter(new IdeCompleter(contextCommandlet, ideContext)); @@ -81,6 +49,7 @@ public void testIdeCompleterOptions() throws IOException { @Test public void testIdeCompleterOptionsRemovesUsedOption() throws IOException { + ContextCommandlet contextCommandlet = new ContextCommandlet(); IdeTestContext ideContext = new IdeTestContext(Paths.get(""), ""); reader.setCompleter(new IdeCompleter(contextCommandlet, ideContext)); @@ -90,6 +59,7 @@ public void testIdeCompleterOptionsRemovesUsedOption() throws IOException { @Test public void testIdeCompleterThirdLayerVersions() throws IOException { + ContextCommandlet contextCommandlet = new ContextCommandlet(); IdeTestContext ideContext = new IdeTestContext(Paths.get(""), ""); reader.setCompleter(new IdeCompleter(contextCommandlet, ideContext)); @@ -99,6 +69,7 @@ public void testIdeCompleterThirdLayerVersions() throws IOException { @Test public void testIdeCompleterNonExistentCommand() throws IOException { + ContextCommandlet contextCommandlet = new ContextCommandlet(); IdeTestContext ideContext = new IdeTestContext(Paths.get(""), ""); reader.setCompleter(new IdeCompleter(contextCommandlet, ideContext)); diff --git a/cli/src/test/java/com/devonfw/tools/ide/context/ReaderTestSupport.java b/cli/src/test/java/com/devonfw/tools/ide/cli/ReaderTestSupport.java similarity index 98% rename from cli/src/test/java/com/devonfw/tools/ide/context/ReaderTestSupport.java rename to cli/src/test/java/com/devonfw/tools/ide/cli/ReaderTestSupport.java index 91b594c65..0667f39f4 100644 --- a/cli/src/test/java/com/devonfw/tools/ide/context/ReaderTestSupport.java +++ b/cli/src/test/java/com/devonfw/tools/ide/cli/ReaderTestSupport.java @@ -6,7 +6,7 @@ * * https://opensource.org/licenses/BSD-3-Clause */ -package com.devonfw.tools.ide.context; +package com.devonfw.tools.ide.cli; import static org.jline.reader.LineReader.ACCEPT_LINE; import static org.jline.reader.LineReader.BACKWARD_CHAR; @@ -47,7 +47,7 @@ /** * Provides support for reader and completion tests. - * Inspired from jline3 + * Inspired by jline3 */ public abstract class ReaderTestSupport extends Assertions { protected Terminal terminal;