Behavior on typing chars with code completion lookup is completely defined by our own handler + added tests for this handler + fixed a few bugs related to this behavior
This commit is contained in:
@@ -19,6 +19,7 @@ package org.jetbrains.jet.completion;
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.jet.JUnit3RunnerWithInners;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.test.InnerTestClasses;
|
||||
import org.jetbrains.jet.test.TestMetadata;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
|
||||
+26
-21
@@ -16,33 +16,16 @@
|
||||
|
||||
package org.jetbrains.jet.completion.handlers
|
||||
|
||||
import org.jetbrains.jet.plugin.JetLightCodeInsightFixtureTestCase
|
||||
import com.intellij.codeInsight.completion.CompletionType
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager
|
||||
import org.jetbrains.jet.plugin.formatter.JetCodeStyleSettings
|
||||
import com.intellij.codeInsight.lookup.LookupElement
|
||||
import java.io.File
|
||||
import org.jetbrains.jet.plugin.PluginTestCaseBase
|
||||
import com.intellij.codeInsight.lookup.impl.LookupImpl
|
||||
import com.intellij.codeInsight.lookup.LookupEvent
|
||||
import com.intellij.openapi.command.WriteCommandAction
|
||||
import com.intellij.codeInsight.lookup.LookupManager
|
||||
import com.intellij.codeInsight.lookup.LookupElementPresentation
|
||||
import org.junit.Assert
|
||||
import com.intellij.openapi.application.Result
|
||||
import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture
|
||||
import kotlin.properties.Delegates
|
||||
import org.jetbrains.jet.InTextDirectivesUtils
|
||||
|
||||
public abstract class AbstractSmartCompletionHandlerTest() : CompletionHandlerTestBase() {
|
||||
public abstract class AbstractCompletionHandlerTest() : CompletionHandlerTestBase() {
|
||||
private val INVOCATION_COUNT_PREFIX = "INVOCATION_COUNT:"
|
||||
private val LOOKUP_STRING_PREFIX = "ELEMENT:"
|
||||
private val ELEMENT_TEXT_PREFIX = "ELEMENT_TEXT:"
|
||||
private val TAIL_TEXT_PREFIX = "TAIL_TEXT:"
|
||||
private val COMPLETION_CHAR_PREFIX = "CHAR:"
|
||||
|
||||
override val completionType: CompletionType = CompletionType.SMART
|
||||
override val testDataRelativePath: String = "/completion/handlers/smart"
|
||||
private val COMPLETION_TYPE_PREFIX = "COMPLETION_TYPE:"
|
||||
|
||||
protected fun doTest(testPath: String) {
|
||||
fixture.configureByFile(testPath)
|
||||
@@ -52,12 +35,34 @@ public abstract class AbstractSmartCompletionHandlerTest() : CompletionHandlerTe
|
||||
val lookupString = InTextDirectivesUtils.findStringWithPrefixes(fileText, LOOKUP_STRING_PREFIX)
|
||||
val itemText = InTextDirectivesUtils.findStringWithPrefixes(fileText, ELEMENT_TEXT_PREFIX)
|
||||
val tailText = InTextDirectivesUtils.findStringWithPrefixes(fileText, TAIL_TEXT_PREFIX)
|
||||
|
||||
val completionCharString = InTextDirectivesUtils.findStringWithPrefixes(fileText, COMPLETION_CHAR_PREFIX)
|
||||
val completionChar = when(completionCharString) {
|
||||
"\\n", null -> '\n'
|
||||
"\\t" -> '\t'
|
||||
else -> error("Uknown completion char")
|
||||
else -> completionCharString.singleOrNull() ?: error("Incorrect completion char: \"$completionCharString\"")
|
||||
}
|
||||
doTestWithTextLoaded(invocationCount, lookupString, itemText, tailText, completionChar)
|
||||
|
||||
val completionTypeString = InTextDirectivesUtils.findStringWithPrefixes(fileText, COMPLETION_TYPE_PREFIX)
|
||||
val completionType = when (completionTypeString) {
|
||||
"BASIC" -> CompletionType.BASIC
|
||||
"SMART" -> CompletionType.SMART
|
||||
null -> defaultCompletionType
|
||||
else -> error("Unknown completion type: $completionTypeString")
|
||||
}
|
||||
|
||||
doTestWithTextLoaded(completionType, invocationCount, lookupString, itemText, tailText, completionChar)
|
||||
}
|
||||
|
||||
protected abstract val defaultCompletionType: CompletionType
|
||||
}
|
||||
|
||||
public abstract class AbstractSmartCompletionHandlerTest() : AbstractCompletionHandlerTest() {
|
||||
override val defaultCompletionType: CompletionType = CompletionType.SMART
|
||||
override val testDataRelativePath: String = "/completion/handlers/smart"
|
||||
}
|
||||
|
||||
public abstract class AbstractCompletionCharFilterTest() : AbstractCompletionHandlerTest() {
|
||||
override val defaultCompletionType: CompletionType = CompletionType.BASIC
|
||||
override val testDataRelativePath: String = "/completion/handlers/charFilter"
|
||||
}
|
||||
|
||||
@@ -21,9 +21,21 @@ import org.jetbrains.jet.plugin.formatter.JetCodeStyleSettings
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager
|
||||
|
||||
public class BasicCompletionHandlerTest : CompletionHandlerTestBase(){
|
||||
override val completionType: CompletionType = CompletionType.BASIC
|
||||
override val testDataRelativePath: String = "/completion/handlers"
|
||||
|
||||
private fun doTest() {
|
||||
doTest(2, "*", null, null, '\n')
|
||||
}
|
||||
|
||||
private fun doTest(time: Int, lookupString: String?, tailText: String?, completionChar: Char) {
|
||||
doTest(time, lookupString, null, tailText, completionChar)
|
||||
}
|
||||
|
||||
private fun doTest(time: Int, lookupString: String?, itemText: String?, tailText: String?, completionChar: Char) {
|
||||
fixture.configureByFile(fileName())
|
||||
doTestWithTextLoaded(CompletionType.BASIC, time, lookupString, itemText, tailText, completionChar)
|
||||
}
|
||||
|
||||
fun testClassCompletionImport() = doTest(2, "SortedSet", null, '\n')
|
||||
|
||||
fun testClassCompletionInMiddle() = doTest(1, "TimeZone", " (java.util)", '\t')
|
||||
@@ -48,9 +60,9 @@ public class BasicCompletionHandlerTest : CompletionHandlerTestBase(){
|
||||
|
||||
fun testNamedParametersCompletion() = doTest()
|
||||
|
||||
fun testNamedParametersCompletionOnEqual() = doTest(0, "paramTest =", null, '=')
|
||||
fun testNamedParametersCompletionOnEqual() = doTest(0, "paramTest", "paramTest =", null, '=')
|
||||
|
||||
fun testNamedParameterKeywordName() = doTest(1, "class =", null, '\n')
|
||||
fun testNamedParameterKeywordName() = doTest(1, "class", "class =", null, '\n')
|
||||
|
||||
fun testInsertJavaClassImport() = doTest()
|
||||
|
||||
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright 2010-2014 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.jet.completion.handlers;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.jet.JUnit3RunnerWithInners;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.test.InnerTestClasses;
|
||||
import org.jetbrains.jet.test.TestMetadata;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("idea/testData/completion/handlers/charFilter")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class CompletionCharFilterTestGenerated extends AbstractCompletionCharFilterTest {
|
||||
public void testAllFilesPresentInCharFilter() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/completion/handlers/charFilter"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("Colon.kt")
|
||||
public void testColon() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/handlers/charFilter/Colon.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("Comma1.kt")
|
||||
public void testComma1() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/handlers/charFilter/Comma1.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("Comma2.kt")
|
||||
public void testComma2() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/handlers/charFilter/Comma2.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ConstructorWithLambdaArg1.kt")
|
||||
public void testConstructorWithLambdaArg1() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/handlers/charFilter/ConstructorWithLambdaArg1.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ConstructorWithLambdaArg2.kt")
|
||||
public void testConstructorWithLambdaArg2() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/handlers/charFilter/ConstructorWithLambdaArg2.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("Dot.kt")
|
||||
public void testDot() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/handlers/charFilter/Dot.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("FunctionWithLambdaArg1.kt")
|
||||
public void testFunctionWithLambdaArg1() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/handlers/charFilter/FunctionWithLambdaArg1.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("FunctionWithLambdaArg2.kt")
|
||||
public void testFunctionWithLambdaArg2() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/handlers/charFilter/FunctionWithLambdaArg2.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("LParenth.kt")
|
||||
public void testLParenth() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/handlers/charFilter/LParenth.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("NamedParameter1.kt")
|
||||
public void testNamedParameter1() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/handlers/charFilter/NamedParameter1.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("NamedParameter2.kt")
|
||||
public void testNamedParameter2() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/handlers/charFilter/NamedParameter2.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("RangeTyping.kt")
|
||||
public void testRangeTyping() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/handlers/charFilter/RangeTyping.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("Space.kt")
|
||||
public void testSpace() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/handlers/charFilter/Space.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
@@ -31,24 +31,19 @@ import com.intellij.openapi.application.Result
|
||||
import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture
|
||||
|
||||
public abstract class CompletionHandlerTestBase() : JetLightCodeInsightFixtureTestCase() {
|
||||
protected abstract val completionType : CompletionType
|
||||
protected abstract val testDataRelativePath: String
|
||||
|
||||
protected val fixture: JavaCodeInsightTestFixture
|
||||
get() = myFixture
|
||||
|
||||
protected fun doTest() : Unit = doTest(2, "*", null, null, '\n')
|
||||
|
||||
protected fun doTest(time: Int, lookupString: String?, tailText: String?, completionChar: Char) {
|
||||
doTest(time, lookupString, null, tailText, completionChar)
|
||||
}
|
||||
|
||||
protected fun doTest(time: Int, lookupString: String?, itemText: String?, tailText: String?, completionChar: Char) {
|
||||
fixture.configureByFile(fileName())
|
||||
doTestWithTextLoaded(time, lookupString, itemText, tailText, completionChar)
|
||||
}
|
||||
|
||||
protected fun doTestWithTextLoaded(time: Int, lookupString: String?, itemText: String?, tailText: String?, completionChar: Char) {
|
||||
protected fun doTestWithTextLoaded(
|
||||
completionType: CompletionType,
|
||||
time: Int,
|
||||
lookupString: String?,
|
||||
itemText: String?,
|
||||
tailText: String?,
|
||||
completionChar: Char
|
||||
) {
|
||||
fixture.complete(completionType, time)
|
||||
|
||||
if (lookupString != null || itemText != null || tailText != null) {
|
||||
@@ -126,7 +121,9 @@ public abstract class CompletionHandlerTestBase() : JetLightCodeInsightFixtureTe
|
||||
|
||||
protected fun selectItem(item: LookupElement?, completionChar: Char) {
|
||||
val lookup = (fixture.getLookup() as LookupImpl)
|
||||
lookup.setCurrentItem(item)
|
||||
if (lookup.getCurrentItem() != item) { // do not touch selection if not changed - important for char filter tests
|
||||
lookup.setCurrentItem(item)
|
||||
}
|
||||
if (LookupEvent.isSpecialCompletionChar(completionChar)) {
|
||||
(object : WriteCommandAction.Simple<Any>(getProject()) {
|
||||
protected override fun run(result: Result<Any>) {
|
||||
|
||||
Reference in New Issue
Block a user