From 2db1cd4250da55ef1fcdb12a16cb436099386c35 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 26 Sep 2013 21:32:52 +0200 Subject: [PATCH] extract dfa-related completion tests to separate test cases --- .../LightFixtureCompletionTestCase.java | 12 ++- .../completion/NormalCompletionDfaTest.groovy | 48 ++++++++++++ .../completion/NormalCompletionTest.groovy | 23 +----- .../SecondSmartTypeCompletionTest.java | 6 -- .../SmartTypeCompletionDfaTest.groovy | 78 +++++++++++++++++++ .../completion/SmartTypeCompletionTest.java | 47 ----------- .../DataFlowInspectionTestSuite.java | 8 +- 7 files changed, 142 insertions(+), 80 deletions(-) create mode 100644 java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionDfaTest.groovy create mode 100644 java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionDfaTest.groovy diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/LightFixtureCompletionTestCase.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/LightFixtureCompletionTestCase.java index 17f0308d3119..5adb7db771c9 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/LightFixtureCompletionTestCase.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/LightFixtureCompletionTestCase.java @@ -1,6 +1,5 @@ package com.intellij.codeInsight.completion; -import com.intellij.codeInsight.lookup.Lookup; import com.intellij.codeInsight.lookup.LookupElement; import com.intellij.codeInsight.lookup.LookupEvent; import com.intellij.codeInsight.lookup.LookupManager; @@ -35,6 +34,17 @@ public abstract class LightFixtureCompletionTestCase extends LightCodeInsightFix complete(); } + protected void configureByTestName() { + configureByFile("/" + getTestName(false) + ".java"); + } + + protected void doAntiTest() { + configureByTestName(); + checkResultByFile(getTestName(false) + ".java"); + assertEmpty(myItems); + assertNull(getLookup()); + } + protected void complete() { myItems = myFixture.completeBasic(); } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionDfaTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionDfaTest.groovy new file mode 100644 index 000000000000..2aaeb5fe5607 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionDfaTest.groovy @@ -0,0 +1,48 @@ +/* + * Copyright 2000-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 com.intellij.codeInsight.completion + +import com.intellij.JavaTestUtil; + +/** + * @author peter + */ +class NormalCompletionDfaTest extends LightFixtureCompletionTestCase { + @Override + protected String getBasePath() { + return JavaTestUtil.getRelativeJavaTestDataPath() + "/codeInsight/completion/normal/"; + } + + void testCastInstanceofedQualifier() { doTest(); } + void testCastInstanceofedQualifierInForeach() { doTest(); } + void testCastComplexInstanceofedQualifier() { doTest(); } + void _testCastIncompleteInstanceofedQualifier() { doTest(); } + + void testCastTooComplexInstanceofedQualifier() { doAntiTest() } + + void testDontCastInstanceofedQualifier() { doTest(); } + void testQualifierCastingWithUnknownAssignments() { doTest(); } + void testQualifierCastingBeforeLt() { doTest(); } + void testCastQualifierForPrivateFieldReference() { doTest(); } + void testOrAssignmentDfa() { doTest(); } + void testFieldWithCastingCaret() { doTest(); } + + private void doTest() throws Exception { + configureByTestName() + checkResultByFile(getTestName(false) + "_after.java") + } + +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy index 8e04d8728e73..c444d50448cd 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy @@ -627,8 +627,6 @@ public class ListUtils { doTest(); } - public void testFieldWithCastingCaret() throws Throwable { doTest(); } - public void testInnerEnumConstant() throws Throwable { doTest('\n'); } public void testMethodReturnType() throws Throwable { @@ -798,7 +796,7 @@ public class ListUtils { } private def configure() { - configureByFile(getTestName(false) + ".java") + configureByTestName() } public void testFinalInForLoop() throws Throwable { @@ -868,13 +866,6 @@ public class ListUtils { checkResult(); } - private void doAntiTest() throws Exception { - configure() - checkResultByFile(getTestName(false) + ".java"); - assertEmpty(myItems); - assertNull(getLookup()); - } - public void testSecondAnonymousClassParameter() throws Throwable { doTest('\n'); } public void testSpaceAfterReturn() throws Throwable { @@ -892,20 +883,8 @@ public class ListUtils { assertStringItems "fooa", "foob" } - public void testCastInstanceofedQualifier() throws Throwable { doTest(); } - public void testCastInstanceofedQualifierInForeach() throws Throwable { doTest(); } - public void testCastComplexInstanceofedQualifier() throws Throwable { doTest(); } - public void _testCastIncompleteInstanceofedQualifier() throws Throwable { doTest(); } - - public void testCastTooComplexInstanceofedQualifier() throws Throwable { doAntiTest(); } - public void testDontCastInstanceofedQualifier() throws Throwable { doTest(); } - public void testQualifierCastingWithUnknownAssignments() throws Throwable { doTest(); } - public void testQualifierCastingBeforeLt() throws Throwable { doTest(); } - public void testCastQualifierForPrivateFieldReference() throws Throwable { doTest(); } public void testNoReturnInTernary() throws Throwable { doTest(); } - public void testOrAssignmentDfa() throws Throwable { doTest(); } - public void testWildcardsInLookup() throws Exception { configure() assertNotNull(getLookup()); diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SecondSmartTypeCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SecondSmartTypeCompletionTest.java index 8873c4a63ca7..a25827ac6a60 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SecondSmartTypeCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SecondSmartTypeCompletionTest.java @@ -141,12 +141,6 @@ public class SecondSmartTypeCompletionTest extends LightFixtureCompletionTestCas public void testNoUnqualifiedCastsInQualifiedContext() throws Throwable { doAntiTest(); } - private void doAntiTest() throws Exception { - configure(); - assertEmpty(myItems); - checkResultByFile(getTestName(false) + ".java"); - } - public void testCastInstanceofedQualifier() throws Throwable { doTest(); } public void testNoLeftRecursion() throws Throwable { diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionDfaTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionDfaTest.groovy new file mode 100644 index 000000000000..16fc5083adb7 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionDfaTest.groovy @@ -0,0 +1,78 @@ +/* + * Copyright 2000-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 com.intellij.codeInsight.completion +import com.intellij.JavaTestUtil +/** + * @author peter + */ +class SmartTypeCompletionDfaTest extends LightFixtureCompletionTestCase { + @Override + protected String getBasePath() { + return JavaTestUtil.getRelativeJavaTestDataPath() + "/codeInsight/completion/smartType/"; + } + + @Override + protected void complete() { + myItems = myFixture.complete(CompletionType.SMART); + } + + private void doTest() { + configureByTestName(); + checkResultByTestName(); + } + + private void checkResultByTestName() { + checkResultByFile("/" + getTestName(false) + "-out.java"); + } + + void testCastGenericQualifier() { doTest() } + + void testDontAutoCastWhenAlreadyCasted() { + configureByTestName(); + myFixture.assertPreferredCompletionItems(0, "s", "toString"); + myFixture.type('\n') + checkResultByTestName(); + } + + void testAutoCastWhenAlreadyCasted() { + configureByTestName(); + myFixture.type('\n') + checkResultByTestName(); + } + + void testSuggestCastedValueAfterCast() { doTest(); } + + void testSuggestInstanceofedValue() { doTest() } + + void testSuggestInstanceofedValueInTernary() { doTest() } + + void testSuggestInstanceofedValueInComplexIf() { doTest(); } + + void testSuggestInstanceofedValueInElseNegated() { doTest(); } + + void testSuggestInstanceofedValueAfterReturn() { doTest(); } + + void testNoInstanceofedValueWhenBasicSuits() { doTest(); } + + void testNoInstanceofedValueInElse() { doAntiTest(); } + + void testNoInstanceofedValueInThenNegated() { doAntiTest(); } + + void testNoInstanceofedValueInElseWithComplexIf() { doAntiTest(); } + + void testInstanceofedInsideAnonymous() { doTest(); } + +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java index f8069730d006..15038d55c62d 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java @@ -626,8 +626,6 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase { public void testDefaultAnnoParam() throws Throwable { doTest(); } - public void testCastGenericQualifier() throws Throwable { doTest(); } - public void testNewWithTypeParameterErasure() throws Throwable { doTest(); } public void testEverythingDoubles() throws Throwable { @@ -694,34 +692,8 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase { doTest(); } - public void testSuggestInstanceofedValue() throws Throwable { - doTest(); - } - - public void testSuggestInstanceofedValueInTernary() throws Throwable { - doTest(); - } - - public void testSuggestInstanceofedValueInComplexIf() throws Throwable { doTest('\n'); } - - public void testSuggestInstanceofedValueInElseNegated() throws Throwable { doTest('\n'); } - - public void testSuggestInstanceofedValueAfterReturn() throws Throwable { doTest('\n'); } - - public void testNoInstanceofedValueWhenBasicSuits() throws Throwable { doTest(); } - - public void testSuggestCastedValueAfterCast() throws Throwable { doTest('\n'); } - - public void testNoInstanceofedValueInElse() throws Throwable { doAntiTest(); } - - public void testNoInstanceofedValueInThenNegated() throws Throwable { doAntiTest(); } - - public void testNoInstanceofedValueInElseWithComplexIf() throws Throwable { doAntiTest(); } - public void testReplaceWholeReferenceChain() throws Throwable { doTest(Lookup.REPLACE_SELECT_CHAR); } - public void testInstanceofedInsideAnonymous() throws Throwable { doTest(Lookup.REPLACE_SELECT_CHAR); } - public void testDoubleTrueInOverloadedMethodCall() throws Throwable { doTest(Lookup.REPLACE_SELECT_CHAR); } public void testMethodColon() throws Exception { doFirstItemTest(':'); } @@ -737,15 +709,6 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase { public void testCastToArray() throws Throwable { doTest(); } - public void testDontAutoCastWhenAlreadyCasted() throws Throwable { - configureByTestName(); - myFixture.assertPreferredCompletionItems(0, "s", "toString"); - select(); - checkResultByTestName(); - } - - public void testAutoCastWhenAlreadyCasted() throws Throwable { doTest('\n'); } - public void testCommaDoublePenetration() throws Throwable { doFirstItemTest(','); } @@ -803,12 +766,6 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase { checkResultByTestName(); } - private void doAntiTest() throws Exception { - configureByTestName(); - assertEmpty(myItems); - checkResultByFile("/" + getTestName(false) + ".java"); - } - public void testAfterNewWithGenerics() throws Exception { doActionTest(); } @@ -946,10 +903,6 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase { public void testConstructorArgsSmartEnter() throws Exception { doTest(Lookup.COMPLETE_STATEMENT_SELECT_CHAR); } - private void configureByTestName() { - configureByFile("/" + getTestName(false) + ".java"); - } - public void testIDEADEV13148() throws Exception { configureByFile("/IDEADEV13148.java"); assertStringItems("false", "true"); //todo don't suggest boolean literals in synchronized diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTestSuite.java b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTestSuite.java index 1bd64f4d0802..c7dacef88b0d 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTestSuite.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTestSuite.java @@ -15,8 +15,8 @@ */ package com.intellij.codeInspection; -import com.intellij.codeInsight.completion.NormalCompletionTest; -import com.intellij.codeInsight.completion.SmartTypeCompletionTest; +import com.intellij.codeInsight.completion.NormalCompletionDfaTest; +import com.intellij.codeInsight.completion.SmartTypeCompletionDfaTest; import com.intellij.codeInsight.slice.SliceBackwardTest; import com.intellij.codeInsight.slice.SliceTreeTest; import junit.framework.Test; @@ -29,8 +29,8 @@ public class DataFlowInspectionTestSuite { suite.addTestSuite(DataFlowInspectionAncientTest.class); suite.addTestSuite(SliceTreeTest.class); suite.addTestSuite(SliceBackwardTest.class); - suite.addTestSuite(SmartTypeCompletionTest.class); - suite.addTestSuite(NormalCompletionTest.class); + suite.addTestSuite(SmartTypeCompletionDfaTest.class); + suite.addTestSuite(NormalCompletionDfaTest.class); return suite; } }