Test keywords completion with fixture tests
This commit is contained in:
@@ -30,6 +30,7 @@ import org.jetbrains.jet.codegen.generated.AbstractBlackBoxCodegenTest;
|
||||
import org.jetbrains.jet.completion.AbstractJavaCompletionTest;
|
||||
import org.jetbrains.jet.completion.AbstractJavaWithLibCompletionTest;
|
||||
import org.jetbrains.jet.completion.AbstractJetJSCompletionTest;
|
||||
import org.jetbrains.jet.completion.AbstractKeywordCompletionTest;
|
||||
import org.jetbrains.jet.jvm.compiler.*;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.AbstractLazyResolveDescriptorRendererTest;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.AbstractLazyResolveNamespaceComparingTest;
|
||||
@@ -244,6 +245,13 @@ public class GenerateTests {
|
||||
testModel("idea/testData/completion/basic/java", false, "doTest")
|
||||
);
|
||||
|
||||
generateTest(
|
||||
"idea/tests/",
|
||||
"JetKeywordCompletionTestGenerated",
|
||||
AbstractKeywordCompletionTest.class,
|
||||
testModel("idea/testData/completion/keywords", false, "doTest")
|
||||
);
|
||||
|
||||
generateTest(
|
||||
"idea/tests",
|
||||
"JetJavaLibCompletionTestGenerated",
|
||||
|
||||
@@ -7,8 +7,10 @@ public class Test {
|
||||
}
|
||||
}
|
||||
|
||||
// TIME: 1
|
||||
|
||||
// EXIST: abstract
|
||||
// ?ABSENT: annotation
|
||||
/* // ABSENT: annotation */
|
||||
// ABSENT: as
|
||||
// ABSENT: break
|
||||
// ABSENT: by
|
||||
|
||||
@@ -2,6 +2,8 @@ class TestClass {
|
||||
<caret>
|
||||
}
|
||||
|
||||
// TIME: 1
|
||||
|
||||
// EXIST: abstract
|
||||
// ABSENT: annotation
|
||||
// ABSENT: as
|
||||
|
||||
@@ -3,7 +3,7 @@ fun foo() {
|
||||
}
|
||||
|
||||
// ABSENT: abstract
|
||||
// ??ABSENT: annotation // java annotation namespace
|
||||
/* // ABSENT: annotation */
|
||||
// EXIST: as
|
||||
// EXIST: break
|
||||
// EXIST: by
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// for: KT-2170
|
||||
open class Foo {
|
||||
p<caret> val foo = 1
|
||||
}
|
||||
|
||||
// FOR: KT-2170
|
||||
// EXIST: private, public, protected
|
||||
@@ -3,7 +3,7 @@ fun foo() {
|
||||
}
|
||||
|
||||
// ABSENT: abstract
|
||||
// ??ABSENT: annotation // java annotation namespace
|
||||
/* // ABSENT: annotation */
|
||||
// EXIST: as
|
||||
// EXIST: break
|
||||
// EXIST: by
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleType;
|
||||
import com.intellij.openapi.module.StdModuleTypes;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.roots.ContentEntry;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.plugin.JetLightProjectDescriptor;
|
||||
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public abstract class AbstractKeywordCompletionTest extends JetFixtureCompletionBaseTestCase {
|
||||
@Override
|
||||
public ExpectedCompletionUtils.Platform getPlatform() {
|
||||
return ExpectedCompletionUtils.Platform.JAVA;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return JetLightProjectDescriptor.INSTANCE;
|
||||
}
|
||||
}
|
||||
@@ -249,7 +249,7 @@ public class ExpectedCompletionUtils {
|
||||
return InTextDirectivesUtils.getPrefixedInt(fileText, NUMBER_LINE_PREFIX);
|
||||
}
|
||||
|
||||
public static void assertNotContainsRenderedItems(CompletionProposal[] unexpected,LookupElement[] items) {
|
||||
public static void assertNotContainsRenderedItems(CompletionProposal[] unexpected, LookupElement[] items) {
|
||||
List<CompletionProposal> itemsInformation = getItemsInformation(items);
|
||||
String allItemsString = listToString(itemsInformation);
|
||||
|
||||
|
||||
@@ -1,112 +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.CodeCompletionHandlerBase;
|
||||
import com.intellij.codeInsight.completion.CompletionType;
|
||||
import com.intellij.codeInsight.completion.LightCompletionTestCase;
|
||||
import com.intellij.codeInsight.lookup.Lookup;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.LookupManager;
|
||||
import com.intellij.openapi.projectRoots.JavaSdk;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import org.apache.commons.lang.SystemUtils;
|
||||
import org.jetbrains.jet.InTextDirectivesUtils;
|
||||
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||
import org.jetbrains.jet.testing.ConfigLibraryUtil;
|
||||
import org.jetbrains.jet.utils.ExceptionUtils;
|
||||
|
||||
public abstract class JetCompletionTestBase extends LightCompletionTestCase {
|
||||
private CompletionType type;
|
||||
|
||||
@Override
|
||||
protected abstract String getTestDataPath();
|
||||
|
||||
protected void doTest() {
|
||||
try {
|
||||
String testName = getTestName(false);
|
||||
configureByFileNoComplete(testName + ".kt");
|
||||
|
||||
String fileText = getFile().getText();
|
||||
type = getCompletionType(testName, fileText);
|
||||
|
||||
boolean withKotlinRuntime = InTextDirectivesUtils.getPrefixedInt(fileText, "// RUNTIME:") != null;
|
||||
|
||||
try {
|
||||
if (withKotlinRuntime) {
|
||||
ConfigLibraryUtil.configureKotlinRuntime(getModule(), getFullJavaJDK());
|
||||
}
|
||||
|
||||
Integer completionTime = ExpectedCompletionUtils.getExecutionTime(fileText);
|
||||
|
||||
complete(completionTime == null ? 1 : completionTime);
|
||||
|
||||
ExpectedCompletionUtils.CompletionProposal[] expected = ExpectedCompletionUtils.itemsShouldExist(fileText);
|
||||
ExpectedCompletionUtils.CompletionProposal[] unexpected = ExpectedCompletionUtils.itemsShouldAbsent(fileText);
|
||||
Integer itemsNumber = ExpectedCompletionUtils.getExpectedNumber(fileText);
|
||||
|
||||
assertTrue("Should be some assertions about completion",
|
||||
expected.length != 0 || unexpected.length != 0 || itemsNumber != null);
|
||||
|
||||
if (myItems == null) {
|
||||
myItems = new LookupElement[0];
|
||||
}
|
||||
|
||||
ExpectedCompletionUtils.assertContainsRenderedItems(expected, myItems, ExpectedCompletionUtils.isWithOrder(fileText));
|
||||
ExpectedCompletionUtils.assertNotContainsRenderedItems(unexpected, myItems);
|
||||
|
||||
if (itemsNumber != null) {
|
||||
assertEquals(
|
||||
String.format(
|
||||
"Invalid number of completion items: %s",
|
||||
ExpectedCompletionUtils.listToString(ExpectedCompletionUtils.getItemsInformation(myItems))),
|
||||
itemsNumber.intValue(), myItems.length);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if (withKotlinRuntime) {
|
||||
ConfigLibraryUtil.unConfigureKotlinRuntime(getModule(), getProjectJDK());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw ExceptionUtils.rethrow(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected CompletionType getCompletionType(String testName, String fileText) {
|
||||
return (testName.startsWith("Smart")) ? CompletionType.SMART : CompletionType.BASIC;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Sdk getProjectJDK() {
|
||||
return PluginTestCaseBase.jdkFromIdeaHome();
|
||||
}
|
||||
|
||||
protected static Sdk getFullJavaJDK() {
|
||||
return JavaSdk.getInstance().createJdk("JDK", SystemUtils.getJavaHome().getAbsolutePath());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void complete(int time) {
|
||||
new CodeCompletionHandlerBase(type, false, false, true).invokeCompletion(getProject(), getEditor(), time, false, false);
|
||||
|
||||
Lookup lookup = LookupManager.getActiveLookup(myEditor);
|
||||
myItems = lookup == null ? null : lookup.getItems().toArray(LookupElement.EMPTY_ARRAY);
|
||||
myPrefix = lookup == null ? null : lookup.itemPattern(lookup.getItems().get(0));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* 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 junit.framework.Assert;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.test.InnerTestClasses;
|
||||
import org.jetbrains.jet.test.TestMetadata;
|
||||
|
||||
import org.jetbrains.jet.completion.AbstractKeywordCompletionTest;
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("idea/testData/completion/keywords")
|
||||
public class JetKeywordCompletionTestGenerated extends AbstractKeywordCompletionTest {
|
||||
@TestMetadata("AfterClassProperty.kt")
|
||||
public void testAfterClassProperty() throws Exception {
|
||||
doTest("idea/testData/completion/keywords/AfterClassProperty.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("AfterDot.kt")
|
||||
public void testAfterDot() throws Exception {
|
||||
doTest("idea/testData/completion/keywords/AfterDot.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("AfterSpaceAndDot.kt")
|
||||
public void testAfterSpaceAndDot() throws Exception {
|
||||
doTest("idea/testData/completion/keywords/AfterSpaceAndDot.kt");
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInKeywords() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/completion/keywords"), Pattern.compile("^(.+)\\.kt$"), false);
|
||||
}
|
||||
|
||||
@TestMetadata("classObject.kt")
|
||||
public void testClassObject() throws Exception {
|
||||
doTest("idea/testData/completion/keywords/classObject.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InBlockComment.kt")
|
||||
public void testInBlockComment() throws Exception {
|
||||
doTest("idea/testData/completion/keywords/InBlockComment.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InChar.kt")
|
||||
public void testInChar() throws Exception {
|
||||
doTest("idea/testData/completion/keywords/InChar.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InClassBeforeFun.kt")
|
||||
public void testInClassBeforeFun() throws Exception {
|
||||
doTest("idea/testData/completion/keywords/InClassBeforeFun.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InClassProperty.kt")
|
||||
public void testInClassProperty() throws Exception {
|
||||
doTest("idea/testData/completion/keywords/InClassProperty.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InClassScope.kt")
|
||||
public void testInClassScope() throws Exception {
|
||||
doTest("idea/testData/completion/keywords/InClassScope.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InClassTypeParameters.kt")
|
||||
public void testInClassTypeParameters() throws Exception {
|
||||
doTest("idea/testData/completion/keywords/InClassTypeParameters.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InFunctionName.kt")
|
||||
public void testInFunctionName() throws Exception {
|
||||
doTest("idea/testData/completion/keywords/InFunctionName.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InFunctionScope.kt")
|
||||
public void testInFunctionScope() throws Exception {
|
||||
doTest("idea/testData/completion/keywords/InFunctionScope.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InFunctionTypeReference.kt")
|
||||
public void testInFunctionTypeReference() throws Exception {
|
||||
doTest("idea/testData/completion/keywords/InFunctionTypeReference.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InMethodParametersList.kt")
|
||||
public void testInMethodParametersList() throws Exception {
|
||||
doTest("idea/testData/completion/keywords/InMethodParametersList.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InModifierListInsideClass.kt")
|
||||
public void testInModifierListInsideClass() throws Exception {
|
||||
doTest("idea/testData/completion/keywords/InModifierListInsideClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InNotFinishedGenericWithFunAfter.kt")
|
||||
public void testInNotFinishedGenericWithFunAfter() throws Exception {
|
||||
doTest("idea/testData/completion/keywords/InNotFinishedGenericWithFunAfter.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InParametersList.kt")
|
||||
public void testInParametersList() throws Exception {
|
||||
doTest("idea/testData/completion/keywords/InParametersList.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InPropertyTypeReference.kt")
|
||||
public void testInPropertyTypeReference() throws Exception {
|
||||
doTest("idea/testData/completion/keywords/InPropertyTypeReference.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InString.kt")
|
||||
public void testInString() throws Exception {
|
||||
doTest("idea/testData/completion/keywords/InString.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InTopProperty.kt")
|
||||
public void testInTopProperty() throws Exception {
|
||||
doTest("idea/testData/completion/keywords/InTopProperty.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InTopScopeAfterPackage.kt")
|
||||
public void testInTopScopeAfterPackage() throws Exception {
|
||||
doTest("idea/testData/completion/keywords/InTopScopeAfterPackage.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InTypeScope.kt")
|
||||
public void testInTypeScope() throws Exception {
|
||||
doTest("idea/testData/completion/keywords/InTypeScope.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("LineComment.kt")
|
||||
public void testLineComment() throws Exception {
|
||||
doTest("idea/testData/completion/keywords/LineComment.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("NoCompletionForCapitalPrefix.kt")
|
||||
public void testNoCompletionForCapitalPrefix() throws Exception {
|
||||
doTest("idea/testData/completion/keywords/NoCompletionForCapitalPrefix.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("PropertySetterGetter.kt")
|
||||
public void testPropertySetterGetter() throws Exception {
|
||||
doTest("idea/testData/completion/keywords/PropertySetterGetter.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("TopScope.kt")
|
||||
public void testTopScope() throws Exception {
|
||||
doTest("idea/testData/completion/keywords/TopScope.kt");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,137 +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 org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Test auto completion messages
|
||||
*/
|
||||
public class KeywordsCompletionTest extends JetCompletionTestBase {
|
||||
|
||||
public void testAfterClassProperty() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testAfterDot() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testAfterSpaceAndDot() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testclassObject() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testInBlockComment() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testInChar() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testInClassBeforeFun() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testInClassProperty() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testInClassScope() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testInClassTypeParameters() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testInFunctionName() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testInFunctionScope() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testInNotFinishedGenericWithFunAfter() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testInFunctionTypeReference() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testInParametersList() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testInPropertyTypeReference() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testInMethodParametersList() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testInModifierListInsideClass() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testInString() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testInTopProperty() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testInTopScopeAfterPackage() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testInTypeScope() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testLineComment() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNoCompletionForCapitalPrefix() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testPropertySetterGetter() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testTopScope() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return new File(PluginTestCaseBase.getTestDataPathBase(), "/completion/keywords").getPath() +
|
||||
File.separator;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user