Imports on paste tests: generate result if does not exist and use default target file text
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
import java.io.File
|
||||
|
||||
fun foo(): List<File><caret>
|
||||
fun foo(): List<File>
|
||||
@@ -1,5 +1,5 @@
|
||||
import java.io.File
|
||||
|
||||
fun foo() {
|
||||
list.add(File.separatorChar)<caret>
|
||||
list.add(File.separatorChar)
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import ppp.Dependency
|
||||
|
||||
fun f() {
|
||||
return Dependency.FIELD<caret>
|
||||
return Dependency.FIELD
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import ppp.dummy0
|
||||
|
||||
fun f() {
|
||||
return dummy0()<caret>
|
||||
return dummy0()
|
||||
}
|
||||
@@ -17,9 +17,14 @@
|
||||
package org.jetbrains.kotlin.idea
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightSettings
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.psi.PsiFile
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import java.io.File
|
||||
|
||||
public abstract class AbstractCopyPasteTest : JetLightCodeInsightFixtureTestCase() {
|
||||
private var savedImportsOnPasteSetting: Int = 0
|
||||
private val DEFAULT_TO_FILE_TEXT = "package to\n\n<caret>"
|
||||
|
||||
override fun setUp() {
|
||||
super.setUp()
|
||||
@@ -31,5 +36,26 @@ public abstract class AbstractCopyPasteTest : JetLightCodeInsightFixtureTestCase
|
||||
CodeInsightSettings.getInstance().ADD_IMPORTS_ON_PASTE = savedImportsOnPasteSetting
|
||||
super.tearDown()
|
||||
}
|
||||
|
||||
protected fun configureByDependencyIfExists(dependencyFileName: String): PsiFile? {
|
||||
val file = File(getTestDataPath() + File.separator + dependencyFileName)
|
||||
if (!file.exists()) return null
|
||||
return if (dependencyFileName.endsWith(".java")) {
|
||||
//allow test framework to put it under right directory
|
||||
myFixture.addClass(FileUtil.loadFile(file, true)).getContainingFile()
|
||||
}
|
||||
else {
|
||||
myFixture.configureByFile(dependencyFileName)
|
||||
}
|
||||
}
|
||||
|
||||
protected fun configureTargetFile(fileName: String): JetFile {
|
||||
if (File(getTestDataPath() + File.separator + fileName).exists()) {
|
||||
return myFixture.configureByFile(fileName) as JetFile
|
||||
}
|
||||
else {
|
||||
return myFixture.configureByText(fileName, DEFAULT_TO_FILE_TEXT) as JetFile
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-23
@@ -30,7 +30,6 @@ import java.io.File
|
||||
|
||||
public abstract class AbstractInsertImportOnPasteTest : AbstractCopyPasteTest() {
|
||||
private val BASE_PATH = PluginTestCaseBase.getTestDataPathBase() + "/copyPaste/imports"
|
||||
private val DEFAULT_TO_FILE_TEXT = "package to\n\n<caret>"
|
||||
|
||||
private val NO_ERRORS_DUMP_DIRECTIVE = "// NO_ERRORS_DUMP"
|
||||
private val DELETE_DEPENDENCIES_BEFORE_PASTE_DIRECTIVE = "// DELETE_DEPENDENCIES_BEFORE_PASTE"
|
||||
@@ -66,7 +65,7 @@ public abstract class AbstractInsertImportOnPasteTest : AbstractCopyPasteTest()
|
||||
|
||||
KotlinCopyPasteReferenceProcessor.declarationsToImportSuggested = emptyList()
|
||||
|
||||
configureToFile(testFileName.replace(".kt", ".to.kt"))
|
||||
configureTargetFile(testFileName.replace(".kt", ".to.kt"))
|
||||
performNotWriteEditorAction(IdeActions.ACTION_PASTE)
|
||||
|
||||
val namesToImportDump = KotlinCopyPasteReferenceProcessor.declarationsToImportSuggested.joinToString("\n")
|
||||
@@ -79,25 +78,4 @@ public abstract class AbstractInsertImportOnPasteTest : AbstractCopyPasteTest()
|
||||
resultFile.dumpTextWithErrors()
|
||||
JetTestUtils.assertEqualsToFile(File(path.replace(".kt", ".expected.kt")), resultText)
|
||||
}
|
||||
|
||||
private fun configureToFile(toFileName: String): JetFile {
|
||||
if (File(BASE_PATH + "/" + toFileName).exists()) {
|
||||
return myFixture.configureByFile(toFileName) as JetFile
|
||||
}
|
||||
else {
|
||||
return myFixture.configureByText(toFileName, DEFAULT_TO_FILE_TEXT) as JetFile
|
||||
}
|
||||
}
|
||||
|
||||
private fun configureByDependencyIfExists(dependencyFileName: String): PsiFile? {
|
||||
val file = File(BASE_PATH + "/" + dependencyFileName)
|
||||
if (!file.exists()) return null
|
||||
return if (dependencyFileName.endsWith(".java")) {
|
||||
//allow test framework to put it under right directory
|
||||
myFixture.addClass(FileUtil.loadFile(file, true)).getContainingFile()
|
||||
}
|
||||
else {
|
||||
myFixture.configureByFile(dependencyFileName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-13
@@ -17,12 +17,12 @@
|
||||
package org.jetbrains.kotlin.idea.conversion.copy
|
||||
|
||||
import com.intellij.openapi.actionSystem.IdeActions
|
||||
import com.intellij.testFramework.LightProjectDescriptor
|
||||
import org.jetbrains.kotlin.idea.AbstractCopyPasteTest
|
||||
import org.jetbrains.kotlin.idea.JetWithJdkAndRuntimeLightProjectDescriptor
|
||||
import org.jetbrains.kotlin.idea.PluginTestCaseBase
|
||||
import org.jetbrains.kotlin.idea.editor.JetEditorOptions
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||
import org.jetbrains.kotlin.test.JetTestUtils
|
||||
import java.io.File
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@@ -31,9 +31,9 @@ public abstract class AbstractJavaToKotlinCopyPasteConversionTest : AbstractCopy
|
||||
|
||||
private var oldEditorOptions: JetEditorOptions? = null
|
||||
|
||||
override fun getProjectDescriptor(): LightProjectDescriptor {
|
||||
return JetWithJdkAndRuntimeLightProjectDescriptor.INSTANCE
|
||||
}
|
||||
override fun getTestDataPath() = BASE_PATH
|
||||
|
||||
override fun getProjectDescriptor() = JetWithJdkAndRuntimeLightProjectDescriptor.INSTANCE
|
||||
|
||||
override fun setUp() {
|
||||
super.setUp()
|
||||
@@ -57,15 +57,9 @@ public abstract class AbstractJavaToKotlinCopyPasteConversionTest : AbstractCopy
|
||||
|
||||
myFixture.performEditorAction(IdeActions.ACTION_COPY)
|
||||
|
||||
val toFileName = testName + ".to.kt"
|
||||
val dependencyFileName = testName + ".dependency.kt"
|
||||
configureByDependencyIfExists(testName + ".dependency.kt")
|
||||
|
||||
if (File(BASE_PATH + File.separator + dependencyFileName).exists()) {
|
||||
myFixture.configureByFiles(toFileName, dependencyFileName)
|
||||
}
|
||||
else {
|
||||
myFixture.configureByFile(toFileName)
|
||||
}
|
||||
configureTargetFile(testName + ".to.kt")
|
||||
|
||||
ConvertJavaCopyPastePostProcessor.conversionPerformed = false
|
||||
|
||||
@@ -74,6 +68,6 @@ public abstract class AbstractJavaToKotlinCopyPasteConversionTest : AbstractCopy
|
||||
assertEquals(noConversionExpected, !ConvertJavaCopyPastePostProcessor.conversionPerformed,
|
||||
if (noConversionExpected) "Conversion to Kotlin should not be suggested" else "No conversion to Kotlin suggested")
|
||||
|
||||
myFixture.checkResultByFile(testName + ".expected.kt")
|
||||
JetTestUtils.assertEqualsToFile(File(path.replace(".java", ".expected.kt")), myFixture.getFile().getText())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user