Migrate MultiModuleLineMarkerTest to the new CodeMetaInfo test infrastructure

This commit is contained in:
Alexander Dudinsky
2020-10-10 10:07:31 +03:00
parent 94bf38a7b5
commit 0e7e657657
76 changed files with 278 additions and 128 deletions
@@ -5,22 +5,10 @@
package org.jetbrains.kotlin.idea.caches.resolve
import org.jetbrains.kotlin.idea.multiplatform.setupMppProjectFromDirStructure
import org.jetbrains.kotlin.idea.codeMetaInfo.AbstractLineMarkerCodeMetaInfoTest
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
import java.io.File
abstract class AbstractMultiModuleLineMarkerTest : AbstractMultiModuleHighlightingTest() {
abstract class AbstractMultiModuleLineMarkerTest : AbstractLineMarkerCodeMetaInfoTest() {
override fun getTestDataPath() = PluginTestCaseBase.getTestDataPathBase() + "/multiModuleLineMarker/"
override val shouldCheckLineMarkers = true
override val shouldCheckResult = false
override fun doTestLineMarkers() = true
protected fun doTest(path: String) {
setupMppProjectFromDirStructure(File(path))
checkLineMarkersInProject()
}
}
@@ -29,7 +29,9 @@ import com.intellij.testFramework.runInEdtAndWait
import com.intellij.util.io.exists
import gnu.trove.TIntArrayList
import org.jetbrains.kotlin.checkers.BaseDiagnosticsTest
import org.jetbrains.kotlin.checkers.diagnostics.DebugInfoDiagnostic
import org.jetbrains.kotlin.checkers.diagnostics.SyntaxErrorDiagnostic
import org.jetbrains.kotlin.checkers.diagnostics.factories.DebugInfoDiagnosticFactory0
import org.jetbrains.kotlin.checkers.utils.CheckerTestUtil
import org.jetbrains.kotlin.checkers.utils.DiagnosticsRenderingConfiguration
import org.jetbrains.kotlin.daemon.common.OSKind
@@ -49,9 +51,11 @@ import org.jetbrains.kotlin.idea.stubs.AbstractMultiModuleTest
import org.jetbrains.kotlin.idea.util.sourceRoots
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.test.KotlinTestUtils
import org.junit.Ignore
import java.io.File
import java.nio.file.Paths
@Ignore
class CodeMetaInfoTestCase(
val codeMetaInfoTypes: Collection<AbstractCodeMetaInfoRenderConfiguration>,
val checkNoDiagnosticError: Boolean = false
@@ -158,12 +162,11 @@ class CodeMetaInfoTestCase(
codeMetaInfo.platforms.add(OSKind.current.toString())
}
}
if (parsedMetaInfo.isNotEmpty())
parsedMetaInfo.forEach {
if (it.platforms.isNotEmpty() && OSKind.current.toString() !in it.platforms) codeMetaInfoForCheck.add(
it
)
}
parsedMetaInfo.forEach {
if (it.platforms.isNotEmpty() && OSKind.current.toString() !in it.platforms) codeMetaInfoForCheck.add(
it
)
}
val textWithCodeMetaInfo = CodeMetaInfoRenderer.renderTagsToText(codeMetaInfoForCheck, myEditor.document.text)
KotlinTestUtils.assertEqualsToFile(
expectedFile,
@@ -199,6 +202,11 @@ class CodeMetaInfoTestCase(
val diagnostic: AbstractDiagnostic<*> = diagnosticCodeMetaInfo.diagnostic
diagnostic.factory.toString() in (highlightingCodeMetaInfo as HighlightingCodeMetaInfo).highlightingInfo.description
}
is DebugInfoDiagnostic -> {
val diagnostic: DebugInfoDiagnostic = diagnosticCodeMetaInfo.diagnostic
diagnostic.factory == DebugInfoDiagnosticFactory0.MISSING_UNRESOLVED &&
"[DEBUG] Reference is not resolved to anything, but is not marked unresolved" in (highlightingCodeMetaInfo as HighlightingCodeMetaInfo).highlightingInfo.description
}
else -> throw java.lang.IllegalArgumentException("Unknown diagnostic type: ${diagnosticCodeMetaInfo.diagnostic}")
}
},
@@ -17,14 +17,17 @@ import org.jetbrains.kotlin.idea.codeMetaInfo.models.LineMarkerCodeMetaInfo
abstract class AbstractCodeMetaInfoRenderConfiguration(var renderParams: Boolean = true) {
private val clickOrPressRegex = "Click or press (.*)to navigate".toRegex() //We have different hotkeys on different platforms
open fun asString(codeMetaInfo: CodeMetaInfo) = codeMetaInfo.getTag() + getPlatformsString(codeMetaInfo)
open fun getAdditionalParams(codeMetaInfo: CodeMetaInfo) = ""
protected fun sanitizeLineMarkerTooltip(originalText: String?): String {
if (originalText == null) return "null"
val noHtmlTags = StringUtil.removeHtmlTags(originalText).replace(" ", "")
val noHtmlTags = StringUtil.removeHtmlTags(originalText)
.replace(" ", "")
.replace(clickOrPressRegex, "")
.trim()
return sanitizeLineBreaks(noHtmlTags)
}
@@ -79,15 +82,16 @@ open class DiagnosticCodeMetaInfoRenderConfiguration(
}
}
open class LineMarkerRenderConfiguration(val renderDescription: Boolean = true) : AbstractCodeMetaInfoRenderConfiguration() {
open class LineMarkerRenderConfiguration(var renderDescription: Boolean = true) : AbstractCodeMetaInfoRenderConfiguration() {
override fun asString(codeMetaInfo: CodeMetaInfo): String {
if (codeMetaInfo !is LineMarkerCodeMetaInfo) return ""
return getTag() + if (renderParams) "(\"${getParamsString(codeMetaInfo)}\")" else ""
return getTag() + getParamsString(codeMetaInfo)
}
fun getTag() = "LINE_MARKER"
private fun getParamsString(lineMarkerCodeMetaInfo: LineMarkerCodeMetaInfo): String {
if (!renderParams) return ""
val params = mutableListOf<String>()
if (renderDescription)
@@ -95,7 +99,8 @@ open class LineMarkerRenderConfiguration(val renderDescription: Boolean = true)
params.add(getAdditionalParams(lineMarkerCodeMetaInfo))
return params.filter { it.isNotEmpty() }.joinToString("; ")
val paramsString = params.filter { it.isNotEmpty() }.joinToString("; ")
return if (paramsString.isEmpty()) "" else "(\"$paramsString\")"
}
}
@@ -107,14 +112,15 @@ open class HighlightingRenderConfiguration(
override fun asString(codeMetaInfo: CodeMetaInfo): String {
if (codeMetaInfo !is HighlightingCodeMetaInfo) return ""
return getTag() + if (renderParams) "(${getParamsString(codeMetaInfo)})" else ""
return getTag() + getParamsString(codeMetaInfo)
}
fun getTag() = "HIGHLIGHTING"
private fun getParamsString(highlightingCodeMetaInfo: HighlightingCodeMetaInfo): String {
val params = mutableListOf<String>()
if (!renderParams) return ""
val params = mutableListOf<String>()
if (renderSeverity)
params.add("severity='${highlightingCodeMetaInfo.highlightingInfo.severity}'")
if (renderDescription)
@@ -123,7 +129,8 @@ open class HighlightingRenderConfiguration(
params.add("textAttributesKey='${highlightingCodeMetaInfo.highlightingInfo.forcedTextAttributesKey}'")
params.add(getAdditionalParams(highlightingCodeMetaInfo))
val paramsString = params.filter { it.isNotEmpty() }.joinToString("; ")
return params.filter { it.isNotEmpty() }.joinToString("; ")
return if (paramsString.isEmpty()) "" else "(\"$paramsString\")"
}
}