mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
move completion sorting checks to the fixture
This commit is contained in:
+3
-26
@@ -10,11 +10,6 @@ import com.intellij.codeInsight.lookup.impl.LookupImpl;
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
@@ -41,30 +36,12 @@ public abstract class CompletionSortingTestCase extends LightFixtureCompletionTe
|
||||
}
|
||||
|
||||
protected void assertPreferredItems(final int selected, @NonNls final String... expected) {
|
||||
final LookupImpl lookup = getLookup();
|
||||
final JList list = lookup.getList();
|
||||
final List<LookupElement> model = lookup.getItems();
|
||||
final List<String> actual = new ArrayList<String>();
|
||||
final int count = lookup.getPreferredItemsCount();
|
||||
for (int i = 0; i < count; i++) {
|
||||
actual.add(model.get(i).getLookupString());
|
||||
}
|
||||
if (!actual.equals(Arrays.asList(expected))) {
|
||||
final List<String> strings = new ArrayList<String>();
|
||||
for (int i = 0; i < model.size(); i++) {
|
||||
final LookupElement item = model.get(i);
|
||||
strings.add(item.getLookupString() + Arrays.toString(item.getUserData(CompletionLookupArranger.WEIGHT)));
|
||||
if (i == count - 1) {
|
||||
strings.add("---");
|
||||
}
|
||||
}
|
||||
assertOrderedEquals(strings, expected);
|
||||
}
|
||||
assertEquals(selected, list.getSelectedIndex());
|
||||
myFixture.assertPreferredCompletionItems(selected, expected);
|
||||
}
|
||||
|
||||
protected LookupImpl invokeCompletion(final String path) throws Exception {
|
||||
myFixture.configureFromExistingVirtualFile(myFixture.copyFileToProject(path, com.intellij.openapi.util.text.StringUtil.getShortName(path, '/')));
|
||||
myFixture.configureFromExistingVirtualFile(
|
||||
myFixture.copyFileToProject(path, com.intellij.openapi.util.text.StringUtil.getShortName(path, '/')));
|
||||
myFixture.complete(myType);
|
||||
return getLookup();
|
||||
}
|
||||
|
||||
+2
@@ -367,4 +367,6 @@ public interface CodeInsightTestFixture extends IdeaProjectTestFixture {
|
||||
|
||||
void testFolding(String fileName);
|
||||
void testFoldingWithCollapseStatus(String fileName);
|
||||
|
||||
void assertPreferredCompletionItems(int selected, @NonNls String... expected);
|
||||
}
|
||||
|
||||
+32
-1
@@ -20,6 +20,7 @@ import com.intellij.analysis.AnalysisScope;
|
||||
import com.intellij.codeHighlighting.HighlightDisplayLevel;
|
||||
import com.intellij.codeInsight.TargetElementUtilBase;
|
||||
import com.intellij.codeInsight.completion.CodeCompletionHandlerBase;
|
||||
import com.intellij.codeInsight.completion.CompletionLookupArranger;
|
||||
import com.intellij.codeInsight.completion.CompletionProgressIndicator;
|
||||
import com.intellij.codeInsight.completion.CompletionType;
|
||||
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
|
||||
@@ -900,7 +901,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
@Override
|
||||
@Nullable
|
||||
public LookupElement[] getLookupElements() {
|
||||
LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(myEditor);
|
||||
LookupImpl lookup = getLookup();
|
||||
if (lookup == null) {
|
||||
return myEmptyLookup ? LookupElement.EMPTY_ARRAY : null;
|
||||
}
|
||||
@@ -1683,4 +1684,34 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
public void testFolding(final String verificationFileName) {
|
||||
testFoldingRegions(verificationFileName, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void assertPreferredCompletionItems(final int selected, @NonNls final String... expected) {
|
||||
final LookupImpl lookup = getLookup();
|
||||
assertNotNull(lookup);
|
||||
final JList list = lookup.getList();
|
||||
final List<LookupElement> model = lookup.getItems();
|
||||
final List<String> actual = new ArrayList<String>();
|
||||
final int count = lookup.getPreferredItemsCount();
|
||||
for (int i = 0; i < count; i++) {
|
||||
actual.add(model.get(i).getLookupString());
|
||||
}
|
||||
if (!actual.equals(Arrays.asList(expected))) {
|
||||
final List<String> strings = new ArrayList<String>();
|
||||
for (int i = 0; i < model.size(); i++) {
|
||||
final LookupElement item = model.get(i);
|
||||
strings.add(item.getLookupString() + Arrays.toString(item.getUserData(CompletionLookupArranger.WEIGHT)));
|
||||
if (i == count - 1) {
|
||||
strings.add("---");
|
||||
}
|
||||
}
|
||||
assertOrderedEquals(strings, expected);
|
||||
}
|
||||
assertEquals(selected, list.getSelectedIndex());
|
||||
}
|
||||
|
||||
private LookupImpl getLookup() {
|
||||
return (LookupImpl)LookupManager.getActiveLookup(myEditor);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user