Fix broken NavBar for 201

^KT-38466 Fixed
^KT-38260 Fixed
This commit is contained in:
Nikita Bobko
2020-05-26 23:46:30 +03:00
committed by igoriakovlev
parent 246c68b0a9
commit 2ef46b586d
20 changed files with 241 additions and 5 deletions
@@ -0,0 +1,34 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.idea.navigationToolbar
import com.intellij.ide.navigationToolbar.NavBarModel
import com.intellij.ide.navigationToolbar.NavBarModelExtension
import com.intellij.ide.navigationToolbar.NavBarPresentation
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.ex.EditorEx
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
import org.jetbrains.kotlin.test.InTextDirectivesUtils
abstract class AbstractKotlinNavBarTest : KotlinLightCodeInsightFixtureTestCase() {
// inspired by: com.intellij.ide.navigationToolbar.JavaNavBarTest#assertNavBarModel
protected fun doTest(testPath: String) {
val psiFile = myFixture.configureByFile(testDataFile().name)
val model = NavBarModel(myFixture.project)
model::class.java.getDeclaredMethod("updateModel", DataContext::class.java)
.apply { isAccessible = true }
.invoke(model, (myFixture.editor as EditorEx).dataContext)
val actualItems = (0 until model.size()).map {
NavBarPresentation.calcPresentableText(model[it])
}
val expectedItems = InTextDirectivesUtils.findListWithPrefixes(psiFile.text, "// NAV_BAR_ITEMS:")
assertOrderedEquals(actualItems, expectedItems)
}
}
@@ -0,0 +1,34 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.idea.navigationToolbar
import com.intellij.ide.navigationToolbar.NavBarModel
import com.intellij.ide.navigationToolbar.NavBarModelExtension
import com.intellij.ide.navigationToolbar.NavBarPresentation
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.ex.EditorEx
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
import org.jetbrains.kotlin.test.InTextDirectivesUtils
abstract class AbstractKotlinNavBarTest : KotlinLightCodeInsightFixtureTestCase() {
// inspired by: com.intellij.ide.navigationToolbar.JavaNavBarTest#assertNavBarModel
protected fun doTest(testPath: String) {
val psiFile = myFixture.configureByFile(testDataFile().name)
val model = NavBarModel(myFixture.project)
model::class.java.getDeclaredMethod("updateModel", DataContext::class.java)
.apply { isAccessible = true }
.invoke(model, (myFixture.editor as EditorEx).dataContext)
val actualItems = (0 until model.size()).map {
NavBarPresentation.calcPresentableText(model[it], false)
}
val expectedItems = InTextDirectivesUtils.findListWithPrefixes(psiFile.text, "// NAV_BAR_ITEMS:")
assertOrderedEquals(actualItems, expectedItems)
}
}
@@ -0,0 +1,60 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.idea.navigationToolbar;
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/navigationToolbar")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class KotlinNavBarTestGenerated extends AbstractKotlinNavBarTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInNavigationToolbar() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/navigationToolbar"), Pattern.compile("^(.+)\\.kt$"), null, false);
}
@TestMetadata("ClassProperty.kt")
public void testClassProperty() throws Exception {
runTest("idea/testData/navigationToolbar/ClassProperty.kt");
}
@TestMetadata("fileNameDoesntMatchClassName.kt")
public void testFileNameDoesntMatchClassName() throws Exception {
runTest("idea/testData/navigationToolbar/fileNameDoesntMatchClassName.kt");
}
@TestMetadata("MethodInClass.kt")
public void testMethodInClass() throws Exception {
runTest("idea/testData/navigationToolbar/MethodInClass.kt");
}
@TestMetadata("SeveralClassesInFile.kt")
public void testSeveralClassesInFile() throws Exception {
runTest("idea/testData/navigationToolbar/SeveralClassesInFile.kt");
}
@TestMetadata("topLevelFunction.kt")
public void testTopLevelFunction() throws Exception {
runTest("idea/testData/navigationToolbar/topLevelFunction.kt");
}
@TestMetadata("topLevelProperty.kt")
public void testTopLevelProperty() throws Exception {
runTest("idea/testData/navigationToolbar/topLevelProperty.kt");
}
}