Rewrite test class to make it work on Windows
Stop using dummy file and assert result with assertEqualsToFile(). Previous version didn't work on Windows because of `\r`.
This commit is contained in:
+8
-17
@@ -16,36 +16,27 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.intentions
|
package org.jetbrains.kotlin.idea.intentions
|
||||||
|
|
||||||
import com.intellij.openapi.fileEditor.FileDocumentManager
|
|
||||||
import com.intellij.openapi.vfs.LocalFileSystem
|
|
||||||
import com.intellij.psi.PsiDocumentManager
|
|
||||||
import junit.framework.TestCase
|
import junit.framework.TestCase
|
||||||
import org.jetbrains.kotlin.idea.intentions.copyConcatenatedStringToClipboard.ConcatenatedStringGenerator
|
import org.jetbrains.kotlin.idea.intentions.copyConcatenatedStringToClipboard.ConcatenatedStringGenerator
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||||
import org.jetbrains.kotlin.psi.KtBinaryExpression
|
import org.jetbrains.kotlin.psi.KtBinaryExpression
|
||||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.collectDescendantsOfType
|
import org.jetbrains.kotlin.psi.psiUtil.collectDescendantsOfType
|
||||||
|
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compare xxx.kt.result file with the result of ConcatenatedStringGenerator().create(KtBinaryExpression) where KtBinaryExpression is the last KtBinaryExpression of xxx.kt file
|
* Compare xxx.kt.result file with the result of ConcatenatedStringGenerator().create(KtBinaryExpression) where KtBinaryExpression is
|
||||||
|
* the last KtBinaryExpression of xxx.kt file
|
||||||
*/
|
*/
|
||||||
abstract class AbstractConcatenatedStringGeneratorTest : KotlinLightCodeInsightFixtureTestCase() {
|
abstract class AbstractConcatenatedStringGeneratorTest : KotlinLightCodeInsightFixtureTestCase() {
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
protected fun doTest(path: String) {
|
protected fun doTest(path: String) {
|
||||||
val mainFile = File(path)
|
myFixture.configureByFile(path)
|
||||||
val fileText = mainFile.readText()
|
val expression = myFixture.file.collectDescendantsOfType<KtBinaryExpression>().lastOrNull()
|
||||||
val resultFile = File("$path.result")
|
|
||||||
val expectedText = resultFile.readText()
|
|
||||||
|
|
||||||
val vFile = LocalFileSystem.getInstance().findFileByPath(path) ?: return
|
|
||||||
val document = FileDocumentManager.getInstance().getDocument(vFile) ?: return
|
|
||||||
val psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document) ?: return
|
|
||||||
|
|
||||||
val ktFile = KtPsiFactory(project).createAnalyzableFile("dummy.kt", fileText, psiFile)
|
|
||||||
val expression = ktFile.collectDescendantsOfType<KtBinaryExpression>().lastOrNull()
|
|
||||||
TestCase.assertNotNull("No binary expression found: $path", expression)
|
TestCase.assertNotNull("No binary expression found: $path", expression)
|
||||||
|
|
||||||
val generatedString = ConcatenatedStringGenerator().create(expression!!)
|
val generatedString = ConcatenatedStringGenerator().create(expression!!)
|
||||||
TestCase.assertEquals("mismatch '$expectedText' - '$generatedString'", expectedText, generatedString)
|
|
||||||
|
KotlinTestUtils.assertEqualsToFile(File("$path.result"), generatedString)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user