New MPP highlighting test: check also line markers (KT-27494)

We have to do complex operations with tags, because otherwise
tags in different files prevent correct analysis of the current one
This commit is contained in:
Mikhail Glukhikh
2018-10-31 17:51:05 +03:00
parent 9be23bb21c
commit 62e9eae48d
3 changed files with 37 additions and 16 deletions
@@ -27,17 +27,22 @@ class GradleMultiplatformHighlightingTest : GradleImportingTestCase() {
@TargetVersions("4.7+") @TargetVersions("4.7+")
@Test @Test
fun testFirst() { fun testFirst() {
doTest()
}
private fun doTest() {
val files = importProjectFromTestData() val files = importProjectFromTestData()
val project = myTestFixture.project val project = myTestFixture.project
checkFiles(files, project) { editor -> checkFiles(files, project) { editor ->
daemonAnalyzerTestCase.checkHighlighting(editor, project) daemonAnalyzerTestCase.checkHighlighting(project, editor)
} }
} }
private val daemonAnalyzerTestCase = object : DaemonAnalyzerTestCase() { private val daemonAnalyzerTestCase = object : DaemonAnalyzerTestCase() {
fun checkHighlighting(editor: Editor, project: Project) { override fun doTestLineMarkers() = true
fun checkHighlighting(project: Project, editor: Editor) {
myProject = project myProject = project
runInEdtAndWait { runInEdtAndWait {
checkHighlighting(editor, /* checkWarnings = */ true, /* checkInfos = */ false) checkHighlighting(editor, /* checkWarnings = */ true, /* checkInfos = */ false)
@@ -47,34 +52,50 @@ class GradleMultiplatformHighlightingTest : GradleImportingTestCase() {
private fun checkFiles(files: List<VirtualFile>, project: Project, check: (Editor) -> Unit) { private fun checkFiles(files: List<VirtualFile>, project: Project, check: (Editor) -> Unit) {
var atLeastOneFile = false var atLeastOneFile = false
files.filter { it.extension == "kt" }.forEach { file -> val kotlinFiles = files.filter { it.extension == "kt" }
val editor = configureEditorByExistingFile(file, project) val content = mutableMapOf<VirtualFile, String>()
kotlinFiles.forEach { file ->
val (_, textWithTags) = configureEditorByExistingFile(file, project)
atLeastOneFile = true atLeastOneFile = true
check(editor) content[file] = textWithTags
} }
Assert.assertTrue(atLeastOneFile) Assert.assertTrue(atLeastOneFile)
kotlinFiles.forEach { file ->
val (editor, _) = configureEditorByExistingFile(file, project, content[file])
check(editor)
}
} }
private fun configureEditorByExistingFile(virtualFile: VirtualFile, project: Project): Editor { private fun configureEditorByExistingFile(
var result: Editor? = null virtualFile: VirtualFile,
project: Project,
contentToSet: String? = null
): Pair<Editor, String> {
var result: Pair<Editor, String>? = null
runInEdtAndWait { runInEdtAndWait {
val editor = createEditor(virtualFile, project) val editor = createEditor(virtualFile, project)
val document = editor.document val document = editor.document
val editorInfo = EditorInfo(document.text) val editorInfo = EditorInfo(document.text)
val newFileText = editorInfo.newFileText val textWithTags = editorInfo.newFileText
ApplicationManager.getApplication().runWriteAction { ApplicationManager.getApplication().runWriteAction {
if (document.text != newFileText) { val newText = contentToSet ?: textWithTags.withoutTags()
document.setText(newFileText) if (document.text != newText) {
document.setText(newText)
} }
editorInfo.applyToEditor(editor) editorInfo.applyToEditor(editor)
} }
PsiDocumentManager.getInstance(project).commitAllDocuments() PsiDocumentManager.getInstance(project).commitAllDocuments()
result = editor result = editor to textWithTags
} }
return result!! return result!!
} }
private fun String.withoutTags(): String {
val regex = "</?(error|warning|lineMarker).*?>".toRegex()
return regex.replace(this, "")
}
private fun createEditor(file: VirtualFile, project: Project): Editor { private fun createEditor(file: VirtualFile, project: Project): Editor {
val instance = FileEditorManager.getInstance(this.myProject) val instance = FileEditorManager.getInstance(this.myProject)
PsiDocumentManager.getInstance(project).commitAllDocuments() PsiDocumentManager.getInstance(project).commitAllDocuments()
@@ -1,3 +1,3 @@
expect class <error descr="[NO_ACTUAL_FOR_EXPECT] Expected class 'My' has no actual declaration in module first_jsMain for JS">My</error> { expect class <error descr="[NO_ACTUAL_FOR_EXPECT] Expected class 'My' has no actual declaration in module first_jsMain for JS"><lineMarker>My</lineMarker></error> {
fun foo() fun <lineMarker>foo</lineMarker>()
} }
@@ -1,5 +1,5 @@
actual class My { actual class <lineMarker>My</lineMarker> {
actual fun foo() {} actual fun <lineMarker>foo</lineMarker>() {}
actual fun <error descr="[ACTUAL_WITHOUT_EXPECT] Actual function 'bar' has no corresponding expected declaration">bar</error>() {} actual fun <error descr="[ACTUAL_WITHOUT_EXPECT] Actual function 'bar' has no corresponding expected declaration">bar</error>() {}
} }