KT-32366: Change base of AbstractScratchLineMarkersTest

- with `FileEditorManagerTestCase` it is possible to work with actual TextEditors instead of wrappers during tests, so it will be possible to use `TextEditorWithPreview` via `TextEditorProvider` service
This commit is contained in:
Roman Golyshev
2019-08-19 11:24:44 +03:00
committed by Roman Golyshev
parent 1177566386
commit 37c6102a03
3 changed files with 54 additions and 29 deletions
@@ -45,34 +45,14 @@ abstract class AbstractLineMarkersTest : KotlinLightCodeInsightFixtureTestCase()
fun doTest(path: String) = doTest(path) {}
protected fun doAndCheckHighlighting(
documentToAnalyze: Document, expectedHighlighting: ExpectedHighlightingData, expectedFile: File
project: Project,
documentToAnalyze: Document,
expectedHighlighting: ExpectedHighlightingData,
expectedFile: File
): List<LineMarkerInfo<*>> {
myFixture.doHighlighting()
val markers = DaemonCodeAnalyzerImpl.getLineMarkers(documentToAnalyze, myFixture.project)
try {
expectedHighlighting.checkLineMarkers(markers, documentToAnalyze.text)
// This is a workaround for sad bug in ExpectedHighlightingData:
// the latter doesn't throw assertion error when some line markers are expected, but none are present.
if (FileUtil.loadFile(expectedFile).contains("<lineMarker") && markers.isEmpty()) {
throw AssertionError("Some line markers are expected, but nothing is present at all")
}
} catch (error: AssertionError) {
try {
val actualTextWithTestData = TagsTestDataUtil.insertInfoTags(markers, true, myFixture.file.text)
KotlinTestUtils.assertEqualsToFile(expectedFile, actualTextWithTestData)
} catch (failure: FileComparisonFailure) {
throw FileComparisonFailure(
error.message + "\n" + failure.message,
failure.expected,
failure.actual,
failure.filePath
)
}
}
return markers
return checkHighlighting(project, documentToAnalyze, expectedHighlighting, expectedFile)
}
fun doTest(path: String, additionalCheck: () -> Unit) {
@@ -92,7 +72,7 @@ abstract class AbstractLineMarkersTest : KotlinLightCodeInsightFixtureTestCase()
PsiDocumentManager.getInstance(project).commitAllDocuments()
val markers = doAndCheckHighlighting(document, data, File(path))
val markers = doAndCheckHighlighting(myFixture.project, document, data, File(path))
assertNavigationElements(myFixture.project, myFixture.file as KtFile, markers)
additionalCheck()
@@ -173,5 +153,37 @@ abstract class AbstractLineMarkersTest : KotlinLightCodeInsightFixtureTestCase()
return expectedNavigationText
}
fun checkHighlighting(
project: Project,
documentToAnalyze: Document,
expectedHighlighting: ExpectedHighlightingData,
expectedFile: File
): MutableList<LineMarkerInfo<*>> {
val markers = DaemonCodeAnalyzerImpl.getLineMarkers(documentToAnalyze, project)
try {
expectedHighlighting.checkLineMarkers(markers, documentToAnalyze.text)
// This is a workaround for sad bug in ExpectedHighlightingData:
// the latter doesn't throw assertion error when some line markers are expected, but none are present.
if (FileUtil.loadFile(expectedFile).contains("<lineMarker") && markers.isEmpty()) {
throw AssertionError("Some line markers are expected, but nothing is present at all")
}
} catch (error: AssertionError) {
try {
val actualTextWithTestData = TagsTestDataUtil.insertInfoTags(markers, true, documentToAnalyze.text)
KotlinTestUtils.assertEqualsToFile(expectedFile, actualTextWithTestData)
} catch (failure: FileComparisonFailure) {
throw FileComparisonFailure(
error.message + "\n" + failure.message,
failure.expected,
failure.actual,
failure.filePath
)
}
}
return markers
}
}
}
@@ -79,7 +79,7 @@ abstract class AbstractLineMarkersTestInLibrarySources : AbstractLineMarkersTest
throw AssertionError("File ${myFixture.file.virtualFile.path} should be in library sources!")
}
doAndCheckHighlighting(document, data, file)
doAndCheckHighlighting(myFixture.project, document, data, file)
}
}
}
@@ -5,12 +5,16 @@
package org.jetbrains.kotlin.idea.scratch
import com.intellij.codeInsight.daemon.LineMarkerInfo
import com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl
import com.intellij.ide.scratch.ScratchFileService
import com.intellij.ide.scratch.ScratchRootType
import com.intellij.openapi.editor.Document
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.util.io.FileUtil
import com.intellij.psi.PsiDocumentManager
import com.intellij.testFramework.ExpectedHighlightingData
import com.intellij.testFramework.FileEditorManagerTestCase
import org.jetbrains.kotlin.idea.KotlinLanguage
import org.jetbrains.kotlin.idea.codeInsight.AbstractLineMarkersTest
import org.jetbrains.kotlin.idea.core.script.ScriptDependenciesManager
@@ -19,7 +23,7 @@ import org.jetbrains.kotlin.idea.util.application.runWriteAction
import org.jetbrains.kotlin.psi.KtFile
import java.io.File
abstract class AbstractScratchLineMarkersTest : AbstractLineMarkersTest() {
abstract class AbstractScratchLineMarkersTest : FileEditorManagerTestCase() {
fun doScratchTest(path: String) {
val fileText = FileUtil.loadFile(File(path))
@@ -50,7 +54,7 @@ abstract class AbstractScratchLineMarkersTest : AbstractLineMarkersTest() {
val markers = doAndCheckHighlighting(document, data, File(path))
assertNavigationElements(myFixture.project, myFixture.file as KtFile, markers)
AbstractLineMarkersTest.assertNavigationElements(myFixture.project, myFixture.file as KtFile, markers)
}
override fun tearDown() {
@@ -60,4 +64,13 @@ abstract class AbstractScratchLineMarkersTest : AbstractLineMarkersTest() {
runWriteAction { file.delete(this) }
}
}
private fun doAndCheckHighlighting(
documentToAnalyze: Document, expectedHighlighting: ExpectedHighlightingData, expectedFile: File
): List<LineMarkerInfo<*>> {
myFixture.doHighlighting()
return AbstractLineMarkersTest.checkHighlighting(myFixture.project, documentToAnalyze, expectedHighlighting, expectedFile)
}
}