Remove custom runtime configure from AbstractParameterInfoTest
This commit is contained in:
@@ -21,11 +21,12 @@ import com.intellij.codeInsight.hint.ShowParameterInfoHandler
|
|||||||
import com.intellij.psi.PsiDocumentManager
|
import com.intellij.psi.PsiDocumentManager
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import com.intellij.psi.PsiWhiteSpace
|
import com.intellij.psi.PsiWhiteSpace
|
||||||
import com.intellij.testFramework.IdeaTestUtil
|
|
||||||
import com.intellij.testFramework.LightProjectDescriptor
|
import com.intellij.testFramework.LightProjectDescriptor
|
||||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||||
import org.jetbrains.kotlin.idea.KotlinLanguage
|
import org.jetbrains.kotlin.idea.KotlinLanguage
|
||||||
import org.jetbrains.kotlin.idea.test.*
|
import org.jetbrains.kotlin.idea.test.JdkAndMockLibraryProjectDescriptor
|
||||||
|
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
|
||||||
|
import org.jetbrains.kotlin.idea.test.ProjectDescriptorWithStdlibSources
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
import org.jetbrains.kotlin.psi.KtFile
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.allChildren
|
import org.jetbrains.kotlin.psi.psiUtil.allChildren
|
||||||
@@ -37,11 +38,9 @@ abstract class AbstractParameterInfoTest : LightCodeInsightFixtureTestCase() {
|
|||||||
override fun getProjectDescriptor(): LightProjectDescriptor {
|
override fun getProjectDescriptor(): LightProjectDescriptor {
|
||||||
val root = KotlinTestUtils.getTestsRoot(this::class.java)
|
val root = KotlinTestUtils.getTestsRoot(this::class.java)
|
||||||
if (root.contains("Lib")) {
|
if (root.contains("Lib")) {
|
||||||
return JdkAndMockLibraryProjectDescriptor(
|
return JdkAndMockLibraryProjectDescriptor("$root/sharedLib", true, true, false, false)
|
||||||
"$root/sharedLib", true, true, false, false
|
|
||||||
)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ProjectDescriptorWithStdlibSources.INSTANCE
|
return ProjectDescriptorWithStdlibSources.INSTANCE
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,52 +53,41 @@ abstract class AbstractParameterInfoTest : LightCodeInsightFixtureTestCase() {
|
|||||||
myFixture.configureByFile(fileName)
|
myFixture.configureByFile(fileName)
|
||||||
|
|
||||||
val file = myFixture.file as KtFile
|
val file = myFixture.file as KtFile
|
||||||
val isWithRuntime = InTextDirectivesUtils.findStringWithPrefixes(file.text, "// WITH_RUNTIME") != null
|
val lastChild = file.allChildren.filter { it !is PsiWhiteSpace }.last()
|
||||||
|
val expectedResultText = when (lastChild.node.elementType) {
|
||||||
try {
|
KtTokens.BLOCK_COMMENT -> lastChild.text.substring(2, lastChild.text.length - 2).trim()
|
||||||
if (isWithRuntime) {
|
KtTokens.EOL_COMMENT -> lastChild.text.substring(2).trim()
|
||||||
ConfigLibraryUtil.configureKotlinRuntimeAndSdk(myFixture.module, PluginTestCaseBase.mockJdk())
|
else -> error("Unexpected last file child")
|
||||||
}
|
|
||||||
|
|
||||||
val lastChild = file.allChildren.filter { it !is PsiWhiteSpace }.last()
|
|
||||||
val expectedResultText = when (lastChild.node.elementType) {
|
|
||||||
KtTokens.BLOCK_COMMENT -> lastChild.text.substring(2, lastChild.text.length - 2).trim()
|
|
||||||
KtTokens.EOL_COMMENT -> lastChild.text.substring(2).trim()
|
|
||||||
else -> error("Unexpected last file child")
|
|
||||||
}
|
|
||||||
|
|
||||||
val context = ShowParameterInfoContext(editor, project, file, editor.caretModel.offset, -1, true)
|
|
||||||
|
|
||||||
val handlers = ShowParameterInfoHandler.getHandlers(project, KotlinLanguage.INSTANCE)!!
|
|
||||||
val handler = handlers.firstOrNull { it.findElementForParameterInfo(context) != null }
|
|
||||||
?: error("Could not find parameter info handler")
|
|
||||||
|
|
||||||
val mockCreateParameterInfoContext = MockCreateParameterInfoContext(file, myFixture)
|
|
||||||
val parameterOwner = handler.findElementForParameterInfo(mockCreateParameterInfoContext) as PsiElement
|
|
||||||
|
|
||||||
val textToType = InTextDirectivesUtils.findStringWithPrefixes(file.text, "// TYPE:")
|
|
||||||
if (textToType != null) {
|
|
||||||
myFixture.type(textToType)
|
|
||||||
PsiDocumentManager.getInstance(project).commitAllDocuments()
|
|
||||||
}
|
|
||||||
|
|
||||||
//to update current parameter index
|
|
||||||
val updateContext = MockUpdateParameterInfoContext(file, myFixture)
|
|
||||||
val elementForUpdating = handler.findElementForUpdatingParameterInfo(updateContext)
|
|
||||||
if (elementForUpdating != null) {
|
|
||||||
handler.updateParameterInfo(elementForUpdating, updateContext)
|
|
||||||
}
|
|
||||||
|
|
||||||
val parameterInfoUIContext = MockParameterInfoUIContext(parameterOwner, updateContext.currentParameter)
|
|
||||||
|
|
||||||
mockCreateParameterInfoContext.itemsToShow?.forEach {
|
|
||||||
handler.updateUI(it, parameterInfoUIContext)}
|
|
||||||
|
|
||||||
Assert.assertEquals(expectedResultText, parameterInfoUIContext.resultText)}
|
|
||||||
finally {
|
|
||||||
if (isWithRuntime) {
|
|
||||||
ConfigLibraryUtil.unConfigureKotlinRuntimeAndSdk(myFixture.module, IdeaTestUtil.getMockJdk17())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val context = ShowParameterInfoContext(editor, project, file, editor.caretModel.offset, -1, true)
|
||||||
|
|
||||||
|
val handlers = ShowParameterInfoHandler.getHandlers(project, KotlinLanguage.INSTANCE)!!
|
||||||
|
val handler = handlers.firstOrNull { it.findElementForParameterInfo(context) != null }
|
||||||
|
?: error("Could not find parameter info handler")
|
||||||
|
|
||||||
|
val mockCreateParameterInfoContext = MockCreateParameterInfoContext(file, myFixture)
|
||||||
|
val parameterOwner = handler.findElementForParameterInfo(mockCreateParameterInfoContext) as PsiElement
|
||||||
|
|
||||||
|
val textToType = InTextDirectivesUtils.findStringWithPrefixes(file.text, "// TYPE:")
|
||||||
|
if (textToType != null) {
|
||||||
|
myFixture.type(textToType)
|
||||||
|
PsiDocumentManager.getInstance(project).commitAllDocuments()
|
||||||
|
}
|
||||||
|
|
||||||
|
//to update current parameter index
|
||||||
|
val updateContext = MockUpdateParameterInfoContext(file, myFixture)
|
||||||
|
val elementForUpdating = handler.findElementForUpdatingParameterInfo(updateContext)
|
||||||
|
if (elementForUpdating != null) {
|
||||||
|
handler.updateParameterInfo(elementForUpdating, updateContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
val parameterInfoUIContext = MockParameterInfoUIContext(parameterOwner, updateContext.currentParameter)
|
||||||
|
|
||||||
|
mockCreateParameterInfoContext.itemsToShow?.forEach {
|
||||||
|
handler.updateUI(it, parameterInfoUIContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.assertEquals(expectedResultText, parameterInfoUIContext.resultText)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user