FIR IDE: ignore attributes in completion tests

This commit is contained in:
Ilya Kirillov
2021-06-09 13:11:09 +02:00
committed by teamcityserver
parent 72e26771d8
commit 167917cf07
21 changed files with 34 additions and 7 deletions
@@ -1,3 +1,4 @@
// FIR_COMPARISON
fun String?.forNullableString(){} fun String?.forNullableString(){}
fun Any?.forNullableAny(){} fun Any?.forNullableAny(){}
fun String.forString(){} fun String.forString(){}
@@ -1,3 +1,4 @@
// FIR_COMPARISON
interface T1 { interface T1 {
fun inT1(){} fun inT1(){}
} }
@@ -1,3 +1,4 @@
// FIR_COMPARISON
fun String.extFunForString(){} fun String.extFunForString(){}
fun Any.extFunForAny(){} fun Any.extFunForAny(){}
fun String?.extFunForStringNullable(){} fun String?.extFunForStringNullable(){}
@@ -1,3 +1,4 @@
// FIR_COMPARISON
fun String.extFunForString(){} fun String.extFunForString(){}
fun Any.extFunForAny(){} fun Any.extFunForAny(){}
fun String?.extFunForStringNullable(){} fun String?.extFunForStringNullable(){}
@@ -1,3 +1,4 @@
// FIR_COMPARISON
fun <T> List<T>.forListT(){} fun <T> List<T>.forListT(){}
fun <T> Collection<T>.forCollectionT(){} fun <T> Collection<T>.forCollectionT(){}
fun <T> T.forT() {} fun <T> T.forT() {}
@@ -1,3 +1,4 @@
// FIR_COMPARISON
interface T { interface T {
fun fromTrait(){} fun fromTrait(){}
} }
@@ -1,3 +1,4 @@
// FIR_COMPARISON
interface T { interface T {
fun fromTrait(){} fun fromTrait(){}
} }
@@ -1,3 +1,4 @@
// FIR_COMPARISON
interface T { interface T {
fun f(){} fun f(){}
} }
@@ -1,3 +1,4 @@
// FIR_COMPARISON
fun globalFun(){} fun globalFun(){}
interface T { interface T {
@@ -1,3 +1,4 @@
// FIR_COMPARISON
interface R<T> interface R<T>
val <T> R<T>.prop: Int get() = TODO() val <T> R<T>.prop: Int get() = TODO()
@@ -1,3 +1,4 @@
// FIR_COMPARISON
// COMPILER_ARGUMENTS: -XXLanguage:-NewInference // COMPILER_ARGUMENTS: -XXLanguage:-NewInference
fun String.forString(){} fun String.forString(){}
@@ -1,3 +1,4 @@
// FIR_COMPARISON
// COMPILER_ARGUMENTS: -XXLanguage:-NewInference // COMPILER_ARGUMENTS: -XXLanguage:-NewInference
interface A { interface A {
@@ -1,3 +1,4 @@
// FIR_COMPARISON
interface Base { interface Base {
fun inBase() fun inBase()
} }
@@ -1,3 +1,4 @@
// FIR_COMPARISON
@DslMarker @DslMarker
annotation class SimpleDsl annotation class SimpleDsl
@@ -1,3 +1,4 @@
// FIR_COMPARISON
@DslMarker @DslMarker
annotation class SimpleDsl annotation class SimpleDsl
@@ -1,3 +1,4 @@
// FIR_COMPARISON
fun foo(param: String) { fun foo(param: String) {
val s = "$param.<caret>bla-bla-bla" val s = "$param.<caret>bla-bla-bla"
} }
@@ -1,3 +1,4 @@
// FIR_COMPARISON
fun String.extFunForString(){} fun String.extFunForString(){}
fun Any.extFunForAny(){} fun Any.extFunForAny(){}
fun String?.extFunForStringNullable(){} fun String?.extFunForStringNullable(){}
@@ -22,6 +22,7 @@ fun testCompletion(
complete: (CompletionType, Int) -> Array<LookupElement>?, complete: (CompletionType, Int) -> Array<LookupElement>?,
defaultCompletionType: CompletionType = CompletionType.BASIC, defaultCompletionType: CompletionType = CompletionType.BASIC,
defaultInvocationCount: Int = 0, defaultInvocationCount: Int = 0,
ignoreProperties: Collection<String> = emptyList(),
additionalValidDirectives: Collection<String> = emptyList() additionalValidDirectives: Collection<String> = emptyList()
) { ) {
testWithAutoCompleteSetting(fileText) { testWithAutoCompleteSetting(fileText) {
@@ -40,8 +41,8 @@ fun testCompletion(
"Should be some assertions about completion", "Should be some assertions about completion",
expected.size != 0 || unexpected.size != 0 || itemsNumber != null || nothingElse expected.size != 0 || unexpected.size != 0 || itemsNumber != null || nothingElse
) )
ExpectedCompletionUtils.assertContainsRenderedItems(expected, items, ExpectedCompletionUtils.isWithOrder(fileText), nothingElse) ExpectedCompletionUtils.assertContainsRenderedItems(expected, items, ExpectedCompletionUtils.isWithOrder(fileText), nothingElse, ignoreProperties)
ExpectedCompletionUtils.assertNotContainsRenderedItems(unexpected, items) ExpectedCompletionUtils.assertNotContainsRenderedItems(unexpected, items, ignoreProperties)
if (itemsNumber != null) { if (itemsNumber != null) {
val expectedItems = ExpectedCompletionUtils.listToString(ExpectedCompletionUtils.getItemsInformation(items)) val expectedItems = ExpectedCompletionUtils.listToString(ExpectedCompletionUtils.getItemsInformation(items))
@@ -64,9 +64,10 @@ object ExpectedCompletionUtils {
} }
} }
fun matches(expectedProposal: CompletionProposal): Boolean { fun matches(expectedProposal: CompletionProposal, ignoreProperties: Collection<String>): Boolean {
return expectedProposal.map.entries.none { expected -> return expectedProposal.map.entries.none { expected ->
val actualValues = when (expected.key) { val actualValues = when (expected.key) {
in ignoreProperties -> return@none false
"lookupString" -> { "lookupString" -> {
// FIR IDE adds `.` after package names in completion // FIR IDE adds `.` after package names in completion
listOf(map[expected.key]?.removeSuffix("."), map[expected.key]) listOf(map[expected.key]?.removeSuffix("."), map[expected.key])
@@ -223,7 +224,8 @@ object ExpectedCompletionUtils {
expected: Array<CompletionProposal>, expected: Array<CompletionProposal>,
items: Array<LookupElement>, items: Array<LookupElement>,
checkOrder: Boolean, checkOrder: Boolean,
nothingElse: Boolean nothingElse: Boolean,
ignoreProperties: Collection<String>,
) { ) {
val itemsInformation = getItemsInformation(items) val itemsInformation = getItemsInformation(items)
val allItemsString = listToString(itemsInformation) val allItemsString = listToString(itemsInformation)
@@ -238,7 +240,7 @@ object ExpectedCompletionUtils {
for (index in itemsInformation.indices) { for (index in itemsInformation.indices) {
val proposal = itemsInformation[index] val proposal = itemsInformation[index]
if (proposal.matches(expectedProposal)) { if (proposal.matches(expectedProposal, ignoreProperties)) {
isFound = true isFound = true
Assert.assertTrue( Assert.assertTrue(
@@ -280,7 +282,7 @@ object ExpectedCompletionUtils {
return InTextDirectivesUtils.getPrefixedInt(fileText, NUMBER_LINE_PREFIX) return InTextDirectivesUtils.getPrefixedInt(fileText, NUMBER_LINE_PREFIX)
} }
fun assertNotContainsRenderedItems(unexpected: Array<CompletionProposal>, items: Array<LookupElement>) { fun assertNotContainsRenderedItems(unexpected: Array<CompletionProposal>, items: Array<LookupElement>, ignoreProperties: Collection<String>) {
val itemsInformation = getItemsInformation(items) val itemsInformation = getItemsInformation(items)
val allItemsString = listToString(itemsInformation) val allItemsString = listToString(itemsInformation)
@@ -288,7 +290,7 @@ object ExpectedCompletionUtils {
for (proposal in itemsInformation) { for (proposal in itemsInformation) {
Assert.assertFalse( Assert.assertFalse(
"Unexpected '$unexpectedProposal' presented in\n$allItemsString", "Unexpected '$unexpectedProposal' presented in\n$allItemsString",
proposal.matches(unexpectedProposal) proposal.matches(unexpectedProposal, ignoreProperties)
) )
} }
} }
@@ -46,6 +46,7 @@ abstract class KotlinFixtureCompletionBaseTestCase : KotlinLightCodeInsightFixtu
{ completionType, count -> complete(completionType, count) }, { completionType, count -> complete(completionType, count) },
defaultCompletionType(), defaultCompletionType(),
defaultInvocationCount(), defaultInvocationCount(),
ignoreProperties = ignoreProperties,
additionalValidDirectives = CompilerTestDirectives.ALL_COMPILER_TEST_DIRECTIVES + IgnoreTests.DIRECTIVES.FIR_IDENTICAL additionalValidDirectives = CompilerTestDirectives.ALL_COMPILER_TEST_DIRECTIVES + IgnoreTests.DIRECTIVES.FIR_IDENTICAL
) )
} }
@@ -55,6 +56,8 @@ abstract class KotlinFixtureCompletionBaseTestCase : KotlinLightCodeInsightFixtu
} }
} }
open val ignoreProperties: Collection<String> = emptyList()
protected open fun executeTest(test: () -> Unit) { protected open fun executeTest(test: () -> Unit) {
test() test()
} }
@@ -6,11 +6,15 @@
package org.jetbrains.kotlin.idea.fir.completion package org.jetbrains.kotlin.idea.fir.completion
import org.jetbrains.kotlin.idea.completion.test.AbstractJvmBasicCompletionTest import org.jetbrains.kotlin.idea.completion.test.AbstractJvmBasicCompletionTest
import org.jetbrains.kotlin.idea.completion.test.ExpectedCompletionUtils
import org.jetbrains.kotlin.test.utils.IgnoreTests import org.jetbrains.kotlin.test.utils.IgnoreTests
abstract class AbstractHighLevelJvmBasicCompletionTest : AbstractJvmBasicCompletionTest() { abstract class AbstractHighLevelJvmBasicCompletionTest : AbstractJvmBasicCompletionTest() {
override val captureExceptions: Boolean = false override val captureExceptions: Boolean = false
override val ignoreProperties: Collection<String> =
listOf(ExpectedCompletionUtils.CompletionProposal.PRESENTATION_TEXT_ATTRIBUTES)
override fun executeTest(test: () -> Unit) { override fun executeTest(test: () -> Unit) {
IgnoreTests.runTestIfEnabledByFileDirective(testDataFile().toPath(), IgnoreTests.DIRECTIVES.FIR_COMPARISON, ".after") { IgnoreTests.runTestIfEnabledByFileDirective(testDataFile().toPath(), IgnoreTests.DIRECTIVES.FIR_COMPARISON, ".after") {
super.executeTest(test) super.executeTest(test)