[LL FIR] add script tests for AbstractFileStructureTest

^KT-60728
This commit is contained in:
Dmitrii Gridin
2023-07-26 20:25:59 +02:00
committed by Space Team
parent c79bdd8ce3
commit 3ed5ccbb6f
28 changed files with 440 additions and 6 deletions
@@ -0,0 +1,11 @@
/* NonReanalyzableNonClassDeclarationStructureElement */class X {
var x: Int
get() = field
set(value) {
field = value
}
val y = 42
var z: Int = 15
}
@@ -0,0 +1,6 @@
/* NonReanalyzableNonClassDeclarationStructureElement */class A {
fun x() {
}
fun y(): Int = 10
}
@@ -0,0 +1,9 @@
/* NonReanalyzableNonClassDeclarationStructureElement */class A
(val a: Int)
{
constructor() : this(1) {
}
}
@@ -0,0 +1,16 @@
/* NonReanalyzableNonClassDeclarationStructureElement */class Foo {
@Suppress("") @MustBeDocumented
}
class Bar {
@Suppress("") @MustBeDocumented
}
class Outer {
class Inner {
@Suppress("") @MustBeDocumented
}
fun foo() {
class Local {
@Suppress("") @MustBeDocumented
}
}
}
@@ -0,0 +1,11 @@
/* NonReanalyzableNonClassDeclarationStructureElement */class A {
val a = run {
class X()
val y = 10
}
}
inline fun <R> run(block: () -> R): R {
return block()
}
@@ -0,0 +1,13 @@
/* NonReanalyzableNonClassDeclarationStructureElement */enum class A {
X,
Y,
Z
;
fun foo(){}
val x = 10
fun bar() = 10
}
@@ -0,0 +1,13 @@
/* NonReanalyzableNonClassDeclarationStructureElement */enum class A {
X {
fun localInX() = 1
},
Y {
override fun foo() {}
},
Z,
;
open fun foo() {}
}
@@ -0,0 +1,6 @@
/* NonReanalyzableNonClassDeclarationStructureElement */class A {
init {
val x = 10
class B
}
}
@@ -0,0 +1,9 @@
/* NonReanalyzableNonClassDeclarationStructureElement */fun a() {
class X
}
class Y {
fun b() {
class Z
}
}
@@ -0,0 +1,13 @@
/* NonReanalyzableNonClassDeclarationStructureElement */fun x() {
fun y() {
}
}
class A {
fun z() {
fun q() {
}
}
}
@@ -0,0 +1,15 @@
/* NonReanalyzableNonClassDeclarationStructureElement */fun foo() {
var x: Int
}
class A {
fun q() {
val y = 42
}
}
class B {
class C {
fun u() {
var z: Int = 15
}
}
}
@@ -0,0 +1,3 @@
/* NonReanalyzableNonClassDeclarationStructureElement */class A {
typealias X = Int
}
@@ -0,0 +1,16 @@
/* NonReanalyzableNonClassDeclarationStructureElement */class A {
class B {
fun x() {
}
class C {
}
}
class E {
}
fun y(): Int = 10
}
@@ -0,0 +1,13 @@
/* NonReanalyzableNonClassDeclarationStructureElement */var x: Int = 10
get() = field
set(value) {
field = value
}
class X {
var y: Int = 10
get() = field
set(value) {
field = value
}
}
@@ -0,0 +1,26 @@
/* NonReanalyzableNonClassDeclarationStructureElement */class Builder {
var version: String = ""
fun execute() {
println(version)
}
}
fun build(action: Builder.() -> Unit) = Builder().apply(action)
build {
version = "123"
class A {
fun doo() {
}
}
execute()
}
val builder = build {
version = "321"
}
builder.execute()
@@ -0,0 +1,35 @@
/* NonReanalyzableNonClassDeclarationStructureElement */open class A
(init: A.() -> Unit)
{
val prop: String = ""
}
class B() : A()
object C : A(
{
fun foo() = B.prop.toString()
}
) {
}
val f = object : A(
{
fun bar() = B.prop.toString()
}
) {
}
class D : A(
{
fun foo() = B.prop.toString()
}
) {
constructor(): super(
{
fun boo() = prop.toString()
}
)
}
@@ -0,0 +1 @@
/* NonReanalyzableNonClassDeclarationStructureElement */fun foo(): Int = 42
@@ -0,0 +1 @@
/* NonReanalyzableNonClassDeclarationStructureElement */fun foo() = 42
@@ -0,0 +1,4 @@
/* NonReanalyzableNonClassDeclarationStructureElement */fun foo(): Int {
println("")
return 10
}
@@ -0,0 +1,9 @@
/* NonReanalyzableNonClassDeclarationStructureElement */var x: Int
get() = field
set(value) {
field = value
}
val y = 42
var z: Int = 15
@@ -0,0 +1,3 @@
/* NonReanalyzableNonClassDeclarationStructureElement */fun foo() {
println("")
}
@@ -0,0 +1,29 @@
/* NonReanalyzableNonClassDeclarationStructureElement */fun (a: Int = 1): String = "str"
fun () {
}
val : Int = 4
var : Int
get() = 4
set(value) {
}
class A {
fun (a: Int = 1): String = "str"
fun () {
}
val : Int = 4
var : Boolean
get() = true
set(value) {
}
}
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.analysis.low.level.api.fir.isSourceSession
import org.jetbrains.kotlin.analysis.low.level.api.fir.sessions.LLFirResolvableModuleSession
import org.jetbrains.kotlin.analysis.low.level.api.fir.test.base.AbstractLowLevelApiSingleFileTest
import org.jetbrains.kotlin.analysis.low.level.api.fir.test.configurators.AnalysisApiFirOutOfContentRootTestConfigurator
import org.jetbrains.kotlin.analysis.low.level.api.fir.test.configurators.AnalysisApiFirScriptTestConfigurator
import org.jetbrains.kotlin.analysis.low.level.api.fir.test.configurators.AnalysisApiFirSourceTestConfigurator
import org.jetbrains.kotlin.analysis.project.structure.ProjectStructureProvider
import org.jetbrains.kotlin.psi.*
@@ -66,6 +67,9 @@ abstract class AbstractFileStructureTest : AbstractLowLevelApiSingleFileTest() {
is KtClassInitializer -> {
elementToComment[ktDeclaration.openBraceNode!!] = comment
}
is KtScript -> {
elementToComment[ktFile.importList!!] = comment
}
else -> error("Unsupported declaration $ktDeclaration")
}
}
@@ -121,5 +125,9 @@ abstract class AbstractSourceFileStructureTest : AbstractFileStructureTest() {
}
abstract class AbstractOutOfContentRootFileStructureTest : AbstractFileStructureTest() {
override val configurator = AnalysisApiFirOutOfContentRootTestConfigurator
override val configurator get() = AnalysisApiFirOutOfContentRootTestConfigurator
}
abstract class AbstractScriptFileStructureTest : AbstractFileStructureTest() {
override val configurator get() = AnalysisApiFirScriptTestConfigurator
}
@@ -21,7 +21,7 @@ import java.util.regex.Pattern;
public class OutOfContentRootFileStructureTestGenerated extends AbstractOutOfContentRootFileStructureTest {
@Test
public void testAllFilesPresentInFileStructure() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/low-level-api-fir/testdata/fileStructure"), Pattern.compile("^(.+)\\.kt$"), null, true);
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/low-level-api-fir/testdata/fileStructure"), Pattern.compile("^(.+)\\.(kt)$"), null, true);
}
@Test
@@ -0,0 +1,158 @@
/*
* 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.file.structure;
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/fileStructure")
@TestDataPath("$PROJECT_ROOT")
public class ScriptFileStructureTestGenerated extends AbstractScriptFileStructureTest {
@Test
public void testAllFilesPresentInFileStructure() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/low-level-api-fir/testdata/fileStructure"), Pattern.compile("^(.+)\\.(kts)$"), null, true);
}
@Test
@TestMetadata("classMemberPropertyScript.kts")
public void testClassMemberPropertyScript() throws Exception {
runTest("analysis/low-level-api-fir/testdata/fileStructure/classMemberPropertyScript.kts");
}
@Test
@TestMetadata("classScript.kts")
public void testClassScript() throws Exception {
runTest("analysis/low-level-api-fir/testdata/fileStructure/classScript.kts");
}
@Test
@TestMetadata("constructorsScript.kts")
public void testConstructorsScript() throws Exception {
runTest("analysis/low-level-api-fir/testdata/fileStructure/constructorsScript.kts");
}
@Test
@TestMetadata("danglingAnnotationClassLevelScript.kts")
public void testDanglingAnnotationClassLevelScript() throws Exception {
runTest("analysis/low-level-api-fir/testdata/fileStructure/danglingAnnotationClassLevelScript.kts");
}
@Test
@TestMetadata("declarationsInPropertyInitScript.kts")
public void testDeclarationsInPropertyInitScript() throws Exception {
runTest("analysis/low-level-api-fir/testdata/fileStructure/declarationsInPropertyInitScript.kts");
}
@Test
@TestMetadata("enumClassScript.kts")
public void testEnumClassScript() throws Exception {
runTest("analysis/low-level-api-fir/testdata/fileStructure/enumClassScript.kts");
}
@Test
@TestMetadata("enumClassWithBodyScript.kts")
public void testEnumClassWithBodyScript() throws Exception {
runTest("analysis/low-level-api-fir/testdata/fileStructure/enumClassWithBodyScript.kts");
}
@Test
@TestMetadata("initBlockScript.kts")
public void testInitBlockScript() throws Exception {
runTest("analysis/low-level-api-fir/testdata/fileStructure/initBlockScript.kts");
}
@Test
@TestMetadata("localClassScript.kts")
public void testLocalClassScript() throws Exception {
runTest("analysis/low-level-api-fir/testdata/fileStructure/localClassScript.kts");
}
@Test
@TestMetadata("localFunScript.kts")
public void testLocalFunScript() throws Exception {
runTest("analysis/low-level-api-fir/testdata/fileStructure/localFunScript.kts");
}
@Test
@TestMetadata("localPropertyScript.kts")
public void testLocalPropertyScript() throws Exception {
runTest("analysis/low-level-api-fir/testdata/fileStructure/localPropertyScript.kts");
}
@Test
@TestMetadata("memberTypeAliasScript.kts")
public void testMemberTypeAliasScript() throws Exception {
runTest("analysis/low-level-api-fir/testdata/fileStructure/memberTypeAliasScript.kts");
}
@Test
@TestMetadata("nestedClassesScript.kts")
public void testNestedClassesScript() throws Exception {
runTest("analysis/low-level-api-fir/testdata/fileStructure/nestedClassesScript.kts");
}
@Test
@TestMetadata("propertyAccessorsScript.kts")
public void testPropertyAccessorsScript() throws Exception {
runTest("analysis/low-level-api-fir/testdata/fileStructure/propertyAccessorsScript.kts");
}
@Test
@TestMetadata("script.kts")
public void testScript() throws Exception {
runTest("analysis/low-level-api-fir/testdata/fileStructure/script.kts");
}
@Test
@TestMetadata("superClassCallScript.kts")
public void testSuperClassCallScript() throws Exception {
runTest("analysis/low-level-api-fir/testdata/fileStructure/superClassCallScript.kts");
}
@Test
@TestMetadata("topLevelExpressionBodyFunWithTypeScript.kts")
public void testTopLevelExpressionBodyFunWithTypeScript() throws Exception {
runTest("analysis/low-level-api-fir/testdata/fileStructure/topLevelExpressionBodyFunWithTypeScript.kts");
}
@Test
@TestMetadata("topLevelExpressionBodyFunWithoutTypeScript.kts")
public void testTopLevelExpressionBodyFunWithoutTypeScript() throws Exception {
runTest("analysis/low-level-api-fir/testdata/fileStructure/topLevelExpressionBodyFunWithoutTypeScript.kts");
}
@Test
@TestMetadata("topLevelFunWithTypeScript.kts")
public void testTopLevelFunWithTypeScript() throws Exception {
runTest("analysis/low-level-api-fir/testdata/fileStructure/topLevelFunWithTypeScript.kts");
}
@Test
@TestMetadata("topLevelPropertyScript.kts")
public void testTopLevelPropertyScript() throws Exception {
runTest("analysis/low-level-api-fir/testdata/fileStructure/topLevelPropertyScript.kts");
}
@Test
@TestMetadata("topLevelUnitFunScript.kts")
public void testTopLevelUnitFunScript() throws Exception {
runTest("analysis/low-level-api-fir/testdata/fileStructure/topLevelUnitFunScript.kts");
}
@Test
@TestMetadata("withoutNameScript.kts")
public void testWithoutNameScript() throws Exception {
runTest("analysis/low-level-api-fir/testdata/fileStructure/withoutNameScript.kts");
}
}
@@ -21,7 +21,7 @@ import java.util.regex.Pattern;
public class SourceFileStructureTestGenerated extends AbstractSourceFileStructureTest {
@Test
public void testAllFilesPresentInFileStructure() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/low-level-api-fir/testdata/fileStructure"), Pattern.compile("^(.+)\\.kt$"), null, true);
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/low-level-api-fir/testdata/fileStructure"), Pattern.compile("^(.+)\\.(kt)$"), null, true);
}
@Test
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.analysis.low.level.api.fir
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.LLFirResolveSession
import org.jetbrains.kotlin.analysis.low.level.api.fir.sessions.LLFirSessionConfigurator
import org.jetbrains.kotlin.analysis.low.level.api.fir.state.LLFirNotUnderContentRootResolveSession
import org.jetbrains.kotlin.analysis.low.level.api.fir.state.LLFirScriptResolveSession
import org.jetbrains.kotlin.analysis.low.level.api.fir.state.LLFirSourceResolveSession
import org.jetbrains.kotlin.analysis.project.structure.ProjectStructureProvider
import org.jetbrains.kotlin.analysis.test.framework.services.environmentManager
@@ -55,7 +56,7 @@ internal inline fun <R> resolveWithCaches(context: KtElement, action: (LLFirReso
internal val LLFirResolveSession.isSourceSession: Boolean
get() {
return when (this) {
is LLFirSourceResolveSession, is LLFirNotUnderContentRootResolveSession -> true
is LLFirSourceResolveSession, is LLFirNotUnderContentRootResolveSession, is LLFirScriptResolveSession -> true
else -> false
}
}
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.analysis.low.level.api.fir.diagnostic.compiler.based
import org.jetbrains.kotlin.analysis.low.level.api.fir.diagnostic.compiler.based.AbstractLLFirPreresolvedReversedDiagnosticCompilerTestDataTest
import org.jetbrains.kotlin.analysis.low.level.api.fir.file.structure.AbstractOutOfContentRootFileStructureTest
import org.jetbrains.kotlin.analysis.low.level.api.fir.file.structure.AbstractOutOfContentRootInBlockModificationTest
import org.jetbrains.kotlin.analysis.low.level.api.fir.file.structure.AbstractScriptFileStructureTest
import org.jetbrains.kotlin.analysis.low.level.api.fir.file.structure.AbstractSourceFileStructureTest
import org.jetbrains.kotlin.analysis.low.level.api.fir.file.structure.AbstractSourceInBlockModificationTest
import org.jetbrains.kotlin.analysis.low.level.api.fir.resolve.AbstractErrorResistanceTest
@@ -68,11 +69,15 @@ internal fun TestGroupSuite.generateFirLowLevelApiTests() {
}
testClass<AbstractSourceFileStructureTest> {
model("fileStructure")
model("fileStructure", pattern = TestGeneratorUtil.KT)
}
testClass<AbstractOutOfContentRootFileStructureTest> {
model("fileStructure")
model("fileStructure", pattern = TestGeneratorUtil.KT)
}
testClass<AbstractScriptFileStructureTest> {
model("fileStructure", pattern = TestGeneratorUtil.KTS)
}
testClass<AbstractFirSourceContextCollectionTest> {