Skip to content

Commit

Permalink
#56: moved tests to cli
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-vcapgemini committed Nov 7, 2023
1 parent 3e99f66 commit 047abe8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -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<Completer> argsCompleters = new ArrayList<>();
List<Completers.OptDesc> 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));
Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 047abe8

Please sign in to comment.