Tests for file structure

This commit is contained in:
Nikolay Krasko
2014-05-19 20:49:09 +04:00
parent 63d5897d93
commit dfd66440b4
14 changed files with 178 additions and 1 deletions
@@ -0,0 +1,8 @@
<root>
<item name='com.intellij.ide.util.FileStructurePopup com.intellij.ui.treeStructure.Tree getTree()'>
<annotation name='org.jetbrains.annotations.NotNull'/>
</item>
<item name='com.intellij.ide.util.FileStructurePopup com.intellij.ui.treeStructure.filtered.FilteringTreeBuilder getTreeBuilder()'>
<annotation name='org.jetbrains.annotations.NotNull'/>
</item>
</root>
@@ -10,6 +10,9 @@
<item name='com.intellij.testFramework.PlatformTestCase com.intellij.openapi.module.Module createModule(java.lang.String)'>
<annotation name='org.jetbrains.annotations.NotNull'/>
</item>
<item name='com.intellij.testFramework.PlatformTestUtil java.lang.String print(javax.swing.JTree, boolean)'>
<annotation name='org.jetbrains.annotations.NotNull'/>
</item>
<item name='com.intellij.testFramework.UsefulTestCase java.lang.String getTestName(boolean)'>
<annotation name='org.jetbrains.annotations.NotNull'/>
</item>
@@ -112,6 +112,7 @@ import org.jetbrains.jet.plugin.debugger.evaluate.AbstractCodeFragmentCompletion
import org.jetbrains.jet.plugin.debugger.evaluate.AbstractCodeFragmentHighlightingTest
import org.jetbrains.jet.plugin.stubs.AbstractLazyResolveByStubTest
import org.jetbrains.jet.plugin.stubs.AbstractMultiFileHighlightingTest
import org.jetbrains.jet.plugin.structureView.AbstractKotlinFileStructureTest
fun main(args: Array<String>) {
System.setProperty("java.awt.headless", "true")
@@ -571,6 +572,10 @@ fun main(args: Array<String>) {
model("smartSelection", testMethod = "doTestSmartSelection", pattern = """^([^\.]+)\.kt$""")
}
testClass(javaClass<AbstractKotlinFileStructureTest>()) {
model("structureView/fileStructure")
}
testClass(javaClass<AbstractExpressionSelectionTest>()) {
model("expressionSelection", testMethod = "doTestExpressionSelection", pattern = """^([^\.]+)\.kt$""")
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2013 JetBrains s.r.o.
* 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.
@@ -78,6 +78,7 @@ public class JetStructureViewElement implements StructureViewTreeElement {
return myElement.canNavigateToSource();
}
@NotNull
@Override
public ItemPresentation getPresentation() {
return new ColoredItemPresentation() {
@@ -115,6 +116,7 @@ public class JetStructureViewElement implements StructureViewTreeElement {
};
}
@NotNull
@Override
public TreeElement[] getChildren() {
if (myElement instanceof JetFile) {
@@ -0,0 +1 @@
+EmptyFile.kt
@@ -0,0 +1,2 @@
-InheritedMembers.kt
Test (<root>)
@@ -0,0 +1,3 @@
class Test {
}
@@ -0,0 +1,5 @@
-SeveralClasses.kt
A (<root>)
B (<root>)
Some (<root>)
Other (<root>)
@@ -0,0 +1,4 @@
trait A
open class B
class Some: B(), A
class Other: A
@@ -0,0 +1,6 @@
-Simple.kt
-Test (<root>)
str:kotlin.String
some:kotlin.Int
foo():kotlin.Int
other():kotlin.Unit
@@ -0,0 +1,5 @@
class Test(val str: String) {
private val some = 1
protected fun foo() = some
public fun other() {}
}
@@ -0,0 +1,72 @@
/*
* 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.structureView
import org.jetbrains.jet.plugin.PluginTestCaseBase
import org.jetbrains.jet.plugin.JetLightCodeInsightFixtureTestCase
import com.intellij.util.ui.tree.TreeUtil
import com.intellij.openapi.util.io.FileUtil
import java.io.File
import com.intellij.testFramework.PlatformTestUtil
import com.intellij.ui.treeStructure.filtered.FilteringTreeStructure
import com.intellij.ide.util.FileStructurePopup
import com.intellij.ide.actions.ViewStructureAction
import com.intellij.openapi.fileEditor.impl.text.TextEditorProvider
import org.jetbrains.jet.JetTestUtils
public abstract class AbstractKotlinFileStructureTest : JetLightCodeInsightFixtureTestCase() {
override fun getTestDataPath() = PluginTestCaseBase.getTestDataPathBase() + "/structureView/fileStructure"
public fun doTest(path: String) {
myFixture.configureByFile(path)
val textEditor = TextEditorProvider.getInstance()!!.getTextEditor(myFixture.getEditor())
val popup = ViewStructureAction.createPopup(myFixture.getProject(), textEditor)
if (popup == null) throw AssertionError("popup mustn't be null")
popup.createCenterPanel()
popup.getTreeBuilder().getUi()!!.getUpdater()!!.setPassThroughMode(true)
popup.update()
val popupText = PlatformTestUtil.print(popup.getTree(), false)
JetTestUtils.assertEqualsToFile(File("${FileUtil.getNameWithoutExtension(path)}.after"), popupText)
}
public fun FileStructurePopup.update() {
getTreeBuilder().refilter()!!.doWhenProcessed {
getStructure().rebuild()
updateRecursively(getRootNode())
getTreeBuilder().updateFromRoot()
TreeUtil.expandAll(getTree())
}
}
fun FileStructurePopup.getFileStructureSpeedSearch() = getSpeedSearch() as FileStructurePopup.MyTreeSpeedSearch
fun FileStructurePopup.getStructure() = getTreeBuilder().getTreeStructure() as FilteringTreeStructure
fun FileStructurePopup.getRootNode() = getTreeBuilder().getRootElement() as FilteringTreeStructure.FilteringNode
fun FileStructurePopup.updateRecursively(node: FilteringTreeStructure.FilteringNode) {
node.update()
for (child in node.children()!!) {
updateRecursively(child)
}
}
}
@@ -0,0 +1,61 @@
/*
* 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.structureView;
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.structureView.AbstractKotlinFileStructureTest;
/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("idea/testData/structureView/fileStructure")
public class KotlinFileStructureTestGenerated extends AbstractKotlinFileStructureTest {
public void testAllFilesPresentInFileStructure() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage",
new File("idea/testData/structureView/fileStructure"), Pattern.compile("^(.+)\\.kt$"),
true);
}
@TestMetadata("EmptyFile.kt")
public void testEmptyFile() throws Exception {
doTest("idea/testData/structureView/fileStructure/EmptyFile.kt");
}
@TestMetadata("InheritedMembers.kt")
public void testInheritedMembers() throws Exception {
doTest("idea/testData/structureView/fileStructure/InheritedMembers.kt");
}
@TestMetadata("SeveralClasses.kt")
public void testSeveralClasses() throws Exception {
doTest("idea/testData/structureView/fileStructure/SeveralClasses.kt");
}
@TestMetadata("Simple.kt")
public void testSimple() throws Exception {
doTest("idea/testData/structureView/fileStructure/Simple.kt");
}
}