diff --git a/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt b/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt index 9d45b5852aa..78a119aa454 100644 --- a/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt +++ b/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt @@ -94,6 +94,7 @@ import org.jetbrains.jet.plugin.intentions.AbstractIntentionTest import org.jetbrains.jet.checkers.AbstractJetDiagnosticsTestWithStdLib import org.jetbrains.jet.plugin.codeInsight.AbstractInsertImportOnPasteTest import org.jetbrains.jet.resolve.AbstractReferenceToJavaWithWrongFileStructureTest +import org.jetbrains.jet.plugin.navigation.AbstractKotlinGotoTest fun main(args: Array) { System.setProperty("java.awt.headless", "true") @@ -293,6 +294,10 @@ fun main(args: Array) { model("navigation/gotoSuper", extension = "test") } + testClass(javaClass()) { + model("navigation/gotoSymbol") + } + testClass(javaClass()) { model("quickfix", pattern = """^(\w+)\.before\.Main\.kt$""", testMethod = "doTestWithExtraFile") } diff --git a/idea/tests/org/jetbrains/jet/plugin/navigation/AbstractKotlinGotoTest.java b/idea/tests/org/jetbrains/jet/plugin/navigation/AbstractKotlinGotoTest.java new file mode 100644 index 00000000000..f84ede2a3b5 --- /dev/null +++ b/idea/tests/org/jetbrains/jet/plugin/navigation/AbstractKotlinGotoTest.java @@ -0,0 +1,102 @@ +/* + * 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.plugin.navigation; + +import com.google.common.base.Function; +import com.google.common.collect.Lists; +import com.google.common.collect.Ordering; +import com.intellij.ide.util.gotoByName.GotoSymbolModel2; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiElement; +import com.intellij.testFramework.UsefulTestCase; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.InTextDirectivesUtils; +import org.jetbrains.jet.plugin.JetLightCodeInsightFixtureTestCase; +import org.jetbrains.jet.test.TestMetadata; +import org.jetbrains.jet.testing.ReferenceUtils; +import org.junit.Assert; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public abstract class AbstractKotlinGotoTest extends JetLightCodeInsightFixtureTestCase { + protected void doTest(String path) { + myFixture.configureByFile(path); + assertGotoSymbol(getProject(), myFixture.getEditor()); + } + + private String dirPath = null; + + @Override + protected void setUp() throws Exception { + TestMetadata annotation = getClass().getAnnotation(TestMetadata.class); + dirPath = annotation.value(); + + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + dirPath = null; + } + + @Override + protected String getTestDataPath() { + return dirPath; + } + + @Override + protected String fileName() { + return getTestName(true) + ".kt"; + } + + private static void assertGotoSymbol(@NotNull Project project, @NotNull Editor editor) { + List searchTextList = InTextDirectivesUtils.findListWithPrefixes(editor.getDocument().getText(), "// SEARCH_TEXT:"); + Assert.assertFalse("There's no search text in test data file given. Use '// SEARCH_TEXT:' directive", + searchTextList.isEmpty()); + + List expectedReferences = InTextDirectivesUtils.findListWithPrefixes(editor.getDocument().getText(), "// REF:"); + boolean enableCheckbox = InTextDirectivesUtils.isDirectiveDefined(editor.getDocument().getText(), "// CHECK_BOX"); + + String searchText = searchTextList.get(0); + + List elementsByName = new ArrayList(); + + GotoSymbolModel2 model = new GotoSymbolModel2(project); + String[] names = model.getNames(enableCheckbox); + for (String name : names) { + if (name != null && name.startsWith(searchText)) { + elementsByName.addAll(Arrays.asList(model.getElementsByName(name, enableCheckbox, name + "*"))); + } + } + + List renderedElements = Lists.transform(elementsByName, new Function() { + @Override + public String apply(@Nullable Object element) { + Assert.assertNotNull(element); + Assert.assertTrue(element instanceof PsiElement); + return ReferenceUtils.renderAsGotoImplementation((PsiElement) element); + } + }); + + UsefulTestCase.assertOrderedEquals(Ordering.natural().sortedCopy(renderedElements), expectedReferences); + } +} diff --git a/idea/tests/org/jetbrains/jet/plugin/navigation/JetGotoSymbolTest.java b/idea/tests/org/jetbrains/jet/plugin/navigation/JetGotoSymbolTest.java deleted file mode 100644 index e8ba2a7d332..00000000000 --- a/idea/tests/org/jetbrains/jet/plugin/navigation/JetGotoSymbolTest.java +++ /dev/null @@ -1,51 +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.plugin.navigation; - -import org.jetbrains.jet.plugin.JetLightCodeInsightFixtureTestCase; -import org.jetbrains.jet.plugin.PluginTestCaseBase; - -import java.io.File; - -public class JetGotoSymbolTest extends JetLightCodeInsightFixtureTestCase { - public void testProperties() { - doTest(); - } - - public void testFunctions() { - doTest(); - } - - public void testJavaMethods() { - doTest(); - } - - @Override - protected String getTestDataPath() { - return new File(PluginTestCaseBase.getTestDataPathBase(), "/navigation/gotoSymbol").getPath() + File.separator; - } - - protected void doTest() { - myFixture.configureByFile(fileName()); - NavigationTestUtils.assertGotoSymbol(getProject(), myFixture.getEditor()); - } - - @Override - protected String fileName() { - return getTestName(true) + ".kt"; - } -} diff --git a/idea/tests/org/jetbrains/jet/plugin/navigation/KotlinGotoTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/navigation/KotlinGotoTestGenerated.java new file mode 100644 index 00000000000..44e14efcede --- /dev/null +++ b/idea/tests/org/jetbrains/jet/plugin/navigation/KotlinGotoTestGenerated.java @@ -0,0 +1,54 @@ +/* + * 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.plugin.navigation; + +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.plugin.navigation.AbstractKotlinGotoTest; + +/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("idea/testData/navigation/gotoSymbol") +public class KotlinGotoTestGenerated extends AbstractKotlinGotoTest { + public void testAllFilesPresentInGotoSymbol() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/navigation/gotoSymbol"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("functions.kt") + public void testFunctions() throws Exception { + doTest("idea/testData/navigation/gotoSymbol/functions.kt"); + } + + @TestMetadata("javaMethods.kt") + public void testJavaMethods() throws Exception { + doTest("idea/testData/navigation/gotoSymbol/javaMethods.kt"); + } + + @TestMetadata("properties.kt") + public void testProperties() throws Exception { + doTest("idea/testData/navigation/gotoSymbol/properties.kt"); + } + +} diff --git a/idea/tests/org/jetbrains/jet/plugin/navigation/NavigationTestUtils.java b/idea/tests/org/jetbrains/jet/plugin/navigation/NavigationTestUtils.java index 6fb28f9c29e..d0079d89b22 100644 --- a/idea/tests/org/jetbrains/jet/plugin/navigation/NavigationTestUtils.java +++ b/idea/tests/org/jetbrains/jet/plugin/navigation/NavigationTestUtils.java @@ -21,20 +21,15 @@ import com.google.common.collect.Lists; import com.google.common.collect.Ordering; import com.intellij.codeInsight.navigation.GotoImplementationHandler; import com.intellij.codeInsight.navigation.GotoTargetHandler; -import com.intellij.ide.util.gotoByName.GotoSymbolModel2; import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.progress.util.ProgressIndicatorBase; -import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.testFramework.UsefulTestCase; import junit.framework.Assert; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.InTextDirectivesUtils; import org.jetbrains.jet.testing.ReferenceUtils; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -69,37 +64,4 @@ public final class NavigationTestUtils { UsefulTestCase.assertOrderedEquals(Collections.emptyList(), expectedReferences); } } - - public static void assertGotoSymbol(@NotNull Project project, @NotNull Editor editor) { - - List searchTextList = InTextDirectivesUtils.findListWithPrefixes(editor.getDocument().getText(), "// SEARCH_TEXT:"); - Assert.assertFalse("There's no search text in test data file given. Use '// SEARCH_TEXT:' directive", - searchTextList.isEmpty()); - - List expectedReferences = InTextDirectivesUtils.findListWithPrefixes(editor.getDocument().getText(), "// REF:"); - boolean enableCheckbox = InTextDirectivesUtils.isDirectiveDefined(editor.getDocument().getText(), "// CHECK_BOX"); - - String searchText = searchTextList.get(0); - - List elementsByName = new ArrayList(); - - GotoSymbolModel2 model = new GotoSymbolModel2(project); - String[] names = model.getNames(enableCheckbox); - for (String name : names) { - if (name != null && name.startsWith(searchText)) { - elementsByName.addAll(Arrays.asList(model.getElementsByName(name, enableCheckbox, name + "*"))); - } - } - - List renderedElements = Lists.transform(elementsByName, new Function() { - @Override - public String apply(@Nullable Object element) { - Assert.assertNotNull(element); - Assert.assertTrue(element instanceof PsiElement); - return ReferenceUtils.renderAsGotoImplementation((PsiElement) element); - } - }); - - UsefulTestCase.assertOrderedEquals(Ordering.natural().sortedCopy(renderedElements), expectedReferences); - } }