Minor: cleanup tests in org.jetbrains.kotlin.idea.navigation
This commit is contained in:
@@ -34,8 +34,7 @@ abstract class AbstractGotoActionTest : KotlinLightCodeInsightFixtureTestCase()
|
||||
val afterText = StringBuilder(text).insert(editor.caretModel.offset, "<caret>").toString()
|
||||
|
||||
Assert.assertEquals(parts[1], afterText)
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
val fileOffset = currentEditor.caretModel.offset
|
||||
val lineNumber = currentEditor.document.getLineNumber(fileOffset)
|
||||
val lineStart = currentEditor.document.getLineStartOffset(lineNumber)
|
||||
|
||||
+4
-1
@@ -26,7 +26,10 @@ abstract class AbstractKotlinGotoImplementationTest : LightCodeInsightTestCase()
|
||||
|
||||
protected fun doTest(path: String) {
|
||||
configureByFile(path)
|
||||
val gotoData = NavigationTestUtils.invokeGotoImplementations(LightPlatformCodeInsightTestCase.getEditor(), LightPlatformCodeInsightTestCase.getFile())
|
||||
val gotoData = NavigationTestUtils.invokeGotoImplementations(
|
||||
LightPlatformCodeInsightTestCase.getEditor(),
|
||||
LightPlatformCodeInsightTestCase.getFile()
|
||||
)
|
||||
NavigationTestUtils.assertGotoDataMatching(LightPlatformCodeInsightTestCase.getEditor(), gotoData)
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,7 @@ public abstract class AbstractKotlinGotoTest extends KotlinLightCodeInsightFixtu
|
||||
dirPath = null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return dirPath;
|
||||
|
||||
@@ -12,25 +12,33 @@ import com.intellij.psi.PsiElement
|
||||
import com.intellij.testFramework.UsefulTestCase
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||
import org.jetbrains.kotlin.test.util.renderAsGotoImplementation
|
||||
import org.jetbrains.kotlin.utils.sure
|
||||
import org.junit.Assert
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
object GotoCheck {
|
||||
@JvmStatic @JvmOverloads
|
||||
fun checkGotoDirectives(model: FilteringGotoByModel<Language>, editor: Editor, nonProjectSymbols: Boolean = false, checkNavigation: Boolean = false) {
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun checkGotoDirectives(
|
||||
model: FilteringGotoByModel<Language>,
|
||||
editor: Editor,
|
||||
nonProjectSymbols: Boolean = false,
|
||||
checkNavigation: Boolean = false
|
||||
) {
|
||||
val documentText = editor.document.text
|
||||
val searchTextList = InTextDirectivesUtils.findListWithPrefixes(documentText, "// SEARCH_TEXT:")
|
||||
Assert.assertFalse("There's no search text in test data file given. Use '// SEARCH_TEXT:' directive",
|
||||
searchTextList.isEmpty())
|
||||
Assert.assertFalse(
|
||||
"There's no search text in test data file given. Use '// SEARCH_TEXT:' directive",
|
||||
searchTextList.isEmpty()
|
||||
)
|
||||
|
||||
val expectedReferences = InTextDirectivesUtils.findLinesWithPrefixesRemoved(documentText, "// REF:").map { input -> input.trim { it <= ' ' } }
|
||||
val expectedReferences =
|
||||
InTextDirectivesUtils.findLinesWithPrefixesRemoved(documentText, "// REF:").map { input -> input.trim { it <= ' ' } }
|
||||
val includeNonProjectSymbols = nonProjectSymbols || InTextDirectivesUtils.isDirectiveDefined(documentText, "// CHECK_BOX")
|
||||
|
||||
val searchText = searchTextList.first()
|
||||
|
||||
val foundSymbols = model.getNames(includeNonProjectSymbols).filter { it?.startsWith(searchText) ?: false }.flatMap {
|
||||
model.getElementsByName(it, includeNonProjectSymbols, it + "*").toList()
|
||||
model.getElementsByName(it, includeNonProjectSymbols, "$it*").toList()
|
||||
}
|
||||
|
||||
val inexactMatching = InTextDirectivesUtils.isDirectiveDefined(documentText, "// ALLOW_MORE_RESULTS")
|
||||
@@ -42,8 +50,7 @@ object GotoCheck {
|
||||
|
||||
if (inexactMatching) {
|
||||
UsefulTestCase.assertContainsElements(renderedSymbols, expectedReferences)
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
UsefulTestCase.assertOrderedEquals(renderedSymbols.sorted(), expectedReferences)
|
||||
}
|
||||
if (!checkNavigation) return
|
||||
|
||||
@@ -18,34 +18,34 @@ import org.jetbrains.kotlin.test.util.projectLibrary
|
||||
class GotoWithMultipleLibrariesTest : AbstractMultiModuleTest() {
|
||||
override fun getTestDataPath() = "${PluginTestCaseBase.getTestDataPathBase()}/multiModuleReferenceResolve/sameJarInDifferentLibraries/"
|
||||
|
||||
fun testOneHasSourceAndOneDoesnot() {
|
||||
fun testOneHasSourceAndOneDoesNot() {
|
||||
doTestSameJarSharedByLibrariesWithAndWithoutSourceAttached(
|
||||
withSource = 1,
|
||||
noSource = 1
|
||||
withSource = 1,
|
||||
noSource = 1
|
||||
)
|
||||
}
|
||||
|
||||
fun testOneHasSourceAndManyDont() {
|
||||
fun testOneHasSourceAndManyDoNot() {
|
||||
doTestSameJarSharedByLibrariesWithAndWithoutSourceAttached(
|
||||
withSource = 1,
|
||||
noSource = 3
|
||||
withSource = 1,
|
||||
noSource = 3
|
||||
)
|
||||
}
|
||||
|
||||
fun testSeveralWithSource() {
|
||||
doTestSameJarSharedByLibrariesWithAndWithoutSourceAttached(
|
||||
withSource = 2,
|
||||
noSource = 2
|
||||
withSource = 2,
|
||||
noSource = 2
|
||||
)
|
||||
}
|
||||
|
||||
fun doTestSameJarSharedByLibrariesWithAndWithoutSourceAttached(withSource: Int, noSource: Int) {
|
||||
private fun doTestSameJarSharedByLibrariesWithAndWithoutSourceAttached(withSource: Int, noSource: Int) {
|
||||
val srcPath = testDataPath + "src"
|
||||
|
||||
val sharedJar = MockLibraryUtil.compileJvmLibraryToJar(testDataPath + "libSrc", "sharedJar", addSources = true)
|
||||
val jarRoot = sharedJar.jarRoot
|
||||
|
||||
var i: Int = 0
|
||||
var i = 0
|
||||
repeat(noSource) {
|
||||
module("m${++i}", srcPath).addDependency(projectLibrary("libA", jarRoot))
|
||||
}
|
||||
@@ -58,5 +58,5 @@ class GotoWithMultipleLibrariesTest : AbstractMultiModuleTest() {
|
||||
}
|
||||
}
|
||||
|
||||
protected fun module(name: String, srcPath: String) = createModuleFromTestData(srcPath, name, StdModuleTypes.JAVA, true)!!
|
||||
private fun module(name: String, srcPath: String) = createModuleFromTestData(srcPath, name, StdModuleTypes.JAVA, true)!!
|
||||
}
|
||||
|
||||
+17
-16
@@ -15,56 +15,56 @@ import org.jetbrains.kotlin.idea.test.PluginTestCaseBase;
|
||||
import java.io.File;
|
||||
|
||||
public class KotlinGotoImplementationMultifileTest extends KotlinLightCodeInsightFixtureTestCase {
|
||||
public void testImplementFunInJava() throws Exception {
|
||||
public void testImplementFunInJava() {
|
||||
doKotlinJavaTest();
|
||||
}
|
||||
|
||||
public void testImplementKotlinClassInJava() throws Exception {
|
||||
public void testImplementKotlinClassInJava() {
|
||||
doKotlinJavaTest();
|
||||
}
|
||||
|
||||
public void testImplementKotlinAbstractClassInJava() throws Exception {
|
||||
public void testImplementKotlinAbstractClassInJava() {
|
||||
doKotlinJavaTest();
|
||||
}
|
||||
|
||||
public void testImplementKotlinTraitInJava() throws Exception {
|
||||
public void testImplementKotlinTraitInJava() {
|
||||
doKotlinJavaTest();
|
||||
}
|
||||
|
||||
public void testImplementJavaClassInKotlin() throws Exception {
|
||||
public void testImplementJavaClassInKotlin() {
|
||||
doKotlinJavaTest();
|
||||
}
|
||||
|
||||
public void testImplementJavaAbstractClassInKotlin() throws Exception {
|
||||
public void testImplementJavaAbstractClassInKotlin() {
|
||||
doKotlinJavaTest();
|
||||
}
|
||||
|
||||
public void testImplementJavaInterfaceInKotlin() throws Exception {
|
||||
public void testImplementJavaInterfaceInKotlin() {
|
||||
doKotlinJavaTest();
|
||||
}
|
||||
|
||||
public void testImplementMethodInKotlin() throws Exception {
|
||||
public void testImplementMethodInKotlin() {
|
||||
doKotlinJavaTest();
|
||||
}
|
||||
|
||||
public void testImplementVarInJava() throws Exception {
|
||||
public void testImplementVarInJava() {
|
||||
doKotlinJavaTest();
|
||||
}
|
||||
|
||||
public void testImplementJavaInnerInterface() throws Exception {
|
||||
public void testImplementJavaInnerInterface() {
|
||||
doJavaKotlinTest();
|
||||
}
|
||||
|
||||
public void testImplementJavaInnerInterfaceFromUsage() throws Exception {
|
||||
public void testImplementJavaInnerInterfaceFromUsage() {
|
||||
doJavaKotlinTest();
|
||||
}
|
||||
|
||||
private void doKotlinJavaTest() throws Exception {
|
||||
doMultifileTest(getTestName(false) + ".kt", getTestName(false) + ".java");
|
||||
private void doKotlinJavaTest() {
|
||||
doMultiFileTest(getTestName(false) + ".kt", getTestName(false) + ".java");
|
||||
}
|
||||
|
||||
private void doJavaKotlinTest() throws Exception {
|
||||
doMultifileTest(getTestName(false) + ".java", getTestName(false) + ".kt");
|
||||
private void doJavaKotlinTest() {
|
||||
doMultiFileTest(getTestName(false) + ".java", getTestName(false) + ".kt");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -73,12 +73,13 @@ public class KotlinGotoImplementationMultifileTest extends KotlinLightCodeInsigh
|
||||
return KotlinLightProjectDescriptor.INSTANCE;
|
||||
}
|
||||
|
||||
private void doMultifileTest(String ... fileNames) throws Exception {
|
||||
private void doMultiFileTest(String... fileNames) {
|
||||
myFixture.configureByFiles(fileNames);
|
||||
GotoTargetHandler.GotoData gotoData = NavigationTestUtils.invokeGotoImplementations(getEditor(), getFile());
|
||||
NavigationTestUtils.assertGotoDataMatching(getEditor(), gotoData);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return new File(PluginTestCaseBase.getTestDataPathBase(),
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.navigation;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Ordering;
|
||||
import com.intellij.codeInsight.navigation.GotoTargetHandler;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
@@ -17,20 +15,20 @@ import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiFileSystemItem;
|
||||
import com.intellij.testFramework.UsefulTestCase;
|
||||
import com.intellij.testFramework.fixtures.CodeInsightTestUtil;
|
||||
import com.intellij.util.PathUtil;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import junit.framework.TestCase;
|
||||
import kotlin.collections.ArraysKt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.asJava.LightClassUtilsKt;
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils;
|
||||
import org.jetbrains.kotlin.test.util.ReferenceUtils;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class NavigationTestUtils {
|
||||
private NavigationTestUtils() {
|
||||
@@ -62,18 +60,16 @@ public final class NavigationTestUtils {
|
||||
if (gotoData != null) {
|
||||
List<PsiElement> targets;
|
||||
if (InTextDirectivesUtils.isDirectiveDefined(documentText, "// DISTINCT_REF")) {
|
||||
targets = ArraysKt.distinctBy(gotoData.targets, element -> LightClassUtilsKt.getUnwrapped(element));
|
||||
} else {
|
||||
targets = ArraysKt.distinctBy(gotoData.targets, LightClassUtilsKt::getUnwrapped);
|
||||
}
|
||||
else {
|
||||
targets = Arrays.asList(gotoData.targets);
|
||||
}
|
||||
// Transform given reference result to strings
|
||||
List<String> psiElements = Lists.transform(targets, new Function<PsiElement, String>() {
|
||||
@Override
|
||||
public String apply(@Nullable PsiElement element) {
|
||||
Assert.assertNotNull(element);
|
||||
return ReferenceUtils.renderAsGotoImplementation(element, renderModule);
|
||||
}
|
||||
});
|
||||
List<String> psiElements = targets.stream().map(element -> {
|
||||
Assert.assertNotNull(element);
|
||||
return ReferenceUtils.renderAsGotoImplementation(element, renderModule);
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
// Compare
|
||||
UsefulTestCase.assertOrderedEquals(Ordering.natural().sortedCopy(psiElements), expectedReferences);
|
||||
@@ -84,10 +80,10 @@ public final class NavigationTestUtils {
|
||||
}
|
||||
|
||||
public static String getNavigateElementsText(Project project, Collection<? extends PsiElement> navigableElements) {
|
||||
MultiMap<PsiFile, Pair<Integer, Integer>> filesToNumbersAndOffsets = new MultiMap<PsiFile, Pair<Integer, Integer>>();
|
||||
MultiMap<PsiFile, Pair<Integer, Integer>> filesToNumbersAndOffsets = new MultiMap<>();
|
||||
int refNumber = 1;
|
||||
for (PsiElement navigationElement : navigableElements) {
|
||||
Pair<Integer, Integer> numberAndOffset = new Pair<Integer, Integer>(refNumber++, navigationElement.getTextOffset());
|
||||
Pair<Integer, Integer> numberAndOffset = new Pair<>(refNumber++, navigationElement.getTextOffset());
|
||||
filesToNumbersAndOffsets.putValue(navigationElement.getContainingFile(), numberAndOffset);
|
||||
}
|
||||
|
||||
@@ -95,25 +91,15 @@ public final class NavigationTestUtils {
|
||||
return "<no references>";
|
||||
}
|
||||
|
||||
List<PsiFile> files = new ArrayList<PsiFile>(filesToNumbersAndOffsets.keySet());
|
||||
Collections.sort(files, new Comparator<PsiFile>() {
|
||||
@Override
|
||||
public int compare(@NotNull PsiFile f1, @NotNull PsiFile f2) {
|
||||
return f1.getName().compareTo(f2.getName());
|
||||
}
|
||||
});
|
||||
List<PsiFile> files = new ArrayList<>(filesToNumbersAndOffsets.keySet());
|
||||
files.sort(Comparator.comparing(PsiFileSystemItem::getName));
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (PsiFile file : files) {
|
||||
List<Pair<Integer, Integer>> numbersAndOffsets = new ArrayList<Pair<Integer, Integer>>(filesToNumbersAndOffsets.get(file));
|
||||
List<Pair<Integer, Integer>> numbersAndOffsets = new ArrayList<>(filesToNumbersAndOffsets.get(file));
|
||||
|
||||
Collections.sort(numbersAndOffsets, Collections.reverseOrder(new Comparator<Pair<Integer, Integer>>() {
|
||||
@Override
|
||||
public int compare(Pair<Integer, Integer> t1, Pair<Integer, Integer> t2) {
|
||||
int offsets = t1.second.compareTo(t2.second);
|
||||
return offsets == 0 ? t1.first.compareTo(t2.first) : offsets;
|
||||
}
|
||||
}));
|
||||
numbersAndOffsets.sort(Collections.reverseOrder(
|
||||
Comparator.comparingInt((Pair<Integer, Integer> t) -> t.second).thenComparingInt(t -> t.first)));
|
||||
|
||||
Document document = PsiDocumentManager.getInstance(project).getDocument(file);
|
||||
TestCase.assertNotNull(document);
|
||||
@@ -132,7 +118,7 @@ public final class NavigationTestUtils {
|
||||
|
||||
Document annotated = EditorFactory.getInstance().createDocument(resultForFile);
|
||||
String filePart = annotated.getText().substring(annotated.getLineStartOffset(minLine),
|
||||
annotated.getLineEndOffset(maxLine));
|
||||
annotated.getLineEndOffset(maxLine));
|
||||
result.append(" ").append(file.getName()).append("\n");
|
||||
result.append(filePart).append("\n");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user