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