diff --git a/compiler/util/build.gradle.kts b/compiler/util/build.gradle.kts index 8c46a6821b1..52159eb0af7 100644 --- a/compiler/util/build.gradle.kts +++ b/compiler/util/build.gradle.kts @@ -13,6 +13,9 @@ dependencies { compileOnly(commonDependency("org.jetbrains.intellij.deps:asm-all")) compileOnly(jpsModel()) { isTransitive = false } compileOnly(jpsModelImpl()) { isTransitive = false } + + testImplementation(projectTests(":compiler:tests-common")) + testImplementation(intellijCore()) } sourceSets { @@ -20,5 +23,13 @@ sourceSets { projectDefault() resources.srcDir(File(rootDir, "resources")) } - "test" {} + "test" { + projectDefault() + } } + +testsJar() + +projectTest(parallel = true) { + workingDir = rootDir +} \ No newline at end of file diff --git a/compiler/util/tests/org/jetbrains/kotlin/utils/GetElementWithContextTest.kt b/compiler/util/tests/org/jetbrains/kotlin/utils/GetElementWithContextTest.kt new file mode 100644 index 00000000000..7cbb7f819bf --- /dev/null +++ b/compiler/util/tests/org/jetbrains/kotlin/utils/GetElementWithContextTest.kt @@ -0,0 +1,40 @@ +/* + * 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.utils + +import org.jetbrains.kotlin.parsing.KotlinParserDefinition +import org.jetbrains.kotlin.psi.KtNamedFunction +import org.jetbrains.kotlin.psi.KtPsiFactory +import org.jetbrains.kotlin.test.testFramework.KtParsingTestCase +import org.jetbrains.kotlin.test.util.KtTestUtil + +class GetElementWithContextTest : KtParsingTestCase( + "", + "kt", + KotlinParserDefinition() +) { + + override fun getTestDataPath() = KtTestUtil.getHomeDirectory() + + fun testGetElementWithContext() { + val file = KtPsiFactory(myProject).createFile( + """ | + |fun foo() { + | println(1 + 1) + |} + """.trimMargin() + ) + val statement = + (file.declarations.first() as KtNamedFunction).bodyBlockExpression!!.statements.first() + val text = getElementTextWithContext(statement) + assertEquals( + """| + |fun foo() { + | println(1 + 1) + |} + """.trimMargin(), text) + } +} \ No newline at end of file