From 1e96088cc6d798ce1b5bb887244e8927a49cdacb Mon Sep 17 00:00:00 2001 From: Vladimir Dolzhenko Date: Fri, 21 Aug 2020 10:04:06 +0200 Subject: [PATCH] Check unique symbols in Goto*Tests --- .../gotoSymbol/privateTopLevelDeclarations.kt | 1 - .../org/jetbrains/kotlin/idea/navigation/GotoCheck.kt | 10 +++++++--- .../jetbrains/kotlin/idea/navigation/GotoCheck.kt.202 | 10 +++++++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/idea/testData/navigation/gotoSymbol/privateTopLevelDeclarations.kt b/idea/testData/navigation/gotoSymbol/privateTopLevelDeclarations.kt index 915d2b725e0..722606c1a24 100644 --- a/idea/testData/navigation/gotoSymbol/privateTopLevelDeclarations.kt +++ b/idea/testData/navigation/gotoSymbol/privateTopLevelDeclarations.kt @@ -15,5 +15,4 @@ private val test = 4 // REF: (for Int in privateTopLevelDeclarations.kt in foo.bar).test // REF: (for Int in privateTopLevelDeclarations.kt in foo.bar).test() // REF: (privateTopLevelDeclarations.kt in foo.bar).test -// REF: (privateTopLevelDeclarations.kt in foo.bar).test // REF: (privateTopLevelDeclarations.kt in foo.bar).test() \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/navigation/GotoCheck.kt b/idea/tests/org/jetbrains/kotlin/idea/navigation/GotoCheck.kt index 13219ed2208..a4d3b083838 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/navigation/GotoCheck.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/navigation/GotoCheck.kt @@ -14,6 +14,7 @@ import org.jetbrains.kotlin.test.InTextDirectivesUtils import org.jetbrains.kotlin.test.util.renderAsGotoImplementation import org.junit.Assert import kotlin.test.assertEquals +import kotlin.test.assertTrue object GotoCheck { @JvmStatic @@ -38,11 +39,11 @@ object GotoCheck { val searchText = searchTextList.first() val foundSymbols = model.getNames(includeNonProjectSymbols).filter { it?.startsWith(searchText) ?: false }.flatMap { - model.getElementsByName(it, includeNonProjectSymbols, "$it*").toSet() + model.getElementsByName(it, includeNonProjectSymbols, "$it*").toList() } val inexactMatching = InTextDirectivesUtils.isDirectiveDefined(documentText, "// ALLOW_MORE_RESULTS") - val renderedSymbols = foundSymbols.map { (it as PsiElement).renderAsGotoImplementation() } + val renderedSymbols = foundSymbols.map { (it as PsiElement).renderAsGotoImplementation() }.toSet() if (checkNavigation && (expectedReferences.size != 1 || inexactMatching)) { error("Cannot check navigation targets when multiple references are expected") @@ -55,7 +56,10 @@ object GotoCheck { } if (!checkNavigation) return - assertNavigationElementMatches(foundSymbols.single() as PsiElement, documentText) + assertTrue(foundSymbols.isNotEmpty()) + foundSymbols.forEach { + assertNavigationElementMatches(it as PsiElement, documentText) + } } @JvmStatic diff --git a/idea/tests/org/jetbrains/kotlin/idea/navigation/GotoCheck.kt.202 b/idea/tests/org/jetbrains/kotlin/idea/navigation/GotoCheck.kt.202 index 5fa4dc42fc6..ec02a18b6ae 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/navigation/GotoCheck.kt.202 +++ b/idea/tests/org/jetbrains/kotlin/idea/navigation/GotoCheck.kt.202 @@ -14,6 +14,7 @@ import org.jetbrains.kotlin.test.InTextDirectivesUtils import org.jetbrains.kotlin.test.util.renderAsGotoImplementation import org.junit.Assert import kotlin.test.assertEquals +import kotlin.test.assertTrue object GotoCheck { @JvmStatic @@ -38,11 +39,11 @@ object GotoCheck { val searchText = searchTextList.first() val foundSymbols = model.getNames(includeNonProjectSymbols).filter { it?.startsWith(searchText) ?: false }.flatMap { - model.getElementsByName(it, includeNonProjectSymbols, "$it*").toSet() + model.getElementsByName(it, includeNonProjectSymbols, "$it*").toList() } val inexactMatching = InTextDirectivesUtils.isDirectiveDefined(documentText, "// ALLOW_MORE_RESULTS") - val renderedSymbols = foundSymbols.map { (it as PsiElement).renderAsGotoImplementation() } + val renderedSymbols = foundSymbols.map { (it as PsiElement).renderAsGotoImplementation() }.toSet() if (checkNavigation && (expectedReferences.size != 1 || inexactMatching)) { error("Cannot check navigation targets when multiple references are expected") @@ -55,7 +56,10 @@ object GotoCheck { } if (!checkNavigation) return - assertNavigationElementMatches(foundSymbols.single() as PsiElement, documentText) + assertTrue(foundSymbols.isNotEmpty()) + foundSymbols.forEach { + assertNavigationElementMatches(it as PsiElement, documentText) + } } @JvmStatic