Rewrite KotlinNameSuggesterTest test with KotlinLightCodeInsightFixtureTestCase
Use proper project descriptors and avoid reconfigure for test project.
This commit is contained in:
+39
-49
@@ -17,99 +17,89 @@
|
|||||||
package org.jetbrains.kotlin.idea.refactoring.nameSuggester
|
package org.jetbrains.kotlin.idea.refactoring.nameSuggester
|
||||||
|
|
||||||
import com.intellij.openapi.util.text.StringUtil
|
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.caches.resolve.analyze
|
||||||
import org.jetbrains.kotlin.idea.codeInsight.CodeInsightUtils
|
import org.jetbrains.kotlin.idea.codeInsight.CodeInsightUtils
|
||||||
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester
|
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester
|
||||||
import org.jetbrains.kotlin.idea.refactoring.IntroduceRefactoringException
|
import org.jetbrains.kotlin.idea.refactoring.IntroduceRefactoringException
|
||||||
import org.jetbrains.kotlin.idea.refactoring.selectElement
|
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.idea.test.PluginTestCaseBase
|
||||||
import org.jetbrains.kotlin.psi.KtExpression
|
import org.jetbrains.kotlin.psi.KtExpression
|
||||||
import org.jetbrains.kotlin.psi.KtFile
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
|
||||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||||
import java.lang.AssertionError
|
import java.lang.AssertionError
|
||||||
|
|
||||||
class KotlinNameSuggesterTest : LightCodeInsightFixtureTestCase() {
|
class KotlinNameSuggesterTest : KotlinLightCodeInsightFixtureTestCase() {
|
||||||
fun testArrayList() { doTest() }
|
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() {
|
override fun getTestDataPath(): String {
|
||||||
super.setUp()
|
return PluginTestCaseBase.getTestDataPathBase() + "/refactoring/nameSuggester"
|
||||||
myFixture.testDataPath = PluginTestCaseBase.getTestDataPathBase() + "/refactoring/nameSuggester"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun doTest() {
|
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 {
|
try {
|
||||||
if (withRuntime) {
|
myFixture.configureByFile(getTestName(false) + ".kt")
|
||||||
ConfigLibraryUtil.configureKotlinRuntimeAndSdk(myModule, PluginTestCaseBase.mockJdk())
|
val file = myFixture.file as KtFile
|
||||||
}
|
val expectedResultText = KotlinTestUtils.getLastCommentInFile(file)
|
||||||
|
|
||||||
selectElement(myFixture.editor, file, listOf(CodeInsightUtils.ElementKind.EXPRESSION)) {
|
selectElement(myFixture.editor, file, listOf(CodeInsightUtils.ElementKind.EXPRESSION)) {
|
||||||
val names = KotlinNameSuggester
|
val names = KotlinNameSuggester
|
||||||
.suggestNamesByExpressionAndType(it as KtExpression,
|
.suggestNamesByExpressionAndType(
|
||||||
null,
|
it as KtExpression,
|
||||||
it.analyze(BodyResolveMode.PARTIAL),
|
null,
|
||||||
{ true },
|
it.analyze(BodyResolveMode.PARTIAL),
|
||||||
"value")
|
{ true },
|
||||||
.sorted()
|
"value"
|
||||||
|
)
|
||||||
|
.sorted()
|
||||||
val result = StringUtil.join(names, "\n").trim()
|
val result = StringUtil.join(names, "\n").trim()
|
||||||
assertEquals(expectedResultText, result)
|
assertEquals(expectedResultText, result)
|
||||||
}
|
}
|
||||||
}
|
} catch (e: IntroduceRefactoringException) {
|
||||||
catch (e: IntroduceRefactoringException) {
|
|
||||||
throw AssertionError("Failed to find expression: " + e.message)
|
throw AssertionError("Failed to find expression: " + e.message)
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
if (withRuntime) {
|
|
||||||
ConfigLibraryUtil.unConfigureKotlinRuntimeAndSdk(myModule, PluginTestCaseBase.mockJdk())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user