More correct completion testing + fixed small bug in keyword completion

This commit is contained in:
Valentin Kipyatkov
2014-09-19 21:31:50 +04:00
committed by valentin
parent afbd1aeffc
commit e6ea0537c8
28 changed files with 131 additions and 106 deletions
@@ -120,7 +120,7 @@ class KeywordCompletion {
add(JetTokens.OUT_KEYWORD, InTypeParameterFirstChildFilter)
add(JetTokens.OBJECT_KEYWORD, inNonClassBlock, AfterClassInClassBodyFilter)
add(JetTokens.OBJECT_KEYWORD, inNonClassBlock, inClassBody, AfterClassInClassBodyFilter)
add(JetTokens.ELSE_KEYWORD, inNonClassBlock, inPropertyBody)
add(JetTokens.IF_KEYWORD, inNonClassBlock, inPropertyBody)
@@ -2,6 +2,7 @@ fun test() {
val <caret>
}
// INVOCATION_COUNT: 0
// NUMBER: 0
/* KT-4158 Type "var i" and press space. "var if" is auto-inserted. */
@@ -0,0 +1,4 @@
fun f<caret>
// INVOCATION_COUNT: 0
// NUMBER: 0
@@ -1,5 +1,6 @@
var <caret>
// INVOCATION_COUNT: 0
// NUMBER: 0
/* KT-4158 Type "var i" and press space. "var if" is auto-inserted. */
@@ -5,7 +5,7 @@ class TestClass {
}
// ABSENT: abstract, annotation, as, break, by, catch, class, continue, default, do
// ABSENT: else, enum, false, final, finally, for, fun, get, if, import, in, inline
// ABSENT: else, enum, false, final, finally, for, fun, get, if, import, in
// ABSENT: internal, is, null, object, open, out, override, package, private, protected, public
// ABSENT: ref, return, set, super, This, this, throw, trait, true, try, type, val, var
// ABSENT: vararg, when, where, while
+1 -1
View File
@@ -5,7 +5,7 @@ class TestClass {
}
// ABSENT: abstract, annotation, as, break, by, catch, class, continue, default, do
// ABSENT: else, enum, false, final, finally, for, fun, get, if, import, in, inline
// ABSENT: else, enum, false, final, finally, for, fun, get, if, import, in
// ABSENT: internal, is, null, object, open, out, override, package, private, protected, public
// ABSENT: ref, return, set, super, This, this, throw, trait, true, try, type, val, var
// ABSENT: vararg, when, where, while
@@ -7,8 +7,6 @@ public class Test {
}
}
// INVOCATION_COUNT: 1
// EXIST: abstract
/* // ABSENT: annotation */
// ABSENT: as
@@ -2,8 +2,6 @@ class TestClass {
<caret>
}
// INVOCATION_COUNT: 1
// EXIST: abstract
// ABSENT: annotation
// ABSENT: as
@@ -22,7 +22,6 @@ fun foo() {
// EXIST: if
// ABSENT: import
// EXIST: in
// EXIST: inline
// EXIST: internal
// EXIST: is
// EXIST: null
@@ -25,7 +25,6 @@ class TestSample() {
// ABSENT: if
// ABSENT: import
// ABSENT: in
// ABSENT: inline
// ABSENT: internal
// ABSENT: is
// ABSENT: null
@@ -22,7 +22,6 @@ fun test(<caret>) {
// ABSENT: if
// ABSENT: import
// ABSENT: in
// ABSENT: inline
// ABSENT: internal
// ABSENT: is
// ABSENT: null
@@ -5,7 +5,7 @@ class TestClass {
}
// ABSENT: abstract, annotation, as, break, by, catch, class, continue, default, do
// ABSENT: else, enum, false, final, finally, for, fun, get, if, import, in, inline
// ABSENT: else, enum, false, final, finally, for, fun, get, if, import, in
// ABSENT: internal, is, null, object, open, out, override, package, private, protected, public
// ABSENT: ref, return, set, super, This, this, throw, trait, true, try, type, val, var
// ABSENT: vararg, when, where, while
@@ -22,7 +22,6 @@ fun foo() {
// EXIST: if
// ABSENT: import
// EXIST: in
// EXIST: inline
// EXIST: internal
// EXIST: is
// EXIST: null
@@ -3,7 +3,7 @@ class TestClass {
}
// ABSENT: abstract, annotation, as, break, by, catch, class, continue, default, do
// ABSENT: else, enum, false, final, finally, for, fun, get, if, import, in, inline
// ABSENT: else, enum, false, final, finally, for, fun, get, if, import, in
// ABSENT: internal, is, null, object, open, out, override, package, private, protected, public
// ABSENT: ref, return, set, super, This, this, throw, trait, true, try, type, val, var
// ABSENT: vararg, when, where, while
@@ -17,6 +17,7 @@
package org.jetbrains.jet.completion;
import com.intellij.codeInsight.completion.CompletionType;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.testFramework.LightProjectDescriptor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.plugin.JdkAndMockLibraryProjectDescriptor;
@@ -35,9 +36,8 @@ public abstract class AbstractCompiledKotlinInJavaCompletionTest extends JetFixt
return new JdkAndMockLibraryProjectDescriptor(PluginTestCaseBase.getTestDataPathBase() + "/completion/injava/mockLib", false);
}
@NotNull
@Override
protected CompletionType completionType() {
return CompletionType.BASIC;
protected LookupElement[] complete(int invocationCount) {
return myFixture.complete(CompletionType.BASIC, invocationCount);
}
}
@@ -17,6 +17,7 @@
package org.jetbrains.jet.completion;
import com.intellij.codeInsight.completion.CompletionType;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.testFramework.LightProjectDescriptor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.plugin.JetStdJSProjectDescriptor;
@@ -34,7 +35,8 @@ public abstract class AbstractJSBasicCompletionTest extends JetFixtureCompletion
return TargetPlatform.JS;
}
@NotNull
@Override
protected CompletionType completionType() { return CompletionType.BASIC; }
protected LookupElement[] complete(int invocationCount) {
return myFixture.complete(CompletionType.BASIC, invocationCount);
}
}
@@ -17,6 +17,7 @@
package org.jetbrains.jet.completion;
import com.intellij.codeInsight.completion.CompletionType;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.testFramework.LightProjectDescriptor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.plugin.JetWithJdkAndRuntimeLightProjectDescriptor;
@@ -34,7 +35,8 @@ public abstract class AbstractJvmBasicCompletionTest extends JetFixtureCompletio
return TargetPlatform.JVM;
}
@NotNull
@Override
protected CompletionType completionType() { return CompletionType.BASIC; }
protected LookupElement[] complete(int invocationCount) {
return myFixture.complete(CompletionType.BASIC, invocationCount);
}
}
@@ -17,6 +17,7 @@
package org.jetbrains.jet.completion;
import com.intellij.codeInsight.completion.CompletionType;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.testFramework.LightProjectDescriptor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.plugin.JetWithJdkAndRuntimeLightProjectDescriptor;
@@ -34,7 +35,8 @@ public abstract class AbstractJvmSmartCompletionTest extends JetFixtureCompletio
return TargetPlatform.JVM;
}
@NotNull
@Override
protected CompletionType completionType() { return CompletionType.SMART; }
protected LookupElement[] complete(int invocationCount) {
return myFixture.complete(CompletionType.SMART, invocationCount);
}
}
@@ -17,6 +17,7 @@
package org.jetbrains.jet.completion;
import com.intellij.codeInsight.completion.CompletionType;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.testFramework.LightProjectDescriptor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.plugin.JdkAndMockLibraryProjectDescriptor;
@@ -40,7 +41,8 @@ public abstract class AbstractJvmWithLibBasicCompletionTest extends JetFixtureCo
return TargetPlatform.JVM;
}
@NotNull
@Override
protected CompletionType completionType() { return CompletionType.BASIC; }
protected LookupElement[] complete(int invocationCount) {
return myFixture.complete(CompletionType.BASIC, invocationCount);
}
}
@@ -1,40 +0,0 @@
/*
* Copyright 2010-2013 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;
import com.intellij.codeInsight.completion.CompletionType;
import com.intellij.testFramework.LightProjectDescriptor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.plugin.JetLightProjectDescriptor;
import org.jetbrains.jet.plugin.project.TargetPlatform;
public abstract class AbstractKeywordCompletionTest extends JetFixtureCompletionBaseTestCase {
@Override
public TargetPlatform getPlatform() {
return TargetPlatform.JVM;
}
@NotNull
@Override
protected CompletionType completionType() { return CompletionType.BASIC; }
@NotNull
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return JetLightProjectDescriptor.INSTANCE;
}
}
@@ -0,0 +1,37 @@
/*
* 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
import com.intellij.codeInsight.completion.CompletionType
import com.intellij.codeInsight.lookup.LookupElement
import org.jetbrains.jet.plugin.JetLightProjectDescriptor
import org.jetbrains.jet.plugin.completion.KeywordLookupObject
import org.jetbrains.jet.plugin.project.TargetPlatform
public abstract class AbstractKeywordCompletionTest : JetFixtureCompletionBaseTestCase() {
override fun getPlatform() = TargetPlatform.JVM
override fun complete(invocationCount: Int): Array<LookupElement>? {
val items = myFixture.complete(CompletionType.BASIC)
if (items == null) return null
return items.filter { it.getObject() is KeywordLookupObject }.copyToArray()
}
override fun getProjectDescriptor() = JetLightProjectDescriptor.INSTANCE
override fun defaultInvocationCount() = 1
}
@@ -17,6 +17,7 @@
package org.jetbrains.jet.completion;
import com.intellij.codeInsight.completion.CompletionType;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.testFramework.LightProjectDescriptor;
import com.intellij.util.ArrayUtil;
@@ -55,9 +56,8 @@ public abstract class AbstractKotlinSourceInJavaCompletionTest extends JetFixtur
return JAVA_LATEST;
}
@NotNull
@Override
protected CompletionType completionType() {
return CompletionType.BASIC;
protected LookupElement[] complete(int invocationCount) {
return myFixture.complete(CompletionType.BASIC, invocationCount);
}
}
@@ -42,7 +42,7 @@ public abstract class AbstractMultiFileJvmBasicCompletionTest extends KotlinComp
complete(invocationCount);
return myItems;
}
});
}, 0);
return Unit.INSTANCE$;
}
}
@@ -21,8 +21,8 @@ import org.jetbrains.jet.plugin.project.TargetPlatform
import org.junit.Assert
import org.jetbrains.jet.completion.ExpectedCompletionUtils
fun testCompletion(fileText: String, platform: TargetPlatform?, complete: (Int) -> Array<LookupElement>?) {
val invocationCount = ExpectedCompletionUtils.getInvocationCount(fileText) ?: 0
fun testCompletion(fileText: String, platform: TargetPlatform?, complete: (Int) -> Array<LookupElement>?, defaultInvocationCount: Int = 0) {
val invocationCount = ExpectedCompletionUtils.getInvocationCount(fileText) ?: defaultInvocationCount
val items = complete(invocationCount) ?: array()
ExpectedCompletionUtils.assertDirectivesValid(fileText)
@@ -17,13 +17,10 @@
package org.jetbrains.jet.completion;
import com.intellij.testFramework.TestDataPath;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.junit.runner.RunWith;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.test.InnerTestClasses;
import org.jetbrains.jet.test.TestMetadata;
import org.jetbrains.jet.JUnit3RunnerWithInners;
import org.junit.runner.RunWith;
import java.io.File;
import java.util.regex.Pattern;
@@ -450,6 +447,24 @@ public class JSBasicCompletionTestGenerated extends AbstractJSBasicCompletionTes
doTest(fileName);
}
@TestMetadata("NoAutoPopupInValName.kt")
public void testNoAutoPopupInValName() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/NoAutoPopupInValName.kt");
doTest(fileName);
}
@TestMetadata("NoAutopopupInFunName.kt")
public void testNoAutopopupInFunName() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/NoAutopopupInFunName.kt");
doTest(fileName);
}
@TestMetadata("NoAutopopupInVarName.kt")
public void testNoAutopopupInVarName() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/NoAutopopupInVarName.kt");
doTest(fileName);
}
@TestMetadata("NoClassNameDuplication.kt")
public void testNoClassNameDuplication() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/NoClassNameDuplication.kt");
@@ -17,11 +17,12 @@
package org.jetbrains.jet.completion;
import com.intellij.codeInsight.CodeInsightSettings;
import com.intellij.codeInsight.completion.CompletionType;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.io.FileUtil;
import kotlin.Function1;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.completion.util.UtilPackage;
import org.jetbrains.jet.plugin.JetLightCodeInsightFixtureTestCase;
import org.jetbrains.jet.plugin.caches.resolve.LibraryModificationTracker;
@@ -30,40 +31,37 @@ import org.jetbrains.jet.plugin.project.TargetPlatform;
import java.io.File;
public abstract class JetFixtureCompletionBaseTestCase extends JetLightCodeInsightFixtureTestCase {
private boolean autoCompleteSetting;
private Pair<Boolean, Boolean> savedAutoCompleteSettings;
@Override
protected void setUp() throws Exception {
super.setUp();
autoCompleteSetting = setAutoCompleteSetting(false);
savedAutoCompleteSettings = setAutoCompleteSetting(new Pair<Boolean, Boolean>(false, false));
}
@Override
protected void tearDown() throws Exception {
setAutoCompleteSetting(autoCompleteSetting);
setAutoCompleteSetting(savedAutoCompleteSettings);
super.tearDown();
}
private boolean setAutoCompleteSetting(boolean value){
private static Pair<Boolean, Boolean> setAutoCompleteSetting(Pair<Boolean, Boolean> value){
CodeInsightSettings settings = CodeInsightSettings.getInstance();
boolean oldValue;
if (completionType() == CompletionType.SMART){
oldValue = settings.AUTOCOMPLETE_ON_SMART_TYPE_COMPLETION;
settings.AUTOCOMPLETE_ON_SMART_TYPE_COMPLETION = value;
}
else {
oldValue = settings.AUTOCOMPLETE_COMMON_PREFIX;
settings.AUTOCOMPLETE_ON_CODE_COMPLETION = value;
}
return oldValue;
boolean oldValue1 = settings.AUTOCOMPLETE_ON_CODE_COMPLETION;
boolean oldValue2 = settings.AUTOCOMPLETE_ON_SMART_TYPE_COMPLETION;
settings.AUTOCOMPLETE_ON_CODE_COMPLETION = value.first;
settings.AUTOCOMPLETE_ON_SMART_TYPE_COMPLETION = value.second;
return new Pair<Boolean, Boolean>(oldValue1, oldValue2);
}
public abstract TargetPlatform getPlatform();
@NotNull
protected abstract CompletionType completionType();
@Nullable
protected abstract LookupElement[] complete(int invocationCount);
protected int defaultInvocationCount() { return 0; }
public void doTest(String testPath) throws Exception {
setUpFixture(testPath);
@@ -72,9 +70,9 @@ public abstract class JetFixtureCompletionBaseTestCase extends JetLightCodeInsig
UtilPackage.testCompletion(fileText, getPlatform(), new Function1<Integer, LookupElement[]>() {
@Override
public LookupElement[] invoke(Integer invocationCount) {
return myFixture.complete(completionType(), invocationCount);
return complete(invocationCount);
}
});
}, defaultInvocationCount());
}
protected void setUpFixture(@NotNull String testPath) {
@@ -17,10 +17,13 @@
package org.jetbrains.jet.completion;
import com.intellij.testFramework.TestDataPath;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.junit.runner.RunWith;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.test.InnerTestClasses;
import org.jetbrains.jet.test.TestMetadata;
import org.junit.runner.RunWith;
import org.jetbrains.jet.JUnit3RunnerWithInners;
import java.io.File;
import java.util.regex.Pattern;
@@ -447,6 +450,24 @@ public class JvmBasicCompletionTestGenerated extends AbstractJvmBasicCompletionT
doTest(fileName);
}
@TestMetadata("NoAutoPopupInValName.kt")
public void testNoAutoPopupInValName() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/NoAutoPopupInValName.kt");
doTest(fileName);
}
@TestMetadata("NoAutopopupInFunName.kt")
public void testNoAutopopupInFunName() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/NoAutopopupInFunName.kt");
doTest(fileName);
}
@TestMetadata("NoAutopopupInVarName.kt")
public void testNoAutopopupInVarName() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/NoAutopopupInVarName.kt");
doTest(fileName);
}
@TestMetadata("NoClassNameDuplication.kt")
public void testNoClassNameDuplication() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/NoClassNameDuplication.kt");
@@ -110,12 +110,6 @@ public class KeywordCompletionTestGenerated extends AbstractKeywordCompletionTes
doTest(fileName);
}
@TestMetadata("InFunctionNoCompletionInValName.kt")
public void testInFunctionNoCompletionInValName() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/keywords/InFunctionNoCompletionInValName.kt");
doTest(fileName);
}
@TestMetadata("InFunctionScope.kt")
public void testInFunctionScope() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/keywords/InFunctionScope.kt");
@@ -164,12 +158,6 @@ public class KeywordCompletionTestGenerated extends AbstractKeywordCompletionTes
doTest(fileName);
}
@TestMetadata("InTopNoCompletionInVarName.kt")
public void testInTopNoCompletionInVarName() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/keywords/InTopNoCompletionInVarName.kt");
doTest(fileName);
}
@TestMetadata("InTopProperty.kt")
public void testInTopProperty() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/keywords/InTopProperty.kt");