mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
SmartTreeStructureTest -> platform-tests; allow running platform-tests with module classpath
This commit is contained in:
@@ -15,40 +15,12 @@
|
||||
*/
|
||||
package com.intellij.testFramework;
|
||||
|
||||
import com.intellij.ide.util.treeView.AbstractTreeNode;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.roots.LanguageLevelModuleExtension;
|
||||
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
|
||||
import com.intellij.openapi.ui.Queryable;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
public class IdeaTestUtil extends PlatformTestUtil {
|
||||
public static Comparator<AbstractTreeNode> createComparator(final Queryable.PrintInfo printInfo) {
|
||||
return new Comparator<AbstractTreeNode>() {
|
||||
@Override
|
||||
public int compare(final AbstractTreeNode o1, final AbstractTreeNode o2) {
|
||||
String displayText1 = o1.toTestString(printInfo);
|
||||
String displayText2 = o2.toTestString(printInfo);
|
||||
return displayText1.compareTo(displayText2);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Use {@link #createComparator(com.intellij.openapi.ui.Queryable.PrintInfo)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Comparator<AbstractTreeNode> DEFAULT_COMPARATOR = new Comparator<AbstractTreeNode>() {
|
||||
@Override
|
||||
public int compare(AbstractTreeNode o1, AbstractTreeNode o2) {
|
||||
String displayText1 = o1.getTestPresentation();
|
||||
String displayText2 = o2.getTestPresentation();
|
||||
return displayText1.compareTo(displayText2);
|
||||
}
|
||||
};
|
||||
|
||||
public static void main(String[] args) {
|
||||
printDetectedPerformanceTimings();
|
||||
}
|
||||
|
||||
@@ -14,6 +14,11 @@
|
||||
<orderEntry type="library" name="EasyMock" level="project" />
|
||||
<orderEntry type="module" module-name="lvcs-impl" />
|
||||
<orderEntry type="module" module-name="vcs-impl" />
|
||||
<orderEntry type="module" module-name="platform-resources" scope="RUNTIME" />
|
||||
<orderEntry type="module" module-name="dom-impl" scope="RUNTIME" />
|
||||
<orderEntry type="module" module-name="relaxng" scope="RUNTIME" />
|
||||
<orderEntry type="module" module-name="spellchecker" scope="RUNTIME" />
|
||||
<orderEntry type="module" module-name="xdebugger-impl" scope="RUNTIME" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
+238
@@ -0,0 +1,238 @@
|
||||
package com.intellij.structureView;
|
||||
|
||||
import com.intellij.ide.util.treeView.smartTree.*;
|
||||
import com.intellij.testFramework.PlatformTestCase;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
public class SmartTreeStructureTest extends LightPlatformCodeInsightFixtureTestCase {
|
||||
private TestTreeModel myModel;
|
||||
|
||||
public SmartTreeStructureTest() {
|
||||
PlatformTestCase.initPlatformLangPrefix();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
TestTreeModel.StringTreeElement root = new TestTreeModel.StringTreeElement("root");
|
||||
myModel = new TestTreeModel(root);
|
||||
root.addChild("abc").addChild("abcde");
|
||||
root.addChild("bcd").addChild("bhgyt");
|
||||
root.addChild("ade").addChild("aed");
|
||||
root.addChild("bft").addChild("ttt");
|
||||
root.addChild("xxx");
|
||||
root.addChild("eed").addChild("zzz");
|
||||
root.addChild("xxx").addChild("aaa").addChild("bbb");
|
||||
|
||||
}
|
||||
|
||||
public void testGrouping() throws Exception {
|
||||
assertStructureEqual("root\n" +
|
||||
".Group:a\n" +
|
||||
"..Group:d\n" +
|
||||
"...ade\n" +
|
||||
"....Group:a\n" +
|
||||
".....Group:d\n" +
|
||||
"......aed\n" +
|
||||
"..abc\n" +
|
||||
"...Group:a\n" +
|
||||
"....Group:d\n" +
|
||||
".....abcde\n" +
|
||||
".Group:b\n" +
|
||||
"..Group:d\n" +
|
||||
"...bcd\n" +
|
||||
"....Group:b\n" +
|
||||
".....bhgyt\n" +
|
||||
"..Group:f\n" +
|
||||
"...bft\n" +
|
||||
"....ttt\n" +
|
||||
".Group:d\n" +
|
||||
"..eed\n" +
|
||||
"...zzz\n" +
|
||||
".xxx\n" +
|
||||
".xxx\n" +
|
||||
"..Group:a\n" +
|
||||
"...aaa\n" +
|
||||
"....Group:b\n" +
|
||||
".....bbb\n", PlatformTestUtil.DEFAULT_COMPARATOR);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void testFiltering() throws Exception {
|
||||
myModel.addFlter(new Filter(){
|
||||
@Override
|
||||
@NotNull
|
||||
public ActionPresentation getPresentation() {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getName() {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible(TreeElement treeNode) {
|
||||
return !treeNode.toString().contains("a");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReverted() {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
assertStructureEqual("root\n" +
|
||||
".Group:b\n" +
|
||||
"..Group:d\n" +
|
||||
"...bcd\n" +
|
||||
"....Group:b\n" +
|
||||
".....bhgyt\n" +
|
||||
"..Group:f\n" +
|
||||
"...bft\n" +
|
||||
"....ttt\n" +
|
||||
".Group:d\n" +
|
||||
"..eed\n" +
|
||||
"...zzz\n" +
|
||||
".xxx\n" +
|
||||
".xxx\n", PlatformTestUtil.DEFAULT_COMPARATOR);
|
||||
|
||||
}
|
||||
|
||||
public void testSorting() throws Exception {
|
||||
|
||||
|
||||
myModel.addSorter(new Sorter() {
|
||||
@Override
|
||||
public Comparator getComparator() {
|
||||
return new Comparator() {
|
||||
@Override
|
||||
public int compare(Object o1, Object o2) {
|
||||
if (o1 instanceof Group && !(o2 instanceof Group)) return -1;
|
||||
if (!(o1 instanceof Group) && o2 instanceof Group) return 1;
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public ActionPresentation getPresentation() {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getName() {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
});
|
||||
|
||||
myModel.addSorter(new Sorter() {
|
||||
@Override
|
||||
public Comparator getComparator() {
|
||||
return new Comparator() {
|
||||
@Override
|
||||
public int compare(Object o1, Object o2) {
|
||||
return o1.toString().compareTo(o2.toString());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public ActionPresentation getPresentation() {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getName() {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
});
|
||||
|
||||
assertStructureEqual("root\n" +
|
||||
".Group:a\n" +
|
||||
"..Group:d\n" +
|
||||
"...ade\n" +
|
||||
"....Group:a\n" +
|
||||
".....Group:d\n" +
|
||||
"......aed\n" +
|
||||
"..abc\n" +
|
||||
"...Group:a\n" +
|
||||
"....Group:d\n" +
|
||||
".....abcde\n" +
|
||||
".Group:b\n" +
|
||||
"..Group:d\n" +
|
||||
"...bcd\n" +
|
||||
"....Group:b\n" +
|
||||
".....bhgyt\n" +
|
||||
"..Group:f\n" +
|
||||
"...bft\n" +
|
||||
"....ttt\n" +
|
||||
".Group:d\n" +
|
||||
"..eed\n" +
|
||||
"...zzz\n" +
|
||||
".xxx\n" +
|
||||
".xxx\n" +
|
||||
"..Group:a\n" +
|
||||
"...aaa\n" +
|
||||
"....Group:b\n" +
|
||||
".....bbb\n"
|
||||
, null);
|
||||
|
||||
}
|
||||
|
||||
public void testUnsorted(){
|
||||
TestTreeModel.StringTreeElement root = new TestTreeModel.StringTreeElement("root");
|
||||
myModel = new TestTreeModel(root);
|
||||
root.addChild("xxx");
|
||||
root.addChild("bbb");
|
||||
root.addChild("bbb");
|
||||
root.addChild("zzz").addChild("ttt");
|
||||
root.addChild("aaa");
|
||||
root.addChild("aaa").addChild("zzz");
|
||||
root.addChild("xxx");
|
||||
assertStructureEqual("root\n" +
|
||||
".xxx\n" +
|
||||
".Group:b\n" +
|
||||
"..bbb\n" +
|
||||
"..bbb\n" +
|
||||
".zzz\n" +
|
||||
"..ttt\n" +
|
||||
".Group:a\n" +
|
||||
"..aaa\n" +
|
||||
"..aaa\n" +
|
||||
"...zzz\n" +
|
||||
".xxx\n", null);
|
||||
|
||||
}
|
||||
|
||||
private void assertStructureEqual(@NonNls String expected, Comparator comparator) {
|
||||
SmartTreeStructure structure = new SmartTreeStructure(myFixture.getProject(), myModel);
|
||||
|
||||
String actual = PlatformTestUtil.print(structure, structure.getRootElement(), 0, comparator, -1, '.', null).toString();
|
||||
|
||||
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -323,17 +323,6 @@ public class PlatformTestUtil {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
private static int doPrint(StringBuffer buffer,
|
||||
int currentLevel,
|
||||
Object node,
|
||||
AbstractTreeStructure structure,
|
||||
Comparator comparator,
|
||||
int maxRowCount,
|
||||
int currentLine,
|
||||
char paddingChar) {
|
||||
return doPrint(buffer, currentLevel, node, structure, comparator, maxRowCount, currentLine, paddingChar, null);
|
||||
}
|
||||
|
||||
private static int doPrint(StringBuffer buffer,
|
||||
int currentLevel,
|
||||
Object node,
|
||||
@@ -740,4 +729,29 @@ public class PlatformTestUtil {
|
||||
}
|
||||
return homePath;
|
||||
}
|
||||
|
||||
public static Comparator<AbstractTreeNode> createComparator(final Queryable.PrintInfo printInfo) {
|
||||
return new Comparator<AbstractTreeNode>() {
|
||||
@Override
|
||||
public int compare(final AbstractTreeNode o1, final AbstractTreeNode o2) {
|
||||
String displayText1 = o1.toTestString(printInfo);
|
||||
String displayText2 = o2.toTestString(printInfo);
|
||||
return displayText1.compareTo(displayText2);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Use {@link #createComparator(com.intellij.openapi.ui.Queryable.PrintInfo)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Comparator<AbstractTreeNode> DEFAULT_COMPARATOR = new Comparator<AbstractTreeNode>() {
|
||||
@Override
|
||||
public int compare(AbstractTreeNode o1, AbstractTreeNode o2) {
|
||||
String displayText1 = o1.getTestPresentation();
|
||||
String displayText2 = o2.getTestPresentation();
|
||||
return displayText1.compareTo(displayText2);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user