Added test for auto-import fix in code fragment
This commit is contained in:
@@ -390,6 +390,10 @@ fun main(args: Array<String>) {
|
||||
model("checker/codeFragments/imports", testMethod = "doTestWithImport", extension = "kt")
|
||||
}
|
||||
|
||||
testClass<AbstractCodeFragmentAutoImportTest>() {
|
||||
model("quickfix.special/codeFragmentAutoImport", extension = "kt", recursive = false)
|
||||
}
|
||||
|
||||
testClass<AbstractJetJsCheckerTest>() {
|
||||
model("checker/js")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// WITH_RUNTIME
|
||||
import java.util.concurrent.locks.*
|
||||
|
||||
fun foo(lock: ReentrantReadWriteLock) {
|
||||
<caret>val v = 1
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
lock.read<caret>()
|
||||
+1
@@ -0,0 +1 @@
|
||||
import kotlin.concurrent.read
|
||||
+1
@@ -0,0 +1 @@
|
||||
lock.read<caret>()
|
||||
+38
-8
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.idea.caches.resolve.resolveImportReference
|
||||
import org.jetbrains.kotlin.idea.completion.test.AbstractJvmBasicCompletionTest
|
||||
import org.jetbrains.kotlin.idea.completion.test.ExpectedCompletionUtils
|
||||
import org.jetbrains.kotlin.idea.completion.test.handlers.AbstractCompletionHandlerTest
|
||||
import org.jetbrains.kotlin.idea.test.JetWithJdkAndRuntimeLightProjectDescriptor
|
||||
import org.jetbrains.kotlin.idea.util.ImportInsertHelper
|
||||
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
@@ -36,6 +37,8 @@ import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||
import org.jetbrains.kotlin.test.JetTestUtils
|
||||
import java.io.File
|
||||
import kotlin.test.assertNull
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
public abstract class AbstractCodeFragmentHighlightingTest : AbstractJetPsiCheckerTest() {
|
||||
override fun doTest(filePath: String) {
|
||||
@@ -73,17 +76,44 @@ public abstract class AbstractCodeFragmentCompletionHandlerTest : AbstractComple
|
||||
|
||||
override fun doTest(testPath: String) {
|
||||
super.doTest(testPath)
|
||||
|
||||
val fragment = myFixture.getFile() as KtCodeFragment
|
||||
fragment.checkImports(testPath)
|
||||
}
|
||||
}
|
||||
|
||||
val importList = fragment.importsAsImportList()
|
||||
val fragmentAfterFile = File(testPath + ".after.imports")
|
||||
public abstract class AbstractCodeFragmentAutoImportTest : AbstractJetPsiCheckerTest() {
|
||||
override fun doTest(filePath: String) {
|
||||
myFixture.configureByCodeFragment(filePath)
|
||||
myFixture.doHighlighting()
|
||||
|
||||
if (importList != null && fragmentAfterFile.exists()) {
|
||||
JetTestUtils.assertEqualsToFile(fragmentAfterFile, StringUtil.convertLineSeparators(importList.getText()))
|
||||
}
|
||||
else if (fragmentAfterFile.exists()) {
|
||||
fail("ImportList is empty")
|
||||
}
|
||||
val importFix = myFixture.availableIntentions.singleOrNull { it.familyName == "Import" }
|
||||
?: error("No import fix available")
|
||||
importFix.invoke(project, editor, file)
|
||||
|
||||
myFixture.checkResultByFile(filePath + ".after")
|
||||
|
||||
val fragment = myFixture.file as KtCodeFragment
|
||||
fragment.checkImports(testDataPath + File.separator + filePath)
|
||||
|
||||
val fixAfter = myFixture.availableIntentions.firstOrNull { it.familyName == "Import" }
|
||||
assertNull(fixAfter, "No import fix should be available after")
|
||||
}
|
||||
|
||||
override fun getProjectDescriptor() = JetWithJdkAndRuntimeLightProjectDescriptor.INSTANCE
|
||||
override fun getTestDataPath() = JetTestUtils.getHomeDirectory()
|
||||
}
|
||||
|
||||
private fun KtCodeFragment.checkImports(testPath: String) {
|
||||
val importList = importsAsImportList()
|
||||
val importsText = StringUtil.convertLineSeparators(importList?.text ?: "")
|
||||
val fragmentAfterFile = File(testPath + ".after.imports")
|
||||
|
||||
if (fragmentAfterFile.exists()) {
|
||||
JetTestUtils.assertEqualsToFile(fragmentAfterFile, importsText)
|
||||
}
|
||||
else {
|
||||
assertTrue(importsText.isEmpty(), "Unexpected imports found: $importsText" )
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.debugger.evaluate;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
|
||||
import org.jetbrains.kotlin.test.JetTestUtils;
|
||||
import org.jetbrains.kotlin.test.TestMetadata;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("idea/testData/quickfix.special/codeFragmentAutoImport")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class CodeFragmentAutoImportTestGenerated extends AbstractCodeFragmentAutoImportTest {
|
||||
public void testAllFilesPresentInCodeFragmentAutoImport() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix.special/codeFragmentAutoImport"), Pattern.compile("^(.+)\\.kt$"), false);
|
||||
}
|
||||
|
||||
@TestMetadata("ExtensionFun.kt")
|
||||
public void testExtensionFun() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix.special/codeFragmentAutoImport/ExtensionFun.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user