[AA] Add tests for getSealedInheritors

- Previously, the sealed inheritors provider was only tested indirectly
  through diagnostics tests on `when` expressions.

^KT-66013
This commit is contained in:
Marco Pennekamp
2024-02-29 18:52:29 +01:00
committed by Space Team
parent 1374bc8e2d
commit 5c8c3020c6
21 changed files with 577 additions and 0 deletions
@@ -0,0 +1,20 @@
/*
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.analysis.api.impl.base.test.cases.components.inheritorsProvider
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.KtPsiFactory
import org.jetbrains.kotlin.test.model.TestModule
import org.jetbrains.kotlin.test.services.TestServices
abstract class AbstractDanglingFileSealedInheritorsTest : AbstractSealedInheritorsTest() {
override fun doTestByMainFile(mainFile: KtFile, mainModule: TestModule, testServices: TestServices) {
val ktPsiFactory = KtPsiFactory.contextual(mainFile, markGenerated = true, eventSystemEnabled = false)
val fakeKtFile = ktPsiFactory.createFile("fake.kt", mainFile.text)
super.doTestByMainFile(fakeKtFile, mainModule, testServices)
}
}
@@ -0,0 +1,31 @@
/*
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.analysis.api.impl.base.test.cases.components.inheritorsProvider
import org.jetbrains.kotlin.analysis.api.impl.base.test.SymbolByFqName
import org.jetbrains.kotlin.analysis.api.symbols.KtNamedClassOrObjectSymbol
import org.jetbrains.kotlin.analysis.test.framework.base.AbstractAnalysisApiBasedTest
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.test.model.TestModule
import org.jetbrains.kotlin.test.services.TestServices
import org.jetbrains.kotlin.test.services.assertions
abstract class AbstractSealedInheritorsTest : AbstractAnalysisApiBasedTest() {
override fun doTestByMainFile(mainFile: KtFile, mainModule: TestModule, testServices: TestServices) {
analyseForTest(mainFile) {
val actualText = with(SymbolByFqName.getSymbolDataFromFile(testDataPath)) {
val classSymbol = toSymbols(mainFile).singleOrNull() as? KtNamedClassOrObjectSymbol
?: error("Expected a single named class to be specified.")
classSymbol.getSealedClassInheritors().joinToString("\n\n") { inheritor ->
"${inheritor.classIdIfNonLocal!!}\n${inheritor.render()}"
}
}
testServices.assertions.assertEqualsToTestDataFileSibling(actualText)
}
}
}