[LL FIR] add tests on ClassIdCalculator

This commit is contained in:
Dmitrii Gridin
2023-06-17 13:33:59 +02:00
parent fc7712148e
commit 72c625906f
7 changed files with 157 additions and 0 deletions
@@ -0,0 +1,24 @@
package one
/* ClassId: one/TopLevelObject */object TopLevelObject
/* ClassId: one/A */class A constructor(a: Int) {
/* ClassId: one/A.B */class B {
/* ClassId: one/A.B.C */inner class C {
fun foo() {
/* ClassId: null */typealias F = C
/* ClassId: null */class BBA
}
}
}
fun boo() {
/* ClassId: null */class A
/* ClassId: null */typealias B = A
}
/* ClassId: one/A.NestedTypeAlias */typealias NestedTypeAlias = B
}
/* ClassId: one/TopLevelAlias */typealias TopLevelAlias
@@ -0,0 +1,7 @@
package one
/* ClassId: one/ClassWithParameter */open class ClassWithParameter(i: () -> Unit)
/* ClassId: one/TopLevelClass */class TopLevelClass : ClassWithParameter({
/* ClassId: null */class LocalClass
})
@@ -0,0 +1,10 @@
package one
/* ClassId: one/ClassWithParameter */open class ClassWithParameter(s: String)
/* ClassId: one/TopLevelClass */class TopLevelClass : ClassWithParameter("${
{
/* ClassId: null */class F
F()
}()
}")
@@ -0,0 +1,11 @@
package one
/* ClassId: one/Interface */interface Interface {
fun foo(param: String)
}
/* ClassId: one/ClassWithParameter */open class ClassWithParameter(i: Interface)
/* ClassId: one/TopLevelClass */class TopLevelClass : ClassWithParameter(/* ClassId: null */object : Interface {
/* ClassId: null */class NestedClassFromAnonymousObject
})
@@ -0,0 +1,51 @@
/*
* Copyright 2010-2023 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.low.level.api.fir
import com.intellij.psi.PsiComment
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiElementVisitor
import com.intellij.psi.impl.source.tree.LeafPsiElement
import org.jetbrains.kotlin.analysis.low.level.api.fir.element.builder.getNonLocalContainingOrThisDeclaration
import org.jetbrains.kotlin.analysis.low.level.api.fir.test.base.AbstractLowLevelApiSingleFileTest
import org.jetbrains.kotlin.analysis.low.level.api.fir.test.configurators.AnalysisApiFirSourceTestConfigurator
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.AnalysisApiTestConfigurator
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.psi.KtClassLikeDeclaration
import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.psiUtil.forEachDescendantOfType
import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder
import org.jetbrains.kotlin.test.directives.ConfigurationDirectives
import org.jetbrains.kotlin.test.services.TestModuleStructure
import org.jetbrains.kotlin.test.services.TestServices
import org.jetbrains.kotlin.test.services.assertions
abstract class AbstractClassIdTest : AbstractLowLevelApiSingleFileTest() {
override val configurator: AnalysisApiTestConfigurator = AnalysisApiFirSourceTestConfigurator(analyseInDependentSession = false)
override fun doTestByFileStructure(ktFile: KtFile, moduleStructure: TestModuleStructure, testServices: TestServices) {
val text = buildString {
ktFile.accept(object : PsiElementVisitor() {
override fun visitElement(element: PsiElement) {
if (element is KtClassLikeDeclaration) {
append("/* ClassId: ${element.getClassId()} */")
}
if (element is LeafPsiElement) {
append(element.text)
}
element.acceptChildren(this)
}
override fun visitComment(comment: PsiComment) {}
})
}
testServices.assertions.assertEqualsToTestDataFileSibling(text, ".kt")
}
}
@@ -0,0 +1,50 @@
/*
* Copyright 2010-2023 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.low.level.api.fir;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.util.KtTestUtil;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.analysis.api.GenerateAnalysisApiTestsKt}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("analysis/low-level-api-fir/testdata/classId")
@TestDataPath("$PROJECT_ROOT")
public class ClassIdTestGenerated extends AbstractClassIdTest {
@Test
public void testAllFilesPresentInClassId() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/low-level-api-fir/testdata/classId"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@Test
@TestMetadata("classWithMembers.kt")
public void testClassWithMembers() throws Exception {
runTest("analysis/low-level-api-fir/testdata/classId/classWithMembers.kt");
}
@Test
@TestMetadata("localClassInsideFunctionLiteral.kt")
public void testLocalClassInsideFunctionLiteral() throws Exception {
runTest("analysis/low-level-api-fir/testdata/classId/localClassInsideFunctionLiteral.kt");
}
@Test
@TestMetadata("localClassInsideLambdaCallInsideStringTemplate.kt")
public void testLocalClassInsideLambdaCallInsideStringTemplate() throws Exception {
runTest("analysis/low-level-api-fir/testdata/classId/localClassInsideLambdaCallInsideStringTemplate.kt");
}
@Test
@TestMetadata("localClassInsideSuperEntryCall.kt")
public void testLocalClassInsideSuperEntryCall() throws Exception {
runTest("analysis/low-level-api-fir/testdata/classId/localClassInsideSuperEntryCall.kt");
}
}
@@ -111,6 +111,10 @@ internal fun TestGroupSuite.generateFirLowLevelApiTests() {
testClass<AbstractFirNonLocalDeclarationAnchorTest> {
model("nonLocalDeclarationAnchors")
}
testClass<AbstractClassIdTest> {
model("classId")
}
}
testGroup(