mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixture-based completion sorting tests
This commit is contained in:
+9
-20
@@ -4,12 +4,9 @@
|
||||
*/
|
||||
package com.intellij.codeInsight.completion;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.LookupManager;
|
||||
import com.intellij.codeInsight.lookup.impl.LookupImpl;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
@@ -22,37 +19,28 @@ import java.util.List;
|
||||
* @author peter
|
||||
*/
|
||||
@TestDataPath("$CONTENT_ROOT/testData")
|
||||
public abstract class CompletionSortingTestCase extends LightCompletionTestCase {
|
||||
public abstract class CompletionSortingTestCase extends LightFixtureCompletionTestCase {
|
||||
private final CompletionType myType;
|
||||
|
||||
@SuppressWarnings({"JUnitTestCaseWithNonTrivialConstructors"})
|
||||
protected CompletionSortingTestCase(CompletionType type) {
|
||||
setType(type);
|
||||
myType = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
LookupManager.getInstance(getProject()).hideActiveLookup();
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Sdk getProjectJDK() {
|
||||
return JavaSdkImpl.getMockJdk17("java 1.5");
|
||||
}
|
||||
|
||||
protected abstract String getBasePath();
|
||||
|
||||
protected void checkPreferredItems(final int selected, @NonNls final String... expected) throws Exception {
|
||||
invokeCompletion(getBasePath() + "/" + getTestName(false) + ".java");
|
||||
invokeCompletion(getTestName(false) + ".java");
|
||||
assertPreferredItems(selected, expected);
|
||||
}
|
||||
|
||||
protected static void assertPreferredItems(final int selected, @NonNls final String... expected) {
|
||||
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();
|
||||
@@ -75,8 +63,9 @@ public abstract class CompletionSortingTestCase extends LightCompletionTestCase
|
||||
assertEquals(selected, list.getSelectedIndex());
|
||||
}
|
||||
|
||||
protected LookupImpl invokeCompletion(final String filePath) throws Exception {
|
||||
configureByFile(filePath);
|
||||
protected LookupImpl invokeCompletion(final String path) throws Exception {
|
||||
myFixture.configureFromExistingVirtualFile(myFixture.copyFileToProject(path, com.intellij.openapi.util.text.StringUtil.getShortName(path, '/')));
|
||||
myFixture.complete(myType);
|
||||
return getLookup();
|
||||
}
|
||||
|
||||
|
||||
+19
-20
@@ -4,12 +4,14 @@
|
||||
|
||||
package com.intellij.codeInsight.completion;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInsight.CodeInsightSettings;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.impl.LookupImpl;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings({"ALL"})
|
||||
public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
|
||||
private static final String BASE_PATH = "/codeInsight/completion/normalSorting";
|
||||
@@ -19,7 +21,7 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
|
||||
}
|
||||
|
||||
protected String getBasePath() {
|
||||
return BASE_PATH;
|
||||
return JavaTestUtil.getRelativeJavaTestDataPath() + BASE_PATH;
|
||||
}
|
||||
|
||||
public void testDontPreferRecursiveMethod() throws Throwable {
|
||||
@@ -51,7 +53,7 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
|
||||
}
|
||||
|
||||
public void testShorterPrefixesGoFirst() throws Throwable {
|
||||
final LookupImpl lookup = invokeCompletion(getBasePath() + "/" + getTestName(false) + ".html");
|
||||
final LookupImpl lookup = invokeCompletion(getTestName(false) + ".html");
|
||||
assertPreferredItems(0, "p", "param", "pre");
|
||||
incUseCount(lookup, 2);
|
||||
assertPreferredItems(0, "p", "pre", "param");
|
||||
@@ -108,7 +110,7 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
|
||||
}
|
||||
|
||||
public void testDispreferImpls() throws Throwable {
|
||||
VfsUtil.saveText(getSourceRoot().createChildDirectory(this, "foo").createChildData(this, "Xxx.java"), "package foo; public class Xxx {}");
|
||||
myFixture.addClass("package foo; public class Xxx {}");
|
||||
checkPreferredItems(0, "Xxy", "Xxx", "XxxEx", "XxxImpl");
|
||||
}
|
||||
|
||||
@@ -121,27 +123,26 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
|
||||
}
|
||||
|
||||
public void testDontDispreferImplsAfterNew() throws Throwable {
|
||||
VfsUtil.saveText(getSourceRoot().createChildDirectory(this, "foo").createChildData(this, "Xxx.java"), "package foo; public interface Xxx {}");
|
||||
myFixture.addClass("package foo; public interface Xxx {}");
|
||||
checkPreferredItems(0, "Xxx", "XxxImpl");
|
||||
}
|
||||
|
||||
public void testPreferLessHumps() throws Throwable {
|
||||
final VirtualFile foo = getSourceRoot().createChildDirectory(this, "foo");
|
||||
VfsUtil.saveText(foo.createChildData(this, "XaYa.java"), "package foo; public interface XaYa {}");
|
||||
VfsUtil.saveText(foo.createChildData(this, "XyYa.java"), "package foo; public interface XyYa {}");
|
||||
myFixture.addClass("package foo; public interface XaYa {}");
|
||||
myFixture.addClass("package foo; public interface XyYa {}");
|
||||
checkPreferredItems(0, "XaYa", "XyYa", "XaYaEx", "XaYaImpl", "XyYaXa");
|
||||
}
|
||||
|
||||
public void testPreferLessParameters() throws Throwable {
|
||||
checkPreferredItems(0, "foo", "foo", "foo", "fox");
|
||||
assertEquals(0, ((PsiMethod)myItems[0].getObject()).getParameterList().getParametersCount());
|
||||
assertEquals(1, ((PsiMethod)myItems[1].getObject()).getParameterList().getParametersCount());
|
||||
assertEquals(2, ((PsiMethod)myItems[2].getObject()).getParameterList().getParametersCount());
|
||||
final List<LookupElement> items = getLookup().getItems();
|
||||
assertEquals(0, ((PsiMethod)items.get(0).getObject()).getParameterList().getParametersCount());
|
||||
assertEquals(1, ((PsiMethod)items.get(1).getObject()).getParameterList().getParametersCount());
|
||||
assertEquals(2, ((PsiMethod)items.get(2).getObject()).getParameterList().getParametersCount());
|
||||
}
|
||||
public void testStatsForClassNameInExpression() throws Throwable {
|
||||
final VirtualFile foo = getSourceRoot().createChildDirectory(this, "foo");
|
||||
VfsUtil.saveText(foo.createChildData(this, "FooBar.java"), "package foo; public interface FooBar {}");
|
||||
VfsUtil.saveText(foo.createChildData(this, "FooBee.java"), "package foo; public interface FooBee {}");
|
||||
myFixture.addClass("package foo; public interface FooBar {}");
|
||||
myFixture.addClass("package foo; public interface FooBee {}");
|
||||
|
||||
checkPreferredItems(0, "FooBar", "FooBee");
|
||||
incUseCount(getLookup(), 1);
|
||||
@@ -161,17 +162,15 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
|
||||
}
|
||||
|
||||
public void testClassInCallOfItsMethod() throws Throwable {
|
||||
final VirtualFile foo = getSourceRoot().createChildDirectory(this, "foo");
|
||||
VfsUtil.saveText(foo.createChildData(this, "Foo.java"), "package foo; public interface Foo {}");
|
||||
final VirtualFile bar = getSourceRoot().createChildDirectory(this, "bar");
|
||||
VfsUtil.saveText(bar.createChildData(this, "Foo.java"), "package bar; public interface Foo {}");
|
||||
myFixture.addClass("package foo; public interface Foo {}");
|
||||
myFixture.addClass("package bar; public interface Foo {}");
|
||||
|
||||
checkPreferredItems(0, "Foo", "Foo");
|
||||
assertEquals("foo.Foo", ((JavaPsiClassReferenceElement)getLookup().getCurrentItem()).getQualifiedName());
|
||||
}
|
||||
|
||||
public void testDeclaredMembersGoFirst() throws Exception {
|
||||
invokeCompletion(getBasePath() + "/" + getTestName(false) + ".java");
|
||||
invokeCompletion(getTestName(false) + ".java");
|
||||
assertStringItems("fromThis", "overridden", "fromSuper", "equals", "getClass", "hashCode", "notify", "notifyAll", "toString", "wait", "wait", "wait");
|
||||
}
|
||||
|
||||
|
||||
+10
-15
@@ -4,8 +4,8 @@
|
||||
|
||||
package com.intellij.codeInsight.completion;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInsight.lookup.impl.LookupImpl;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.statistics.StatisticsManager;
|
||||
|
||||
public class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase {
|
||||
@@ -15,11 +15,6 @@ public class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase {
|
||||
super(CompletionType.SMART);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LanguageLevel getLanguageLevel() {
|
||||
return LanguageLevel.JDK_1_6;
|
||||
}
|
||||
|
||||
public void testJComponentAdd() throws Throwable {
|
||||
checkPreferredItems(0, "name", "b", "fooBean239", "this", "getName");
|
||||
}
|
||||
@@ -31,7 +26,7 @@ public class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase {
|
||||
|
||||
public void testJComponentAddNewWithStats() throws Throwable {
|
||||
//there's no PopupMenu in mock jdk
|
||||
final LookupImpl lookup = invokeCompletion(BASE_PATH + "/JComponentAddNew.java");
|
||||
final LookupImpl lookup = invokeCompletion("/JComponentAddNew.java");
|
||||
assertPreferredItems(2, "Component", "String", "FooBean3", "Container", "JComponent");
|
||||
incUseCount(lookup, 3); //Container
|
||||
assertPreferredItems(2, "Component", "String", "Container", "FooBean3", "JComponent");
|
||||
@@ -44,7 +39,7 @@ public class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase {
|
||||
}
|
||||
|
||||
public void testMethodStats() throws Throwable {
|
||||
final LookupImpl lookup = invokeCompletion(BASE_PATH + "/" + getTestName(false) + ".java");
|
||||
final LookupImpl lookup = invokeCompletion(getTestName(false) + ".java");
|
||||
assertPreferredItems(0, "bar", "foo", "goo");
|
||||
incUseCount(lookup, 2);
|
||||
assertPreferredItems(0, "goo", "bar", "foo");
|
||||
@@ -141,7 +136,7 @@ public class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase {
|
||||
}
|
||||
|
||||
public void testStatisticsAffectsNonPreferableExpectedItems() throws Throwable {
|
||||
final LookupImpl lookup = invokeCompletion(BASE_PATH + "/" + getTestName(false) + ".java");
|
||||
final LookupImpl lookup = invokeCompletion(getTestName(false) + ".java");
|
||||
assertPreferredItems(1, "List<Foo>", "AbstractList<Foo>", "AbstractSequentialList<Foo>", "ArrayList<Foo>");
|
||||
incUseCount(lookup, 0);
|
||||
assertPreferredItems(1, "List<Foo>", "AbstractList<Foo>", "AbstractSequentialList<Foo>", "ArrayList<Foo>");
|
||||
@@ -155,7 +150,7 @@ public class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase {
|
||||
|
||||
public void testPreferDelegatingMethodParams() throws Throwable {
|
||||
//there's no PopupMenu in mock jdk
|
||||
final LookupImpl lookup = invokeCompletion(BASE_PATH + "/" + getTestName(false) + ".java");
|
||||
final LookupImpl lookup = invokeCompletion(getTestName(false) + ".java");
|
||||
assertPreferredItems(0, "xyz", "abc");
|
||||
incUseCount(lookup, 1);
|
||||
assertPreferredItems(0, "xyz", "abc");
|
||||
@@ -214,7 +209,7 @@ public class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase {
|
||||
}
|
||||
|
||||
public void testLocalVariablesOutweighStats() throws Throwable {
|
||||
final LookupImpl lookup = invokeCompletion(BASE_PATH + "/" + getTestName(false) + ".java");
|
||||
final LookupImpl lookup = invokeCompletion(getTestName(false) + ".java");
|
||||
assertPreferredItems(0, "foo", "param", "this", "bar", "goo");
|
||||
incUseCount(lookup, 4);
|
||||
assertPreferredItems(0, "foo", "param", "this", "goo", "bar");
|
||||
@@ -226,15 +221,15 @@ public class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase {
|
||||
}
|
||||
|
||||
public void testPreferredByNameDontChangeStatistics() throws Throwable {
|
||||
final LookupImpl lookup = invokeCompletion(BASE_PATH + "/" + getTestName(false) + ".java");
|
||||
final LookupImpl lookup = invokeCompletion(getTestName(false) + ".java");
|
||||
assertPreferredItems(0, "foo", "false");
|
||||
lookup.finishLookup(',');
|
||||
myFixture.type(',');
|
||||
complete();
|
||||
assertPreferredItems(0, "bar", "foo", "equals", "false", "true");
|
||||
}
|
||||
|
||||
public void testFieldNameOutweighsStats() throws Throwable {
|
||||
final LookupImpl lookup = invokeCompletion(BASE_PATH + "/" + getTestName(false) + ".java");
|
||||
final LookupImpl lookup = invokeCompletion(getTestName(false) + ".java");
|
||||
assertPreferredItems(0, "myFoo", "myBar");
|
||||
incUseCount(lookup, 1); //myBar
|
||||
assertPreferredItems(0, "myFoo", "myBar");
|
||||
@@ -242,6 +237,6 @@ public class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase {
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return BASE_PATH;
|
||||
return JavaTestUtil.getRelativeJavaTestDataPath() + BASE_PATH;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user