Use common infrastructure for JetMultifileBasicCompletionTest
This commit is contained in:
@@ -8,4 +8,5 @@ fun firstFun() {
|
||||
a.<caret>
|
||||
}
|
||||
|
||||
// INVOCATION_COUNT: 2
|
||||
// EXIST: secondExtension
|
||||
+2
@@ -2,4 +2,6 @@ fun main(args: Array<String>) {
|
||||
println(R.<caret>)
|
||||
}
|
||||
|
||||
// JAVA_FILE: JavaInnerClasses.java
|
||||
// INVOCATION_COUNT: 1
|
||||
// EXIST: layout
|
||||
+2
-1
@@ -6,5 +6,6 @@ fun test() {
|
||||
}
|
||||
|
||||
/* KT-3779, KT-2821 */
|
||||
|
||||
// INVOCATION_COUNT: 2
|
||||
// JAVA_FILE: javapackage/Bar.java
|
||||
// EXIST: Bar
|
||||
@@ -219,8 +219,10 @@ public class ExpectedCompletionUtils {
|
||||
return InTextDirectivesUtils.getPrefixedInt(fileText, WITH_ORDER_PREFIX) != null;
|
||||
}
|
||||
|
||||
public static void assertDirectivesValid(String fileText) {
|
||||
InTextDirectivesUtils.assertHasUnknownPrefixes(fileText, KNOWN_PREFIXES);
|
||||
public static void assertDirectivesValid(String fileText, List<String> additionalPrefixes) {
|
||||
List<String> allowedPrefixes = new ArrayList<String>(KNOWN_PREFIXES);
|
||||
allowedPrefixes.addAll(additionalPrefixes);
|
||||
InTextDirectivesUtils.assertHasUnknownPrefixes(fileText, allowedPrefixes);
|
||||
}
|
||||
|
||||
public static void assertContainsRenderedItems(CompletionProposal[] expected, LookupElement[] items, boolean checkOrder) {
|
||||
|
||||
@@ -17,47 +17,44 @@
|
||||
package org.jetbrains.jet.completion;
|
||||
|
||||
import com.intellij.codeInsight.completion.CompletionType;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.InTextDirectivesUtils;
|
||||
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||
import org.jetbrains.jet.plugin.project.TargetPlatform;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class JetCompletionMultiTestBase extends JetFixtureCompletionBaseTestCase {
|
||||
|
||||
abstract String[] getFileNameList();
|
||||
public static final String JAVA_FILE = "JAVA_FILE:";
|
||||
|
||||
/**
|
||||
* @param completionLevel {@see CompletionParameters.getInvocationCount()} javadoc
|
||||
* @param fileNameList
|
||||
* @throws Exception
|
||||
*/
|
||||
protected void doFileTest(int completionLevel, String[] fileNameList) {
|
||||
try {
|
||||
myFixture.configureByFiles(fileNameList);
|
||||
myFixture.complete(completionType(), completionLevel);
|
||||
protected void doTest() {
|
||||
doTest(getTestName(false));
|
||||
}
|
||||
|
||||
String fileText = myFixture.getFile().getText();
|
||||
|
||||
LookupElement[] lookupElements = myFixture.getLookupElements();
|
||||
ExpectedCompletionUtils.assertContainsRenderedItems(
|
||||
ExpectedCompletionUtils.itemsShouldExist(fileText), lookupElements, ExpectedCompletionUtils.isWithOrder(fileText));
|
||||
|
||||
ExpectedCompletionUtils.assertNotContainsRenderedItems(ExpectedCompletionUtils.itemsShouldAbsent(fileText), lookupElements);
|
||||
|
||||
Integer itemsNumber = ExpectedCompletionUtils.getExpectedNumber(fileText);
|
||||
if (itemsNumber != null) {
|
||||
assertEquals(itemsNumber.intValue(), lookupElements.length);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new AssertionError(e);
|
||||
@Override
|
||||
protected void setUpFixture(@NotNull String testPath) {
|
||||
myFixture.configureByFiles(getFileNameList(testPath));
|
||||
PsiFile testFile = myFixture.getFile();
|
||||
String text = testFile.getText();
|
||||
String javaFilePath = InTextDirectivesUtils.findStringWithPrefixes(text, JAVA_FILE);
|
||||
if (javaFilePath != null) {
|
||||
myFixture.configureByFile(javaFilePath);
|
||||
myFixture.configureByFiles(getFileNameList(testPath));
|
||||
}
|
||||
}
|
||||
|
||||
protected void doFileTest(int completionLevel) {
|
||||
doFileTest(completionLevel, getFileNameList());
|
||||
}
|
||||
|
||||
protected void doFileTest() {
|
||||
doFileTest(0, getFileNameList());
|
||||
@NotNull
|
||||
private String[] getFileNameList(@NotNull String testPath) {
|
||||
String baseFile = testPath + "-1.kt";
|
||||
String secondaryFile = testPath + "-2.kt";
|
||||
if (new File(getTestDataPath() + "/" + secondaryFile).exists()) {
|
||||
return new String[] {baseFile, secondaryFile};
|
||||
}
|
||||
return new String[] {baseFile};
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -70,4 +67,15 @@ public abstract class JetCompletionMultiTestBase extends JetFixtureCompletionBas
|
||||
protected CompletionType completionType() {
|
||||
return CompletionType.BASIC;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected List<String> getAdditionalDirectives() {
|
||||
return Collections.singletonList(JAVA_FILE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return PluginTestCaseBase.getTestDataPathBase() + "/completion/basic/multifile/";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,9 @@ import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.plugin.project.TargetPlatform;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class JetFixtureCompletionBaseTestCase extends LightCodeInsightFixtureTestCase {
|
||||
private boolean autoCompleteSetting;
|
||||
|
||||
@@ -60,7 +63,7 @@ public abstract class JetFixtureCompletionBaseTestCase extends LightCodeInsightF
|
||||
protected abstract CompletionType completionType();
|
||||
|
||||
public void doTest(String testPath) {
|
||||
myFixture.configureByFile(testPath);
|
||||
setUpFixture(testPath);
|
||||
|
||||
String fileText = myFixture.getFile().getText();
|
||||
|
||||
@@ -68,7 +71,7 @@ public abstract class JetFixtureCompletionBaseTestCase extends LightCodeInsightF
|
||||
|
||||
myFixture.complete(completionType(), invocationCount == null ? 0 : invocationCount);
|
||||
|
||||
ExpectedCompletionUtils.assertDirectivesValid(fileText);
|
||||
ExpectedCompletionUtils.assertDirectivesValid(fileText, getAdditionalDirectives());
|
||||
|
||||
ExpectedCompletionUtils.CompletionProposal[] expected = ExpectedCompletionUtils.itemsShouldExist(fileText, getPlatform());
|
||||
ExpectedCompletionUtils.CompletionProposal[] unexpected = ExpectedCompletionUtils.itemsShouldAbsent(fileText, getPlatform());
|
||||
@@ -94,4 +97,13 @@ public abstract class JetFixtureCompletionBaseTestCase extends LightCodeInsightF
|
||||
itemsNumber.intValue(), items.length);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected List<String> getAdditionalDirectives() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
protected void setUpFixture(@NotNull String testPath) {
|
||||
myFixture.configureByFile(testPath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,75 +16,60 @@
|
||||
|
||||
package org.jetbrains.jet.completion;
|
||||
|
||||
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||
|
||||
public class JetMultifileBasicCompletionTest extends JetCompletionMultiTestBase {
|
||||
public void testCompleteImportedFunction() {
|
||||
doFileTest();
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testCompletionOnImportedFunction() {
|
||||
doFileTest();
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testDoNotCompleteWithConstraints() {
|
||||
doFileTest();
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testTopLevelFunction() throws Exception {
|
||||
doFileTest();
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testExtensionFunctionOnImportedFunction() throws Exception {
|
||||
doFileTest(2);
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void todotestExtensionFunctionOnUnresolved() throws Exception {
|
||||
doFileTest();
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testExtensionOnNullable() throws Exception {
|
||||
doFileTest();
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void todotestExtensionProperty() throws Exception {
|
||||
doFileTest();
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNotImportedJavaClass() throws Exception {
|
||||
String fileName = getTestName(false);
|
||||
doFileTest(2, new String[] {fileName + ".kt", "javapackage/Bar.java"});
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testInImportedFunctionLiteralParameter() throws Exception {
|
||||
doFileTest(2);
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testJavaInnerClasses() throws Exception {
|
||||
String fileName = getTestName(false);
|
||||
doFileTest(1, new String[] {fileName + ".kt", fileName + ".java"});
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNotImportedExtensionFunction() throws Exception {
|
||||
doFileTest();
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testExtensionFunction() throws Exception {
|
||||
doFileTest(2);
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNotImportedObject() throws Exception {
|
||||
doFileTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return PluginTestCaseBase.getTestDataPathBase() + "/completion/basic/multifile/";
|
||||
}
|
||||
|
||||
@Override
|
||||
String[] getFileNameList() {
|
||||
String fileName = getTestName(false);
|
||||
return new String[]{fileName + "-1.kt", fileName + "-2.kt"};
|
||||
doTest();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user