Tests for GotoTypeDeclaration action

This commit is contained in:
Nikolay Krasko
2016-09-05 18:29:40 +03:00
parent 9eddf05676
commit 3cd100bbcf
7 changed files with 159 additions and 1 deletions

View File

@@ -93,6 +93,7 @@ import org.jetbrains.kotlin.idea.kdoc.AbstractKDocTypingTest
import org.jetbrains.kotlin.idea.maven.AbstractKotlinMavenInspectionTest
import org.jetbrains.kotlin.idea.maven.configuration.AbstractMavenConfigureProjectByChangingFileTest
import org.jetbrains.kotlin.idea.navigation.AbstractGotoSuperTest
import org.jetbrains.kotlin.idea.navigation.AbstractGotoTypeDeclarationTest
import org.jetbrains.kotlin.idea.navigation.AbstractKotlinGotoImplementationTest
import org.jetbrains.kotlin.idea.navigation.AbstractKotlinGotoTest
import org.jetbrains.kotlin.idea.parameterInfo.AbstractParameterInfoTest
@@ -427,6 +428,10 @@ fun main(args: Array<String>) {
model("navigation/gotoSuper", extension = "test")
}
testClass<AbstractGotoTypeDeclarationTest>() {
model("navigation/gotoTypeDeclaration", extension = "test")
}
testClass<AbstractParameterInfoTest>() {
model("parameterInfo", recursive = true, excludeDirs = listOf("withLib/sharedLib"))
}

View File

@@ -0,0 +1,23 @@
// FILE: before.kt
class Foo
fun <T> some(a: T, f: (T) -> Unit) {}
fun foo(a: Any) {}
fun baz() {
some(Foo()) { p ->
foo(p<caret>)
}
}
// FILE: after.kt
class <caret>Foo
fun <T> some(a: T, f: (T) -> Unit) {}
fun foo(a: Any) {}
fun baz() {
some(Foo()) { p ->
foo(p)
}
}

View File

@@ -0,0 +1,17 @@
// FILE: before.kt
class Foo
fun test(): Foo = Foo()
fun void() {
<caret>test()
}
// FILE: after.kt
class <caret>Foo
fun test(): Foo = Foo()
fun void() {
test()
}

View File

@@ -0,0 +1,15 @@
// FILE: before.kt
interface Some
fun some() {
val a: Some = null!!
<caret>a
}
// FILE: after.kt
interface <caret>Some
fun some() {
val a: Some = null!!
a
}

View File

@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.idea.navigation;
import com.intellij.codeInsight.CodeInsightActionHandler;
import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.IdeActions;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
import org.jetbrains.kotlin.idea.KotlinFileType;
import org.jetbrains.kotlin.test.KotlinTestUtils;
@@ -30,7 +31,8 @@ public abstract class AbstractGotoSuperTest extends LightCodeInsightFixtureTestC
myFixture.configureByText(KotlinFileType.INSTANCE, parts.get(0));
CodeInsightActionHandler gotoSuperAction = (CodeInsightActionHandler) ActionManager.getInstance().getAction("GotoSuperMethod");
CodeInsightActionHandler gotoSuperAction =
(CodeInsightActionHandler) ActionManager.getInstance().getAction(IdeActions.ACTION_GOTO_SUPER);
gotoSuperAction.invoke(getProject(), myFixture.getEditor(), myFixture.getFile());
myFixture.checkResult(parts.get(1));

View File

@@ -0,0 +1,41 @@
/*
* Copyright 2010-2016 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.kotlin.idea.navigation
import com.intellij.codeInsight.CodeInsightActionHandler
import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.openapi.actionSystem.IdeActions
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
import org.jetbrains.kotlin.idea.KotlinFileType
import org.jetbrains.kotlin.test.KotlinTestUtils
import org.junit.Assert
abstract class AbstractGotoTypeDeclarationTest : LightCodeInsightFixtureTestCase() {
protected fun doTest(testPath: String) {
val parts = KotlinTestUtils.loadBeforeAfterText(testPath)
myFixture.configureByText(KotlinFileType.INSTANCE, parts[0])
val gotoSuperAction = ActionManager.getInstance().getAction(IdeActions.ACTION_GOTO_TYPE_DECLARATION) as CodeInsightActionHandler
gotoSuperAction.invoke(project, myFixture.editor, myFixture.file)
val afterText = StringBuilder(myFixture.getDocument(myFixture.file).text).insert(editor.caretModel.offset, "<caret>").toString()
Assert.assertEquals(parts[1], afterText)
}
}

View File

@@ -0,0 +1,55 @@
/*
* Copyright 2010-2016 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.kotlin.idea.navigation;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.runner.RunWith;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("idea/testData/navigation/gotoTypeDeclaration")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class GotoTypeDeclarationTestGenerated extends AbstractGotoTypeDeclarationTest {
public void testAllFilesPresentInGotoTypeDeclaration() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/navigation/gotoTypeDeclaration"), Pattern.compile("^(.+)\\.test$"), true);
}
@TestMetadata("explicitParameterInLambda.test")
public void testExplicitParameterInLambda() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/navigation/gotoTypeDeclaration/explicitParameterInLambda.test");
doTest(fileName);
}
@TestMetadata("functionCall.test")
public void testFunctionCall() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/navigation/gotoTypeDeclaration/functionCall.test");
doTest(fileName);
}
@TestMetadata("variableType.test")
public void testVariableType() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/navigation/gotoTypeDeclaration/variableType.test");
doTest(fileName);
}
}