Minor: Reformat several IDEA debugger tests
This commit is contained in:
+15
-12
@@ -45,7 +45,7 @@ abstract class AbstractCodeFragmentHighlightingTest : AbstractPsiCheckerTest() {
|
|||||||
val file = myFixture.file as KtFile
|
val file = myFixture.file as KtFile
|
||||||
InTextDirectivesUtils.findListWithPrefixes(fileText, "// IMPORT: ").forEach {
|
InTextDirectivesUtils.findListWithPrefixes(fileText, "// IMPORT: ").forEach {
|
||||||
val descriptor = file.resolveImportReference(FqName(it)).singleOrNull()
|
val descriptor = file.resolveImportReference(FqName(it)).singleOrNull()
|
||||||
?: error("Could not resolve descriptor to import: $it")
|
?: error("Could not resolve descriptor to import: $it")
|
||||||
ImportInsertHelper.getInstance(project).importDescriptor(file, descriptor)
|
ImportInsertHelper.getInstance(project).importDescriptor(file, descriptor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -95,10 +95,10 @@ abstract class AbstractCodeFragmentAutoImportTest : AbstractPsiCheckerTest() {
|
|||||||
myFixture.doHighlighting()
|
myFixture.doHighlighting()
|
||||||
|
|
||||||
val importFix = myFixture.availableIntentions.singleOrNull { it.familyName == "Import" }
|
val importFix = myFixture.availableIntentions.singleOrNull { it.familyName == "Import" }
|
||||||
?: error("No import fix available")
|
?: error("No import fix available")
|
||||||
importFix.invoke(project, editor, file)
|
importFix.invoke(project, editor, file)
|
||||||
|
|
||||||
myFixture.checkResultByFile(filePath + ".after")
|
myFixture.checkResultByFile("$filePath.after")
|
||||||
|
|
||||||
val fragment = myFixture.file as KtCodeFragment
|
val fragment = myFixture.file as KtCodeFragment
|
||||||
fragment.checkImports(testDataPath + File.separator + filePath)
|
fragment.checkImports(testDataPath + File.separator + filePath)
|
||||||
@@ -114,13 +114,12 @@ abstract class AbstractCodeFragmentAutoImportTest : AbstractPsiCheckerTest() {
|
|||||||
private fun KtCodeFragment.checkImports(testPath: String) {
|
private fun KtCodeFragment.checkImports(testPath: String) {
|
||||||
val importList = importsAsImportList()
|
val importList = importsAsImportList()
|
||||||
val importsText = StringUtil.convertLineSeparators(importList?.text ?: "")
|
val importsText = StringUtil.convertLineSeparators(importList?.text ?: "")
|
||||||
val fragmentAfterFile = File(testPath + ".after.imports")
|
val fragmentAfterFile = File("$testPath.after.imports")
|
||||||
|
|
||||||
if (fragmentAfterFile.exists()) {
|
if (fragmentAfterFile.exists()) {
|
||||||
KotlinTestUtils.assertEqualsToFile(fragmentAfterFile, importsText)
|
KotlinTestUtils.assertEqualsToFile(fragmentAfterFile, importsText)
|
||||||
}
|
} else {
|
||||||
else {
|
assertTrue(importsText.isEmpty(), "Unexpected imports found: $importsText")
|
||||||
assertTrue(importsText.isEmpty(), "Unexpected imports found: $importsText" )
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,19 +131,23 @@ private fun JavaCodeInsightTestFixture.configureByCodeFragment(filePath: String)
|
|||||||
|
|
||||||
val typeStr = InTextDirectivesUtils.findStringWithPrefixes(getFile().text, "// ${ExpectedCompletionUtils.RUNTIME_TYPE} ")
|
val typeStr = InTextDirectivesUtils.findStringWithPrefixes(getFile().text, "// ${ExpectedCompletionUtils.RUNTIME_TYPE} ")
|
||||||
if (typeStr != null) {
|
if (typeStr != null) {
|
||||||
file.putCopyableUserData(KtCodeFragment.RUNTIME_TYPE_EVALUATOR, {
|
file.putCopyableUserData(KtCodeFragment.RUNTIME_TYPE_EVALUATOR) {
|
||||||
val codeFragment = KtPsiFactory(project).createBlockCodeFragment("val xxx: $typeStr", PsiTreeUtil.getParentOfType(elementAt, KtElement::class.java))
|
val codeFragment = KtPsiFactory(project).createBlockCodeFragment(
|
||||||
|
"val xxx: $typeStr",
|
||||||
|
PsiTreeUtil.getParentOfType(elementAt, KtElement::class.java)
|
||||||
|
)
|
||||||
val context = codeFragment.analyzeWithContent()
|
val context = codeFragment.analyzeWithContent()
|
||||||
val typeReference: KtTypeReference = PsiTreeUtil.getChildOfType(codeFragment.getContentElement().firstChild, KtTypeReference::class.java)!!
|
val typeReference: KtTypeReference =
|
||||||
|
PsiTreeUtil.getChildOfType(codeFragment.getContentElement().firstChild, KtTypeReference::class.java)!!
|
||||||
context[BindingContext.TYPE, typeReference]
|
context[BindingContext.TYPE, typeReference]
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
configureFromExistingVirtualFile(file.virtualFile!!)
|
configureFromExistingVirtualFile(file.virtualFile!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createCodeFragment(filePath: String, contextElement: PsiElement): KtCodeFragment {
|
private fun createCodeFragment(filePath: String, contextElement: PsiElement): KtCodeFragment {
|
||||||
val fileForFragment = File(filePath + ".fragment")
|
val fileForFragment = File("$filePath.fragment")
|
||||||
val codeFragmentText = FileUtil.loadFile(fileForFragment, true).trim()
|
val codeFragmentText = FileUtil.loadFile(fileForFragment, true).trim()
|
||||||
val psiFactory = KtPsiFactory(contextElement.project)
|
val psiFactory = KtPsiFactory(contextElement.project)
|
||||||
if (fileForFragment.readLines().size == 1) {
|
if (fileForFragment.readLines().size == 1) {
|
||||||
|
|||||||
+4
-3
@@ -25,12 +25,13 @@ import org.jetbrains.kotlin.test.KotlinTestUtils
|
|||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
private val LIBRARY_SRC_PATH = KotlinTestUtils.getHomeDirectory() + "/idea/idea-completion/testData/codeFragmentInLibrarySource/customLibrary/"
|
private val LIBRARY_SRC_PATH =
|
||||||
|
KotlinTestUtils.getHomeDirectory() + "/idea/idea-completion/testData/codeFragmentInLibrarySource/customLibrary/"
|
||||||
|
|
||||||
@RunWith(JUnit3WithIdeaConfigurationRunner::class)
|
@RunWith(JUnit3WithIdeaConfigurationRunner::class)
|
||||||
class CodeFragmentCompletionInLibraryTest : AbstractJvmBasicCompletionTest() {
|
class CodeFragmentCompletionInLibraryTest : AbstractJvmBasicCompletionTest() {
|
||||||
|
|
||||||
override fun getProjectDescriptor() = object: SdkAndMockLibraryProjectDescriptor(LIBRARY_SRC_PATH, false) {
|
override fun getProjectDescriptor() = object : SdkAndMockLibraryProjectDescriptor(LIBRARY_SRC_PATH, false) {
|
||||||
override fun configureModule(module: Module, model: ModifiableRootModel) {
|
override fun configureModule(module: Module, model: ModifiableRootModel) {
|
||||||
super.configureModule(module, model)
|
super.configureModule(module, model)
|
||||||
|
|
||||||
@@ -60,7 +61,7 @@ class CodeFragmentCompletionInLibraryTest : AbstractJvmBasicCompletionTest() {
|
|||||||
|
|
||||||
private fun testCompletionInLibraryCodeFragment(fragmentText: String, vararg completionDirectives: String) {
|
private fun testCompletionInLibraryCodeFragment(fragmentText: String, vararg completionDirectives: String) {
|
||||||
setupFixtureByCodeFragment(fragmentText)
|
setupFixtureByCodeFragment(fragmentText)
|
||||||
val directives = completionDirectives.map { "//$it" }.joinToString(separator = "\n")
|
val directives = completionDirectives.joinToString(separator = "\n") { "//$it" }
|
||||||
testCompletion(directives,
|
testCompletion(directives,
|
||||||
JvmPlatforms.unspecifiedJvmPlatform, { completionType, count -> myFixture.complete(completionType, count) })
|
JvmPlatforms.unspecifiedJvmPlatform, { completionType, count -> myFixture.complete(completionType, count) })
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user