Check only one class in JS decompiler tests to reuse test data
JVM tests check only single class result, in order to reuse test data JS tests should do the same. CHECK_PACKAGE is introduced to override this behaviour explicitly.
This commit is contained in:
@@ -19,6 +19,3 @@ public final class SecondaryConstructors public constructor(x: kotlin.Boolean) {
|
||||
}
|
||||
}
|
||||
|
||||
public final annotation class anno public constructor() : kotlin.Annotation {
|
||||
}
|
||||
|
||||
|
||||
@@ -26,3 +26,5 @@ class TypeAliases {
|
||||
@Suppress("TOPLEVEL_TYPEALIASES_ONLY")
|
||||
private typealias Parametrized<E, F> = Map<E, F>
|
||||
}
|
||||
|
||||
// CHECK_PACKAGE
|
||||
+6
-2
@@ -44,6 +44,8 @@ abstract class AbstractDecompiledTextBaseTest(
|
||||
|
||||
protected abstract fun checkPsiFile(psiFile: PsiFile)
|
||||
|
||||
protected abstract fun textToCheck(psiFile: PsiFile): String
|
||||
|
||||
protected open fun checkStubConsistency(file: VirtualFile, decompiledText: String) {}
|
||||
|
||||
fun doTest(path: String) {
|
||||
@@ -51,9 +53,11 @@ abstract class AbstractDecompiledTextBaseTest(
|
||||
val psiFile = PsiManager.getInstance(project).findFile(fileToDecompile)!!
|
||||
checkPsiFile(psiFile)
|
||||
|
||||
KotlinTestUtils.assertEqualsToFile(File(path.substring(0, path.length - 1) + ".expected.kt"), psiFile.text)
|
||||
val checkedText = textToCheck(psiFile)
|
||||
|
||||
checkStubConsistency(fileToDecompile, psiFile.text)
|
||||
KotlinTestUtils.assertEqualsToFile(File(path.substring(0, path.length - 1) + ".expected.kt"), checkedText)
|
||||
|
||||
checkStubConsistency(fileToDecompile, checkedText)
|
||||
|
||||
checkThatFileWasParsedCorrectly(psiFile)
|
||||
}
|
||||
|
||||
+45
-2
@@ -18,18 +18,61 @@ package org.jetbrains.kotlin.idea.decompiler.textBuilder
|
||||
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.psi.PsiComment
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.PsiWhiteSpace
|
||||
import org.jetbrains.kotlin.idea.decompiler.KtDecompiledFile
|
||||
import org.jetbrains.kotlin.idea.test.SdkAndMockLibraryProjectDescriptor
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.KtClass
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtImportList
|
||||
import org.jetbrains.kotlin.psi.KtPackageDirective
|
||||
import org.jetbrains.kotlin.serialization.js.JsSerializerProtocol
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||
import java.io.File
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
abstract class AbstractDecompiledTextFromJsMetadataTest(baseDirectory: String) : AbstractDecompiledTextBaseTest(baseDirectory, true, withRuntime = true) {
|
||||
private const val CHECK_PACKAGE_DIRECTIVE = "CHECK_PACKAGE"
|
||||
|
||||
abstract class AbstractDecompiledTextFromJsMetadataTest(baseDirectory: String) :
|
||||
AbstractDecompiledTextBaseTest(baseDirectory, true, withRuntime = true) {
|
||||
override fun getFileToDecompile(): VirtualFile = getKjsmFile(TEST_PACKAGE, myModule!!)
|
||||
|
||||
override fun checkPsiFile(psiFile: PsiFile) =
|
||||
assertTrue(psiFile is KtDecompiledFile, "Expecting decompiled kotlin javascript file, was: " + psiFile::class.java)
|
||||
assertTrue(psiFile is KtDecompiledFile, "Expecting decompiled kotlin javascript file, was: " + psiFile::class.java)
|
||||
|
||||
override fun textToCheck(psiFile: PsiFile): String {
|
||||
if (psiFile !is KtFile) return psiFile.text
|
||||
val singleClass = findSingleClassToCheck(psiFile) ?: return psiFile.text
|
||||
|
||||
// Take top-comments and spaces after them, package directive with space after it, and single class element
|
||||
return psiFile.children.filter { child ->
|
||||
when (child) {
|
||||
is PsiComment -> true
|
||||
is KtPackageDirective -> true
|
||||
singleClass -> true
|
||||
is PsiWhiteSpace -> {
|
||||
child.prevSibling is KtPackageDirective || child.prevSibling is KtImportList || child.prevSibling is PsiComment
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
}.joinToString(separator = "") { it.text }
|
||||
}
|
||||
|
||||
private fun findSingleClassToCheck(psiFile: PsiFile): PsiElement? {
|
||||
val singleClassName = getTestName(false)
|
||||
val singleClass = psiFile.children.find { child -> child is KtClass && child.name == singleClassName } ?: return null
|
||||
|
||||
val mainFilePath = "$TEST_DATA_PATH/$singleClassName/$singleClassName.kt"
|
||||
val mainFile = File(mainFilePath)
|
||||
if (mainFile.exists() && InTextDirectivesUtils.isDirectiveDefined(File(mainFilePath).readText(), CHECK_PACKAGE_DIRECTIVE)) {
|
||||
return null
|
||||
}
|
||||
|
||||
return singleClass
|
||||
}
|
||||
}
|
||||
|
||||
abstract class AbstractCommonDecompiledTextFromJsMetadataTest : AbstractDecompiledTextFromJsMetadataTest("/decompiler/decompiledText")
|
||||
|
||||
+2
@@ -46,6 +46,8 @@ abstract class AbstractDecompiledTextTest(baseDirectory: String, allowKotlinPack
|
||||
|
||||
override fun checkPsiFile(psiFile: PsiFile) =
|
||||
assertTrue(psiFile is KtClsFile, "Expecting decompiled kotlin file, was: " + psiFile::class.java)
|
||||
|
||||
override fun textToCheck(psiFile: PsiFile) = psiFile.text
|
||||
}
|
||||
|
||||
abstract class AbstractCommonDecompiledTextTest : AbstractDecompiledTextTest("/decompiler/decompiledText", true)
|
||||
|
||||
Reference in New Issue
Block a user