From c4f7bf6815134e0ecfa2bebad1b942ce6a0f5db6 Mon Sep 17 00:00:00 2001 From: Natalia Ukhorskaya Date: Thu, 5 Mar 2015 16:09:03 +0300 Subject: [PATCH] Add test for inserting imports in JetCodeFragment after completion --- .../handlers/runtimeCast/InsertImport.kt | 6 ++++++ .../handlers/runtimeCast/InsertImport.kt.after | 1 + .../runtimeCast/InsertImport.kt.after.imports | 1 + .../runtimeCast/InsertImport.kt.fragment | 1 + .../handlers/AbstractCompletionHandlerTests.kt | 2 +- .../AbstractEditorForEvaluateExpressionTest.kt | 18 ++++++++++++++++++ ...FragmentCompletionHandlerTestGenerated.java | 6 ++++++ 7 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 idea/testData/completion/handlers/runtimeCast/InsertImport.kt create mode 100644 idea/testData/completion/handlers/runtimeCast/InsertImport.kt.after create mode 100644 idea/testData/completion/handlers/runtimeCast/InsertImport.kt.after.imports create mode 100644 idea/testData/completion/handlers/runtimeCast/InsertImport.kt.fragment diff --git a/idea/testData/completion/handlers/runtimeCast/InsertImport.kt b/idea/testData/completion/handlers/runtimeCast/InsertImport.kt new file mode 100644 index 00000000000..ade799a5501 --- /dev/null +++ b/idea/testData/completion/handlers/runtimeCast/InsertImport.kt @@ -0,0 +1,6 @@ +fun main(args: Array) { + val a = 1 +} + +// ELEMENT: ArrayList +// TAIL_TEXT: (java.util) \ No newline at end of file diff --git a/idea/testData/completion/handlers/runtimeCast/InsertImport.kt.after b/idea/testData/completion/handlers/runtimeCast/InsertImport.kt.after new file mode 100644 index 00000000000..cf172a911d3 --- /dev/null +++ b/idea/testData/completion/handlers/runtimeCast/InsertImport.kt.after @@ -0,0 +1 @@ +ArrayList \ No newline at end of file diff --git a/idea/testData/completion/handlers/runtimeCast/InsertImport.kt.after.imports b/idea/testData/completion/handlers/runtimeCast/InsertImport.kt.after.imports new file mode 100644 index 00000000000..9596157ef46 --- /dev/null +++ b/idea/testData/completion/handlers/runtimeCast/InsertImport.kt.after.imports @@ -0,0 +1 @@ +import java.util.ArrayList \ No newline at end of file diff --git a/idea/testData/completion/handlers/runtimeCast/InsertImport.kt.fragment b/idea/testData/completion/handlers/runtimeCast/InsertImport.kt.fragment new file mode 100644 index 00000000000..d29f3931df9 --- /dev/null +++ b/idea/testData/completion/handlers/runtimeCast/InsertImport.kt.fragment @@ -0,0 +1 @@ +ArrayLis \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/completion/handlers/AbstractCompletionHandlerTests.kt b/idea/tests/org/jetbrains/kotlin/completion/handlers/AbstractCompletionHandlerTests.kt index cfcd1b0a2ad..aeb568153b2 100644 --- a/idea/tests/org/jetbrains/kotlin/completion/handlers/AbstractCompletionHandlerTests.kt +++ b/idea/tests/org/jetbrains/kotlin/completion/handlers/AbstractCompletionHandlerTests.kt @@ -30,7 +30,7 @@ public abstract class AbstractCompletionHandlerTest(private val defaultCompletio private val COMPLETION_CHAR_PREFIX = "CHAR:" private val COMPLETION_TYPE_PREFIX = "COMPLETION_TYPE:" - protected fun doTest(testPath: String) { + protected open fun doTest(testPath: String) { setUpFixture(testPath) val fileText = FileUtil.loadFile(File(testPath)) diff --git a/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/AbstractEditorForEvaluateExpressionTest.kt b/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/AbstractEditorForEvaluateExpressionTest.kt index a74a63778ea..4a94ab3dea6 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/AbstractEditorForEvaluateExpressionTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/AbstractEditorForEvaluateExpressionTest.kt @@ -34,6 +34,7 @@ import org.jetbrains.kotlin.completion.ExpectedCompletionUtils import org.jetbrains.kotlin.psi.JetElement import org.jetbrains.kotlin.completion.handlers.AbstractCompletionHandlerTest import com.intellij.codeInsight.completion.CompletionType +import com.intellij.openapi.util.text.StringUtil import org.jetbrains.kotlin.resolve.JetModuleUtil import org.jetbrains.kotlin.resolve.QualifiedExpressionResolver import org.jetbrains.kotlin.resolve.BindingTraceContext @@ -42,6 +43,8 @@ import org.jetbrains.kotlin.idea.caches.resolve.* import com.intellij.psi.* import com.intellij.psi.util.PsiModificationTracker import com.intellij.psi.impl.PsiModificationTrackerImpl +import org.jetbrains.kotlin.test.JetTestUtils +import kotlin.test.fail public abstract class AbstractCodeFragmentHighlightingTest : AbstractJetPsiCheckerTest() { override fun doTest(filePath: String) { @@ -82,6 +85,21 @@ public abstract class AbstractCodeFragmentCompletionHandlerTest : AbstractComple override fun setUpFixture(testPath: String) { myFixture.configureByCodeFragment(testPath) } + + override fun doTest(testPath: String) { + super.doTest(testPath) + val fragment = myFixture.getFile() as JetCodeFragment + + val importList = fragment.getImportList() + val fragmentAfterFile = File(testPath + ".after.imports") + + if (importList != null && fragmentAfterFile.exists()) { + JetTestUtils.assertEqualsToFile(fragmentAfterFile, StringUtil.convertLineSeparators(importList.getText())) + } + else if (fragmentAfterFile.exists()) { + fail("ImportList is empty") + } + } } private fun JavaCodeInsightTestFixture.configureByCodeFragment(filePath: String) { diff --git a/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/CodeFragmentCompletionHandlerTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/CodeFragmentCompletionHandlerTestGenerated.java index bed52d19677..6883348ae46 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/CodeFragmentCompletionHandlerTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/CodeFragmentCompletionHandlerTestGenerated.java @@ -53,4 +53,10 @@ public class CodeFragmentCompletionHandlerTestGenerated extends AbstractCodeFrag String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/handlers/runtimeCast/InsertFunction.kt"); doTest(fileName); } + + @TestMetadata("InsertImport.kt") + public void testInsertImport() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/handlers/runtimeCast/InsertImport.kt"); + doTest(fileName); + } }