Rewrite KotlinNameSuggesterTest test with KotlinLightCodeInsightFixtureTestCase

Use proper project descriptors and avoid reconfigure for test project.
This commit is contained in:
Nikolay Krasko
2018-01-12 19:38:57 +03:00
parent ed11528664
commit 2ca7045228
@@ -17,99 +17,89 @@
package org.jetbrains.kotlin.idea.refactoring.nameSuggester
import com.intellij.openapi.util.text.StringUtil
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.codeInsight.CodeInsightUtils
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester
import org.jetbrains.kotlin.idea.refactoring.IntroduceRefactoringException
import org.jetbrains.kotlin.idea.refactoring.selectElement
import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
import org.jetbrains.kotlin.psi.KtExpression
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
import org.jetbrains.kotlin.test.InTextDirectivesUtils
import org.jetbrains.kotlin.test.KotlinTestUtils
import java.lang.AssertionError
class KotlinNameSuggesterTest : LightCodeInsightFixtureTestCase() {
fun testArrayList() { doTest() }
class KotlinNameSuggesterTest : KotlinLightCodeInsightFixtureTestCase() {
fun testArrayList() = doTest()
fun testGetterSure() { doTest() }
fun testGetterSure() = doTest()
fun testNameArrayOfClasses() { doTest() }
fun testNameArrayOfClasses() = doTest()
fun testNameArrayOfStrings() { doTest() }
fun testNameArrayOfStrings() = doTest()
fun testNamePrimitiveArray() { doTest() }
fun testNamePrimitiveArray() = doTest()
fun testNameCallExpression() { doTest() }
fun testNameCallExpression() = doTest()
fun testNameClassCamelHump() { doTest() }
fun testNameClassCamelHump() = doTest()
fun testNameLong() { doTest() }
fun testNameLong() = doTest()
fun testNameReferenceExpression() { doTest() }
fun testNameReferenceExpression() = doTest()
fun testNameString() { doTest() }
fun testNameString() = doTest()
fun testAnonymousObject() { doTest() }
fun testAnonymousObject() = doTest()
fun testAnonymousObjectWithSuper() { doTest() }
fun testAnonymousObjectWithSuper() = doTest()
fun testArrayOfObjectsType() { doTest() }
fun testArrayOfObjectsType() = doTest()
fun testURL() { doTest() }
fun testURL() = doTest()
fun testParameterNameByArgumentExpression() { doTest() }
fun testParameterNameByArgumentExpression() = doTest()
fun testParameterNameByParenthesizedArgumentExpression() { doTest() }
fun testParameterNameByParenthesizedArgumentExpression() = doTest()
fun testIdWithDigits() { doTest() }
fun testIdWithDigits() = doTest()
fun testIdWithNonASCII() { doTest() }
fun testIdWithNonASCII() = doTest()
fun testFunction1() { doTest() }
fun testFunction1() = doTest()
fun testFunction2() { doTest() }
fun testFunction2() = doTest()
fun testExtensionFunction1() { doTest() }
fun testExtensionFunction1() = doTest()
fun testExtensionFunction2() { doTest() }
fun testExtensionFunction2() = doTest()
override fun setUp() {
super.setUp()
myFixture.testDataPath = PluginTestCaseBase.getTestDataPathBase() + "/refactoring/nameSuggester"
override fun getTestDataPath(): String {
return PluginTestCaseBase.getTestDataPathBase() + "/refactoring/nameSuggester"
}
private fun doTest() {
myFixture.configureByFile(getTestName(false) + ".kt")
val file = myFixture.file as KtFile
val expectedResultText = KotlinTestUtils.getLastCommentInFile(file)
val withRuntime = InTextDirectivesUtils.isDirectiveDefined(file.text, "//WITH_RUNTIME")
try {
if (withRuntime) {
ConfigLibraryUtil.configureKotlinRuntimeAndSdk(myModule, PluginTestCaseBase.mockJdk())
}
myFixture.configureByFile(getTestName(false) + ".kt")
val file = myFixture.file as KtFile
val expectedResultText = KotlinTestUtils.getLastCommentInFile(file)
selectElement(myFixture.editor, file, listOf(CodeInsightUtils.ElementKind.EXPRESSION)) {
val names = KotlinNameSuggester
.suggestNamesByExpressionAndType(it as KtExpression,
null,
it.analyze(BodyResolveMode.PARTIAL),
{ true },
"value")
.sorted()
.suggestNamesByExpressionAndType(
it as KtExpression,
null,
it.analyze(BodyResolveMode.PARTIAL),
{ true },
"value"
)
.sorted()
val result = StringUtil.join(names, "\n").trim()
assertEquals(expectedResultText, result)
}
}
catch (e: IntroduceRefactoringException) {
} catch (e: IntroduceRefactoringException) {
throw AssertionError("Failed to find expression: " + e.message)
}
finally {
if (withRuntime) {
ConfigLibraryUtil.unConfigureKotlinRuntimeAndSdk(myModule, PluginTestCaseBase.mockJdk())
}
}
}
}