From ce10410aba9da599358c1f9c7c660bb39837aad9 Mon Sep 17 00:00:00 2001 From: Jinseong Jeon Date: Mon, 24 May 2021 23:48:11 -0700 Subject: [PATCH] FIR UAST: refactor FE1 UAST tests --- .../test/env/kotlin/AbstractFE1UastTest.kt | 24 +++++++++++++++++++ .../kotlin/AbstractFE1UastDeclarationTest.kt | 16 ++----------- .../kotlin/AbstractFE1UastIdentifiersTest.kt | 16 ++----------- .../test/kotlin/AbstractFE1UastTypesTest.kt | 16 ++----------- .../test/kotlin/AbstractFE1UastValuesTest.kt | 16 ++----------- 5 files changed, 32 insertions(+), 56 deletions(-) create mode 100644 plugins/uast-kotlin-fir/tests/org/jetbrains/uast/test/env/kotlin/AbstractFE1UastTest.kt diff --git a/plugins/uast-kotlin-fir/tests/org/jetbrains/uast/test/env/kotlin/AbstractFE1UastTest.kt b/plugins/uast-kotlin-fir/tests/org/jetbrains/uast/test/env/kotlin/AbstractFE1UastTest.kt new file mode 100644 index 00000000000..b51551a1298 --- /dev/null +++ b/plugins/uast-kotlin-fir/tests/org/jetbrains/uast/test/env/kotlin/AbstractFE1UastTest.kt @@ -0,0 +1,24 @@ +/* + * Copyright 2010-2021 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.uast.test.env.kotlin + +import org.jetbrains.uast.UFile +import org.jetbrains.uast.test.kotlin.AbstractKotlinUastTest +import java.io.File + +abstract class AbstractFE1UastTest : AbstractKotlinUastTest() { + override var testDataDir = File("plugins/uast-kotlin-fir/testData") + + fun doTest(filePath: String) { + testDataDir = File(filePath).parentFile + val testName = File(filePath).nameWithoutExtension + val virtualFile = getVirtualFile(testName) + + val psiFile = psiManager.findFile(virtualFile) ?: error("Can't get psi file for $testName") + val uFile = uastContext.convertElementWithParent(psiFile, null) ?: error("Can't get UFile for $testName") + check(filePath, uFile as UFile) + } +} diff --git a/plugins/uast-kotlin-fir/tests/org/jetbrains/uast/test/kotlin/AbstractFE1UastDeclarationTest.kt b/plugins/uast-kotlin-fir/tests/org/jetbrains/uast/test/kotlin/AbstractFE1UastDeclarationTest.kt index a179f5fb6cc..c221247ae42 100644 --- a/plugins/uast-kotlin-fir/tests/org/jetbrains/uast/test/kotlin/AbstractFE1UastDeclarationTest.kt +++ b/plugins/uast-kotlin-fir/tests/org/jetbrains/uast/test/kotlin/AbstractFE1UastDeclarationTest.kt @@ -7,24 +7,12 @@ package org.jetbrains.uast.test.kotlin import org.jetbrains.uast.UFile import org.jetbrains.uast.test.common.kotlin.FirUastRenderLogTestBase -import java.io.File +import org.jetbrains.uast.test.env.kotlin.AbstractFE1UastTest -abstract class AbstractFE1UastDeclarationTest : AbstractKotlinUastTest(), FirUastRenderLogTestBase { +abstract class AbstractFE1UastDeclarationTest : AbstractFE1UastTest(), FirUastRenderLogTestBase { override val isFirUastPlugin: Boolean = false override fun check(filePath: String, file: UFile) { super.check(filePath, file) } - - override var testDataDir = File("plugins/uast-kotlin-fir/testData") - - fun doTest(filePath: String) { - testDataDir = File(filePath).parentFile - val testName = filePath.substring(filePath.lastIndexOf('/') + 1).removeSuffix(".kt") - val virtualFile = getVirtualFile(testName) - - val psiFile = psiManager.findFile(virtualFile) ?: error("Can't get psi file for $testName") - val uFile = uastContext.convertElementWithParent(psiFile, null) ?: error("Can't get UFile for $testName") - check(filePath, uFile as UFile) - } } diff --git a/plugins/uast-kotlin-fir/tests/org/jetbrains/uast/test/kotlin/AbstractFE1UastIdentifiersTest.kt b/plugins/uast-kotlin-fir/tests/org/jetbrains/uast/test/kotlin/AbstractFE1UastIdentifiersTest.kt index 8a6a2013208..87447fad41f 100644 --- a/plugins/uast-kotlin-fir/tests/org/jetbrains/uast/test/kotlin/AbstractFE1UastIdentifiersTest.kt +++ b/plugins/uast-kotlin-fir/tests/org/jetbrains/uast/test/kotlin/AbstractFE1UastIdentifiersTest.kt @@ -7,24 +7,12 @@ package org.jetbrains.uast.test.kotlin import org.jetbrains.uast.UFile import org.jetbrains.uast.test.common.kotlin.FirUastIdentifiersTestBase -import java.io.File +import org.jetbrains.uast.test.env.kotlin.AbstractFE1UastTest -abstract class AbstractFE1UastIdentifiersTest : AbstractKotlinUastTest(), FirUastIdentifiersTestBase { +abstract class AbstractFE1UastIdentifiersTest : AbstractFE1UastTest(), FirUastIdentifiersTestBase { override val isFirUastPlugin: Boolean = false override fun check(filePath: String, file: UFile) { super.check(filePath, file) } - - override var testDataDir = File("plugins/uast-kotlin-fir/testData") - - fun doTest(filePath: String) { - testDataDir = File(filePath).parentFile - val testName = File(filePath).nameWithoutExtension - val virtualFile = getVirtualFile(testName) - - val psiFile = psiManager.findFile(virtualFile) ?: error("Can't get psi file for $testName") - val uFile = uastContext.convertElementWithParent(psiFile, null) ?: error("Can't get UFile for $testName") - check(filePath, uFile as UFile) - } } diff --git a/plugins/uast-kotlin-fir/tests/org/jetbrains/uast/test/kotlin/AbstractFE1UastTypesTest.kt b/plugins/uast-kotlin-fir/tests/org/jetbrains/uast/test/kotlin/AbstractFE1UastTypesTest.kt index c9b60970e56..ac36ca5cb52 100644 --- a/plugins/uast-kotlin-fir/tests/org/jetbrains/uast/test/kotlin/AbstractFE1UastTypesTest.kt +++ b/plugins/uast-kotlin-fir/tests/org/jetbrains/uast/test/kotlin/AbstractFE1UastTypesTest.kt @@ -7,24 +7,12 @@ package org.jetbrains.uast.test.kotlin import org.jetbrains.uast.UFile import org.jetbrains.uast.test.common.kotlin.FirUastTypesTestBase -import java.io.File +import org.jetbrains.uast.test.env.kotlin.AbstractFE1UastTest -abstract class AbstractFE1UastTypesTest : AbstractKotlinUastTest(), FirUastTypesTestBase { +abstract class AbstractFE1UastTypesTest : AbstractFE1UastTest(), FirUastTypesTestBase { override val isFirUastPlugin: Boolean = false override fun check(filePath: String, file: UFile) { super.check(filePath, file) } - - override var testDataDir = File("plugins/uast-kotlin-fir/testData") - - fun doTest(filePath: String) { - testDataDir = File(filePath).parentFile - val testName = File(filePath).nameWithoutExtension - val virtualFile = getVirtualFile(testName) - - val psiFile = psiManager.findFile(virtualFile) ?: error("Can't get psi file for $testName") - val uFile = uastContext.convertElementWithParent(psiFile, null) ?: error("Can't get UFile for $testName") - check(filePath, uFile as UFile) - } } diff --git a/plugins/uast-kotlin-fir/tests/org/jetbrains/uast/test/kotlin/AbstractFE1UastValuesTest.kt b/plugins/uast-kotlin-fir/tests/org/jetbrains/uast/test/kotlin/AbstractFE1UastValuesTest.kt index 62f9067aaa4..f893a71a657 100644 --- a/plugins/uast-kotlin-fir/tests/org/jetbrains/uast/test/kotlin/AbstractFE1UastValuesTest.kt +++ b/plugins/uast-kotlin-fir/tests/org/jetbrains/uast/test/kotlin/AbstractFE1UastValuesTest.kt @@ -7,24 +7,12 @@ package org.jetbrains.uast.test.kotlin import org.jetbrains.uast.UFile import org.jetbrains.uast.test.common.kotlin.FirUastValuesTestBase -import java.io.File +import org.jetbrains.uast.test.env.kotlin.AbstractFE1UastTest -abstract class AbstractFE1UastValuesTest : AbstractKotlinUastTest(), FirUastValuesTestBase { +abstract class AbstractFE1UastValuesTest : AbstractFE1UastTest(), FirUastValuesTestBase { override val isFirUastPlugin: Boolean = false override fun check(filePath: String, file: UFile) { super.check(filePath, file) } - - override var testDataDir = File("plugins/uast-kotlin-fir/testData") - - fun doTest(filePath: String) { - testDataDir = File(filePath).parentFile - val testName = filePath.substring(filePath.lastIndexOf('/') + 1).removeSuffix(".kt") - val virtualFile = getVirtualFile(testName) - - val psiFile = psiManager.findFile(virtualFile) ?: error("Can't get psi file for $testName") - val uFile = uastContext.convertElementWithParent(psiFile, null) ?: error("Can't get UFile for $testName") - check(filePath, uFile as UFile) - } }