Remove custom runtime configure from AbstractParameterInfoTest

This commit is contained in:
Nikolay Krasko
2017-11-30 16:06:28 +03:00
parent f460104ace
commit e2418ec892
@@ -21,11 +21,12 @@ import com.intellij.codeInsight.hint.ShowParameterInfoHandler
import com.intellij.psi.PsiDocumentManager
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiWhiteSpace
import com.intellij.testFramework.IdeaTestUtil
import com.intellij.testFramework.LightProjectDescriptor
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
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.psi.KtFile
import org.jetbrains.kotlin.psi.psiUtil.allChildren
@@ -37,11 +38,9 @@ abstract class AbstractParameterInfoTest : LightCodeInsightFixtureTestCase() {
override fun getProjectDescriptor(): LightProjectDescriptor {
val root = KotlinTestUtils.getTestsRoot(this::class.java)
if (root.contains("Lib")) {
return JdkAndMockLibraryProjectDescriptor(
"$root/sharedLib", true, true, false, false
)
return JdkAndMockLibraryProjectDescriptor("$root/sharedLib", true, true, false, false)
}
return ProjectDescriptorWithStdlibSources.INSTANCE
}
@@ -54,52 +53,41 @@ abstract class AbstractParameterInfoTest : LightCodeInsightFixtureTestCase() {
myFixture.configureByFile(fileName)
val file = myFixture.file as KtFile
val isWithRuntime = InTextDirectivesUtils.findStringWithPrefixes(file.text, "// WITH_RUNTIME") != null
try {
if (isWithRuntime) {
ConfigLibraryUtil.configureKotlinRuntimeAndSdk(myFixture.module, PluginTestCaseBase.mockJdk())
}
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 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)
}
}