From 7f8e0e88035b050ec20f3b0d4eee3bd552cb86e5 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Thu, 11 Apr 2013 14:38:52 +0400 Subject: [PATCH] Test keywords completion with fixture tests --- .../jet/generators/tests/GenerateTests.java | 8 + .../completion/keywords/InClassBeforeFun.kt | 4 +- .../completion/keywords/InClassScope.kt | 2 + .../completion/keywords/InFunctionScope.kt | 2 +- .../keywords/InModifierListInsideClass.kt | 2 +- .../completion/keywords/InTypeScope.kt | 2 +- .../AbstractKeywordCompletionTest.java | 43 +++++ .../completion/ExpectedCompletionUtils.java | 2 +- .../jet/completion/JetCompletionTestBase.java | 112 ------------ .../JetKeywordCompletionTestGenerated.java | 169 ++++++++++++++++++ .../completion/KeywordsCompletionTest.java | 137 -------------- 11 files changed, 229 insertions(+), 254 deletions(-) create mode 100644 idea/tests/org/jetbrains/jet/completion/AbstractKeywordCompletionTest.java delete mode 100644 idea/tests/org/jetbrains/jet/completion/JetCompletionTestBase.java create mode 100644 idea/tests/org/jetbrains/jet/completion/JetKeywordCompletionTestGenerated.java delete mode 100644 idea/tests/org/jetbrains/jet/completion/KeywordsCompletionTest.java diff --git a/generators/org/jetbrains/jet/generators/tests/GenerateTests.java b/generators/org/jetbrains/jet/generators/tests/GenerateTests.java index 863b01725ed..855c895be07 100644 --- a/generators/org/jetbrains/jet/generators/tests/GenerateTests.java +++ b/generators/org/jetbrains/jet/generators/tests/GenerateTests.java @@ -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", diff --git a/idea/testData/completion/keywords/InClassBeforeFun.kt b/idea/testData/completion/keywords/InClassBeforeFun.kt index 681e7a69e34..663ecb4e725 100644 --- a/idea/testData/completion/keywords/InClassBeforeFun.kt +++ b/idea/testData/completion/keywords/InClassBeforeFun.kt @@ -7,8 +7,10 @@ public class Test { } } +// TIME: 1 + // EXIST: abstract -// ?ABSENT: annotation +/* // ABSENT: annotation */ // ABSENT: as // ABSENT: break // ABSENT: by diff --git a/idea/testData/completion/keywords/InClassScope.kt b/idea/testData/completion/keywords/InClassScope.kt index 410d33e3392..cb649863433 100644 --- a/idea/testData/completion/keywords/InClassScope.kt +++ b/idea/testData/completion/keywords/InClassScope.kt @@ -2,6 +2,8 @@ class TestClass { } +// TIME: 1 + // EXIST: abstract // ABSENT: annotation // ABSENT: as diff --git a/idea/testData/completion/keywords/InFunctionScope.kt b/idea/testData/completion/keywords/InFunctionScope.kt index 04c2b465211..344e032031e 100644 --- a/idea/testData/completion/keywords/InFunctionScope.kt +++ b/idea/testData/completion/keywords/InFunctionScope.kt @@ -3,7 +3,7 @@ fun foo() { } // ABSENT: abstract -// ??ABSENT: annotation // java annotation namespace +/* // ABSENT: annotation */ // EXIST: as // EXIST: break // EXIST: by diff --git a/idea/testData/completion/keywords/InModifierListInsideClass.kt b/idea/testData/completion/keywords/InModifierListInsideClass.kt index 3c0f43db774..1bc7e037f9c 100644 --- a/idea/testData/completion/keywords/InModifierListInsideClass.kt +++ b/idea/testData/completion/keywords/InModifierListInsideClass.kt @@ -1,6 +1,6 @@ +// for: KT-2170 open class Foo { p val foo = 1 } -// FOR: KT-2170 // EXIST: private, public, protected \ No newline at end of file diff --git a/idea/testData/completion/keywords/InTypeScope.kt b/idea/testData/completion/keywords/InTypeScope.kt index 3a1146fe185..ea594492ccd 100644 --- a/idea/testData/completion/keywords/InTypeScope.kt +++ b/idea/testData/completion/keywords/InTypeScope.kt @@ -3,7 +3,7 @@ fun foo() { } // ABSENT: abstract -// ??ABSENT: annotation // java annotation namespace +/* // ABSENT: annotation */ // EXIST: as // EXIST: break // EXIST: by diff --git a/idea/tests/org/jetbrains/jet/completion/AbstractKeywordCompletionTest.java b/idea/tests/org/jetbrains/jet/completion/AbstractKeywordCompletionTest.java new file mode 100644 index 00000000000..ad4a2473b8e --- /dev/null +++ b/idea/tests/org/jetbrains/jet/completion/AbstractKeywordCompletionTest.java @@ -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; + } +} diff --git a/idea/tests/org/jetbrains/jet/completion/ExpectedCompletionUtils.java b/idea/tests/org/jetbrains/jet/completion/ExpectedCompletionUtils.java index e8cc18c94af..3d13a2226c1 100644 --- a/idea/tests/org/jetbrains/jet/completion/ExpectedCompletionUtils.java +++ b/idea/tests/org/jetbrains/jet/completion/ExpectedCompletionUtils.java @@ -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 itemsInformation = getItemsInformation(items); String allItemsString = listToString(itemsInformation); diff --git a/idea/tests/org/jetbrains/jet/completion/JetCompletionTestBase.java b/idea/tests/org/jetbrains/jet/completion/JetCompletionTestBase.java deleted file mode 100644 index c3a378e5c0f..00000000000 --- a/idea/tests/org/jetbrains/jet/completion/JetCompletionTestBase.java +++ /dev/null @@ -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)); - } -} diff --git a/idea/tests/org/jetbrains/jet/completion/JetKeywordCompletionTestGenerated.java b/idea/tests/org/jetbrains/jet/completion/JetKeywordCompletionTestGenerated.java new file mode 100644 index 00000000000..bb89ae57c10 --- /dev/null +++ b/idea/tests/org/jetbrains/jet/completion/JetKeywordCompletionTestGenerated.java @@ -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"); + } + +} diff --git a/idea/tests/org/jetbrains/jet/completion/KeywordsCompletionTest.java b/idea/tests/org/jetbrains/jet/completion/KeywordsCompletionTest.java deleted file mode 100644 index ef1697b49b5..00000000000 --- a/idea/tests/org/jetbrains/jet/completion/KeywordsCompletionTest.java +++ /dev/null @@ -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; - } -}