Skip to content

Commit

Permalink
#56: implemented requested changes
Browse files Browse the repository at this point in the history
fixed typo
added TODO
  • Loading branch information
jan-vcapgemini committed Jan 23, 2024
1 parent 3927330 commit 42ea369
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.devonfw.tools.ide.completion;

import java.util.List;

import com.devonfw.tools.ide.commandlet.Commandlet;
import com.devonfw.tools.ide.property.Property;

import java.util.List;

/**
* Implementation of {@link CompletionCandidateCollector} that wraps and existing {@link CompletionCandidateCollector} adding a prefix.
* Implementation of {@link CompletionCandidateCollector} that wraps an existing {@link CompletionCandidateCollector}
* adding a prefix.
*/
public class CompletionCandidateCollectorAdapter implements CompletionCandidateCollector {

Expand All @@ -21,13 +22,15 @@ public class CompletionCandidateCollectorAdapter implements CompletionCandidateC
* @param delegate the {@link CompletionCandidateCollector} to wrap.
*/
public CompletionCandidateCollectorAdapter(String prefix, CompletionCandidateCollector delegate) {

super();
this.prefix = prefix;
this.delegate = delegate;
}

@Override
public void add(String text, Property<?> property, Commandlet commandlet) {

this.delegate.add(this.prefix + text, property, commandlet);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package com.devonfw.tools.ide.completion;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

import com.devonfw.tools.ide.cli.CliArguments;
import com.devonfw.tools.ide.commandlet.Commandlet;
import com.devonfw.tools.ide.commandlet.ContextCommandlet;
import com.devonfw.tools.ide.context.AbstractIdeContext;
import com.devonfw.tools.ide.context.IdeTestContextMock;
import com.devonfw.tools.ide.property.Property;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
* Test of {@link AbstractIdeContext#complete(CliArguments, boolean) auto-completion}.
Expand Down Expand Up @@ -75,7 +76,8 @@ public void testCompleteShortOptsCombined() {
// act
List<CompletionCandidate> candidates = context.complete(args, true);
// assert
assertThat(candidates.stream().map(CompletionCandidate::text)).containsExactly("-f", "-fb", "-fd", "-fo", "-fq", "-ft", "-fv");
assertThat(candidates.stream().map(CompletionCandidate::text)).containsExactly("-f", "-fb", "-fd", "-fo", "-fq",
"-ft", "-fv");
}

/** Test of {@link AbstractIdeContext#complete(CliArguments, boolean) auto-completion} for input "-fbdoqt". */
Expand All @@ -99,11 +101,13 @@ public void testCompleteHelpEmptyArgs() {
AbstractIdeContext context = IdeTestContextMock.get();
CliArguments args = CliArguments.ofCompletion("help", "");
List<String> expectedCandidates = getExpectedCandidates(context, true, false);
// TODO: fix the hacky workaround, see: https://github.com/devonfw/IDEasy/issues/188
expectedCandidates.remove("-v"); // hackish solution, improve me please
// act
List<CompletionCandidate> candidates = context.complete(args, true);
// assert
assertThat(candidates.stream().map(CompletionCandidate::text)).containsExactly(expectedCandidates.toArray(String[]::new));
assertThat(candidates.stream().map(CompletionCandidate::text))
.containsExactly(expectedCandidates.toArray(String[]::new));
}

/** Test of {@link AbstractIdeContext#complete(CliArguments, boolean) auto-completion} for input "help", "". */
Expand All @@ -119,7 +123,8 @@ public void testCompleteVersionNoMoreArgs() {
assertThat(candidates).isEmpty();
}

private static List<String> getExpectedCandidates(AbstractIdeContext context, boolean commandlets, boolean ctxOptions) {
private static List<String> getExpectedCandidates(AbstractIdeContext context, boolean commandlets,
boolean ctxOptions) {

List<String> expectedCandidates = new ArrayList<>();
if (ctxOptions) {
Expand Down

0 comments on commit 42ea369

Please sign in to comment.