Generator for goto symbols test
This commit is contained in:
@@ -94,6 +94,7 @@ import org.jetbrains.jet.plugin.intentions.AbstractIntentionTest
|
|||||||
import org.jetbrains.jet.checkers.AbstractJetDiagnosticsTestWithStdLib
|
import org.jetbrains.jet.checkers.AbstractJetDiagnosticsTestWithStdLib
|
||||||
import org.jetbrains.jet.plugin.codeInsight.AbstractInsertImportOnPasteTest
|
import org.jetbrains.jet.plugin.codeInsight.AbstractInsertImportOnPasteTest
|
||||||
import org.jetbrains.jet.resolve.AbstractReferenceToJavaWithWrongFileStructureTest
|
import org.jetbrains.jet.resolve.AbstractReferenceToJavaWithWrongFileStructureTest
|
||||||
|
import org.jetbrains.jet.plugin.navigation.AbstractKotlinGotoTest
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
System.setProperty("java.awt.headless", "true")
|
System.setProperty("java.awt.headless", "true")
|
||||||
@@ -293,6 +294,10 @@ fun main(args: Array<String>) {
|
|||||||
model("navigation/gotoSuper", extension = "test")
|
model("navigation/gotoSuper", extension = "test")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testClass(javaClass<AbstractKotlinGotoTest>()) {
|
||||||
|
model("navigation/gotoSymbol")
|
||||||
|
}
|
||||||
|
|
||||||
testClass(javaClass<AbstractQuickFixMultiFileTest>()) {
|
testClass(javaClass<AbstractQuickFixMultiFileTest>()) {
|
||||||
model("quickfix", pattern = """^(\w+)\.before\.Main\.kt$""", testMethod = "doTestWithExtraFile")
|
model("quickfix", pattern = """^(\w+)\.before\.Main\.kt$""", testMethod = "doTestWithExtraFile")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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<String> 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<String> expectedReferences = InTextDirectivesUtils.findListWithPrefixes(editor.getDocument().getText(), "// REF:");
|
||||||
|
boolean enableCheckbox = InTextDirectivesUtils.isDirectiveDefined(editor.getDocument().getText(), "// CHECK_BOX");
|
||||||
|
|
||||||
|
String searchText = searchTextList.get(0);
|
||||||
|
|
||||||
|
List<Object> elementsByName = new ArrayList<Object>();
|
||||||
|
|
||||||
|
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<String> renderedElements = Lists.transform(elementsByName, new Function<Object, String>() {
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -21,20 +21,15 @@ import com.google.common.collect.Lists;
|
|||||||
import com.google.common.collect.Ordering;
|
import com.google.common.collect.Ordering;
|
||||||
import com.intellij.codeInsight.navigation.GotoImplementationHandler;
|
import com.intellij.codeInsight.navigation.GotoImplementationHandler;
|
||||||
import com.intellij.codeInsight.navigation.GotoTargetHandler;
|
import com.intellij.codeInsight.navigation.GotoTargetHandler;
|
||||||
import com.intellij.ide.util.gotoByName.GotoSymbolModel2;
|
|
||||||
import com.intellij.openapi.editor.Editor;
|
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.PsiElement;
|
||||||
import com.intellij.psi.PsiFile;
|
import com.intellij.psi.PsiFile;
|
||||||
import com.intellij.testFramework.UsefulTestCase;
|
import com.intellij.testFramework.UsefulTestCase;
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.InTextDirectivesUtils;
|
import org.jetbrains.jet.InTextDirectivesUtils;
|
||||||
import org.jetbrains.jet.testing.ReferenceUtils;
|
import org.jetbrains.jet.testing.ReferenceUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -69,37 +64,4 @@ public final class NavigationTestUtils {
|
|||||||
UsefulTestCase.assertOrderedEquals(Collections.emptyList(), expectedReferences);
|
UsefulTestCase.assertOrderedEquals(Collections.emptyList(), expectedReferences);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void assertGotoSymbol(@NotNull Project project, @NotNull Editor editor) {
|
|
||||||
|
|
||||||
List<String> 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<String> expectedReferences = InTextDirectivesUtils.findListWithPrefixes(editor.getDocument().getText(), "// REF:");
|
|
||||||
boolean enableCheckbox = InTextDirectivesUtils.isDirectiveDefined(editor.getDocument().getText(), "// CHECK_BOX");
|
|
||||||
|
|
||||||
String searchText = searchTextList.get(0);
|
|
||||||
|
|
||||||
List<Object> elementsByName = new ArrayList<Object>();
|
|
||||||
|
|
||||||
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<String> renderedElements = Lists.transform(elementsByName, new Function<Object, String>() {
|
|
||||||
@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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user