Update file structure tests as FileStructurePopup api was changed in 173
This commit is contained in:
@@ -1 +1 @@
|
|||||||
+EmptyFile.kt
|
-EmptyFile.kt
|
||||||
+6
-44
@@ -16,43 +16,28 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.structureView
|
package org.jetbrains.kotlin.idea.structureView
|
||||||
|
|
||||||
import com.intellij.ide.actions.ViewStructureAction
|
|
||||||
import com.intellij.ide.util.FileStructurePopup
|
import com.intellij.ide.util.FileStructurePopup
|
||||||
import com.intellij.openapi.fileEditor.impl.text.TextEditorProvider
|
|
||||||
import com.intellij.openapi.ui.Queryable.PrintInfo
|
|
||||||
import com.intellij.openapi.util.io.FileUtil
|
import com.intellij.openapi.util.io.FileUtil
|
||||||
import com.intellij.ui.treeStructure.filtered.FilteringTreeStructure
|
|
||||||
import com.intellij.util.ui.tree.TreeUtil
|
|
||||||
import org.jetbrains.kotlin.idea.completion.test.configureWithExtraFile
|
import org.jetbrains.kotlin.idea.completion.test.configureWithExtraFile
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
||||||
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
|
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
|
||||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
abstract class AbstractKotlinFileStructureTest : KotlinLightCodeInsightFixtureTestCase() {
|
abstract class AbstractKotlinFileStructureTest : KotlinFileStructureTestBase() {
|
||||||
override fun getTestDataPath() = PluginTestCaseBase.getTestDataPathBase() + "/structureView/fileStructure"
|
override fun getTestDataPath() = PluginTestCaseBase.getTestDataPathBase() + "/structureView/fileStructure"
|
||||||
|
|
||||||
override fun getProjectDescriptor() = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE
|
override fun getProjectDescriptor() = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE
|
||||||
|
|
||||||
|
override val fileExtension = "kt"
|
||||||
|
override val treeFileName: String get() = getFileName("after")
|
||||||
|
|
||||||
fun doTest(path: String) {
|
fun doTest(path: String) {
|
||||||
myFixture.configureWithExtraFile(path)
|
myFixture.configureWithExtraFile(path)
|
||||||
|
|
||||||
val textEditor = TextEditorProvider.getInstance()!!.getTextEditor(myFixture.editor)
|
popupFixture.popup.setup()
|
||||||
val popup = ViewStructureAction.createPopup(myFixture.project, textEditor)
|
|
||||||
|
|
||||||
if (popup == null) throw AssertionError("popup mustn't be null")
|
checkTree()
|
||||||
|
|
||||||
popup.createCenterPanel()
|
|
||||||
popup.treeBuilder.ui!!.updater!!.setPassThroughMode(true)
|
|
||||||
popup.update()
|
|
||||||
|
|
||||||
popup.setup()
|
|
||||||
|
|
||||||
val printInfo = PrintInfo(arrayOf("text"), arrayOf("location"))
|
|
||||||
val popupText = StructureViewUtil.print(popup.tree, false, printInfo, null)
|
|
||||||
KotlinTestUtils.assertEqualsToFile(File("${FileUtil.getNameWithoutExtension(path)}.after"), popupText)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun FileStructurePopup.setup() {
|
protected fun FileStructurePopup.setup() {
|
||||||
@@ -61,27 +46,4 @@ abstract class AbstractKotlinFileStructureTest : KotlinLightCodeInsightFixtureTe
|
|||||||
val withInherited = InTextDirectivesUtils.isDirectiveDefined(fileText, "WITH_INHERITED")
|
val withInherited = InTextDirectivesUtils.isDirectiveDefined(fileText, "WITH_INHERITED")
|
||||||
setTreeActionState(KotlinInheritedMembersNodeProvider::class.java, withInherited)
|
setTreeActionState(KotlinInheritedMembersNodeProvider::class.java, withInherited)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun FileStructurePopup.update() {
|
|
||||||
treeBuilder.refilter()!!.doWhenProcessed {
|
|
||||||
getStructure().rebuild()
|
|
||||||
updateRecursively(getRootNode())
|
|
||||||
treeBuilder.updateFromRoot()
|
|
||||||
|
|
||||||
TreeUtil.expandAll(tree)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun FileStructurePopup.getFileStructureSpeedSearch() = speedSearch as FileStructurePopup.MyTreeSpeedSearch
|
|
||||||
|
|
||||||
fun FileStructurePopup.getStructure() = treeBuilder.treeStructure as FilteringTreeStructure
|
|
||||||
|
|
||||||
fun FileStructurePopup.getRootNode() = treeBuilder.rootElement as FilteringTreeStructure.FilteringNode
|
|
||||||
|
|
||||||
fun FileStructurePopup.updateRecursively(node: FilteringTreeStructure.FilteringNode) {
|
|
||||||
node.update()
|
|
||||||
for (child in node.children()!!) {
|
|
||||||
updateRecursively(child)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2017 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.structureView
|
||||||
|
|
||||||
|
import com.intellij.openapi.ui.Queryable
|
||||||
|
import com.intellij.openapi.util.Disposer
|
||||||
|
import com.intellij.openapi.util.text.StringUtil
|
||||||
|
import com.intellij.testFramework.FileStructureTestFixture
|
||||||
|
import com.intellij.testFramework.PlatformTestUtil
|
||||||
|
import com.intellij.testFramework.UsefulTestCase
|
||||||
|
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||||
|
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||||
|
|
||||||
|
abstract class KotlinFileStructureTestBase : KotlinLightCodeInsightFixtureTestCase() {
|
||||||
|
|
||||||
|
protected var myPopupFixture: FileStructureTestFixture? = null
|
||||||
|
protected val popupFixture get() = myPopupFixture!!
|
||||||
|
|
||||||
|
protected abstract val fileExtension: String
|
||||||
|
|
||||||
|
open protected val treeFileName: String
|
||||||
|
get() = getFileName("tree")
|
||||||
|
|
||||||
|
override fun setUp() {
|
||||||
|
super.setUp()
|
||||||
|
myPopupFixture = FileStructureTestFixture(myFixture)
|
||||||
|
}
|
||||||
|
|
||||||
|
protected fun configureDefault() {
|
||||||
|
myFixture.configureByFile(getFileName(fileExtension))
|
||||||
|
}
|
||||||
|
|
||||||
|
public override fun tearDown() {
|
||||||
|
try {
|
||||||
|
Disposer.dispose(popupFixture)
|
||||||
|
myPopupFixture = null
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
super.tearDown()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected fun getFileName(ext: String): String {
|
||||||
|
return getTestName(false) + if (StringUtil.isEmpty(ext)) "" else "." + ext
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("unused")
|
||||||
|
protected fun checkTree(filter: String) {
|
||||||
|
configureDefault()
|
||||||
|
popupFixture.update()
|
||||||
|
popupFixture.popup.setSearchFilterForTests(filter)
|
||||||
|
PlatformTestUtil.waitForPromise(popupFixture.popup.rebuildAndUpdate())
|
||||||
|
popupFixture.speedSearch.findAndSelectElement(filter)
|
||||||
|
checkResult()
|
||||||
|
}
|
||||||
|
|
||||||
|
protected fun checkTree() {
|
||||||
|
configureDefault()
|
||||||
|
popupFixture.update()
|
||||||
|
checkResult()
|
||||||
|
}
|
||||||
|
|
||||||
|
protected fun checkResult() {
|
||||||
|
val printInfo = Queryable.PrintInfo(arrayOf("text"), arrayOf("location"))
|
||||||
|
val popupText = StructureViewUtil.print(popupFixture.tree, false, printInfo, null).trim { it <= ' ' }
|
||||||
|
UsefulTestCase.assertSameLinesWithFile(testDataPath + "/" + treeFileName, popupText)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user