more tests to platform-tests

This commit is contained in:
Dmitry Jemerov
2011-12-16 18:43:35 +01:00
parent 07908fe7ce
commit 74c214e099
5 changed files with 657 additions and 0 deletions

View File

@@ -0,0 +1,116 @@
package com.intellij.unscramble;
import junit.framework.TestCase;
import org.jetbrains.annotations.NonNls;
/**
* @author cdr
*/
public class NormalizeTextTest extends TestCase {
public void testCausedBy() {
doTest("javax.faces.FacesException: Error calling action method of component with id _id6:_id10\n" +
" at java.lang.Th\n" +
"read.run(Thread.java:626)\n" +
"Caused by: javax.faces.el.EvaluationException: Exception while invoking expression #{_loginAction.login}\n" +
" at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:153)\n" +
" at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:63)\n",
"javax.faces.FacesException: Error calling action method of component with id _id6:_id10\n" +
" at java.lang.Thread.run(Thread.java:626)\n" +
"Caused by: javax.faces.el.EvaluationException: Exception while invoking expression #{_loginAction.login}\n" +
" at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:153)\n" +
" at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:63)"
);
}
public void testThreadNames() {
doTest("\"Background process\" prio=6 tid=0x21193b88 nid=0x11ea4 waiting on condition [0x2\n" + "2cbf000..0x22cbfd68]\n" +
" at java.lang.Thread.sleep(Native Method)\n" + " at com.intellij.util.ui.Timer$1.run(Timer.java:23)\n" + "\n" +
"\"Alarm pool\" prio=6 tid=0x37cacbe0 nid=0x7940 waiting on condition [0x3972f000..\n" + "0x3972fae8]\n" +
" at sun.misc.Unsafe.park(Native Method)\n" +
" at java.util.concurrent.locks.LockSupport.park(LockSupport.java:118)\n" +
" at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject\n" +
".await(AbstractQueuedSynchronizer.java:1767)\n\n" +
" at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.jav\n" + "a:359)\n" +
" at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.ja\n" + "va:470)\n" +
" at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor\n" + ".java:674)\n" +
" at java.lang.Thread.run(Thread.java:595)",
"\"Background process\" prio=6 tid=0x21193b88 nid=0x11ea4 waiting on condition [0x22cbf000..0x22cbfd68]\n" +
" at java.lang.Thread.sleep(Native Method)\n" +
" at com.intellij.util.ui.Timer$1.run(Timer.java:23)\n" +
"\n" +
"\"Alarm pool\" prio=6 tid=0x37cacbe0 nid=0x7940 waiting on condition [0x3972f000..0x3972fae8]\n" +
" at sun.misc.Unsafe.park(Native Method)\n" +
" at java.util.concurrent.locks.LockSupport.park(LockSupport.java:118)\n" +
" at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:1767)\n" +
" at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:359)\n" +
" at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:470)\n" +
" at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:674)\n" +
" at java.lang.Thread.run(Thread.java:595)"
);
}
public void testLocked() {
doTest(" at com.intellij.lang.jsp.JspFileViewProviderImpl.getKeyPrefixes(JspFileV\n" + "iewProviderImpl.java:76)\n" +
" at com.intellij.lang.jsp.JspFileViewProviderImpl.getKnownTaglibPrefixes(\n" + "JspFileViewProviderImpl.java:89)\n" +
" - locked <0x04cc0768> (a java.lang.Object)\n" +
" at com.intellij.psi.impl.source.parsing.jsp.JspLexer.doInitOriginal(JspL\n" + "exer.java:39)\n" +
" at com.intellij.psi.impl.source.parsing.jsp.JspLexer.start(JspLexer.java\n" + ":49)",
" at com.intellij.lang.jsp.JspFileViewProviderImpl.getKeyPrefixes(JspFileViewProviderImpl.java:76)\n" +
" at com.intellij.lang.jsp.JspFileViewProviderImpl.getKnownTaglibPrefixes(JspFileViewProviderImpl.java:89)\n" +
" - locked <0x04cc0768> (a java.lang.Object)\n" +
" at com.intellij.psi.impl.source.parsing.jsp.JspLexer.doInitOriginal(JspLexer.java:39)\n" +
" at com.intellij.psi.impl.source.parsing.jsp.JspLexer.start(JspLexer.java:49)");
}
public void testAtSplit() {
doTest("java.lang.Throwable\n" +
"at\n" +
"com.intellij.openapi.util.objectTree.ObjectNode.<init>(ObjectNode.jav\n" + "a:31)\n" +
"at\n" +
"com.intellij.openapi.util.objectTree.ObjectTree.getNodeFor(ObjectTree\n" + ".java:79)",
"java.lang.Throwable\n" +
"at com.intellij.openapi.util.objectTree.ObjectNode.<init>(ObjectNode.java:31)\n" +
"at com.intellij.openapi.util.objectTree.ObjectTree.getNodeFor(ObjectTree.java:79)");
}
public void testSplitMergedLines() {
doTest("org.apache.velocity.exception.MethodInvocationException " +
"at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:246) " +
"at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:175) " +
"at org.apache.velocity.runtime.parser.node.ASTReference.value(ASTReference.java:327) " +
"at org.apache.velocity.runtime.parser.node.ASTExpression.value(ASTExpression.java:51) " +
"at org.apache.velocity.runtime.parser.node.ASTSetDirective.render(ASTSetDirective.java:95) " +
"at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:55) " +
"at org.apache.velocity.runtime.directive.Foreach.render(Foreach.java:166) " +
"at org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:114) " +
"at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:230) " +
"at org.apache.velocity.runtime.directive.VelocimacroProxy.render(VelocimacroProxy.java:172) " +
"at org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:114) " +
"at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:230) " +
"at org.apache.velocity.Template.merge(Template.java:256)",
"org.apache.velocity.exception.MethodInvocationException\n" +
"at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:246)\n" +
"at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:175)\n" +
"at org.apache.velocity.runtime.parser.node.ASTReference.value(ASTReference.java:327)\n" +
"at org.apache.velocity.runtime.parser.node.ASTExpression.value(ASTExpression.java:51)\n" +
"at org.apache.velocity.runtime.parser.node.ASTSetDirective.render(ASTSetDirective.java:95)\n" +
"at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:55)\n" +
"at org.apache.velocity.runtime.directive.Foreach.render(Foreach.java:166)\n" +
"at org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:114)\n" +
"at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:230)\n" +
"at org.apache.velocity.runtime.directive.VelocimacroProxy.render(VelocimacroProxy.java:172)\n" +
"at org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:114)\n" +
"at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:230)\n" +
"at org.apache.velocity.Template.merge(Template.java:256)");
}
private static void doTest(@NonNls String stackTrace, @NonNls String expected) {
String normalized = UnscrambleDialog.normalizeText(stackTrace);
assertEquals(expected, normalized);
}
}

View File

@@ -0,0 +1,183 @@
package com.intellij.openapi.fileChooser.ex;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.testFramework.FlyIdeaTestCase;
import com.intellij.util.ArrayUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.io.File;
import java.io.IOException;
import java.util.*;
public class FileChooserCompletionTest extends FlyIdeaTestCase {
private File myParent;
private LocalFsFinder myFinder;
private final Map<String, String> myMacros = new HashMap<String, String>();
private File myFolder11;
private File myFolder21;
private void basicSetup() throws IOException {
myParent = getTempDir();
myFolder11 = new File(myParent, "folder1/folder11");
assertTrue(myFolder11.mkdirs());
assertTrue(new File(myParent, "a").mkdirs());
myFolder21 = new File(myParent, "folder1/folder11/folder21");
assertTrue(myFolder21.mkdirs());
assertTrue(new File(myParent, "folder1/folder12").mkdirs());
assertTrue(new File(myParent, "file1").mkdir());
}
public void testBasicComplete() throws Exception {
assertComplete("", ArrayUtil.EMPTY_STRING_ARRAY, null);
assertComplete("1", ArrayUtil.EMPTY_STRING_ARRAY, null);
basicSetup();
assertComplete("f", ArrayUtil.EMPTY_STRING_ARRAY, null);
assertComplete("/", new String[] {
"a",
"folder1",
"file1"
}, "a");
assertComplete("/f", new String[] {
"folder1",
"file1"
}, "file1");
assertComplete("/fo", new String[] {
"folder1",
}, "folder1");
assertComplete("/folder", new String[] {
"folder1",
}, "folder1");
assertComplete("/folder1", new String[] {
"folder1",
}, "folder1");
assertComplete("/folder1/", new String[] {
"folder11",
"folder12",
}, "folder11");
assertComplete("/folder1/folder1", new String[] {
"folder11",
"folder12",
}, "folder11");
assertComplete("/foo", ArrayUtil.EMPTY_STRING_ARRAY, null);
assertTrue(new File(myParent, "qw/child.txt").mkdirs());
assertTrue(new File(myParent, "qwe").mkdir());
assertComplete("/qw", new String[] {
"qw",
"qwe"
}, "qw");
assertComplete("/qw/", new String[] {
"child.txt"
}, "child.txt");
}
public void testComplete() throws Exception {
basicSetup();
myParent = null;
myMacros.put("$FOLDER_11$", myFolder11.getAbsolutePath());
myMacros.put("$FOLDER_21$", myFolder21.getAbsolutePath());
myMacros.put("$WHATEVER$", "/somepath");
assertComplete("$", new String[] {"$FOLDER_11$", "$FOLDER_21$"}, "$FOLDER_11$");
}
private void assertComplete(String typed, String[] expected, String preselected) {
myFinder = new LocalFsFinder() {
@Override
public LookupFile find(@NotNull final String path) {
final File ioFile = new File(path);
return ioFile.isAbsolute() ? new IoFile(ioFile) : null;
}
};
String typedText = typed.replace("/", myFinder.getSeparator());
final FileTextFieldImpl.CompletionResult result = new FileTextFieldImpl.CompletionResult();
result.myCompletionBase = myParent != null ? (myParent.getAbsolutePath() + typedText) : typedText;
new FileTextFieldImpl(new JTextField(), myFinder, new FileLookup.LookupFilter() {
@Override
public boolean isAccepted(final FileLookup.LookupFile file) {
return true;
}
}, myMacros, getRootDisposable()) {
@Override
@Nullable
public VirtualFile getSelectedFile() {
return null;
}
}.processCompletion(result);
for (int i = 0; i < expected.length; i++) {
expected[i] = expected[i].replace("/", myFinder.getSeparator());
}
final List<String> expectedList = Arrays.asList(expected);
Collections.sort(result.myToComplete, new Comparator<FileLookup.LookupFile>() {
@Override
public int compare(final FileLookup.LookupFile o1, final FileLookup.LookupFile o2) {
return o1.getName().compareTo(o2.getName());
}
});
Collections.sort(expectedList);
assertEquals(asString(expectedList, result), asString(result.myToComplete, result));
final String preselectedText = preselected != null ? preselected.replace("/", myFinder.getSeparator()) : null;
assertEquals(preselectedText, toFileText(result.myPreselected, result));
if (preselected != null) {
assertTrue(result.myToComplete.contains(result.myPreselected));
}
}
private String asString(List objects, FileTextFieldImpl.CompletionResult completion) {
StringBuffer result = new StringBuffer();
for (int i = 0; i < objects.size(); i++) {
final Object each = objects.get(i);
result.append(toFileText(each, completion));
if (i < objects.size() - 1) {
result.append("\n");
}
}
return result.toString();
}
private String toFileText(final Object each, final FileTextFieldImpl.CompletionResult completion) {
String text = null;
if (each instanceof FileLookup.LookupFile) {
final FileLookup.LookupFile file = (FileLookup.LookupFile)each;
if (file.getMacro() != null) {
text = file.getMacro();
} else {
text = file.getName();
}
} else if (each != null) {
text = each.toString();
}
if (text == null) return null;
return (completion.myKidsAfterSeparator.contains(each) ? myFinder.getSeparator() : "" ) + text;
}
}

View File

@@ -0,0 +1,194 @@
/*
* Copyright (c) 2000-2007 JetBrains s.r.o. All Rights Reserved.
*/
package com.intellij.patterns;
import com.intellij.openapi.util.Key;
import com.intellij.testFramework.UsefulTestCase;
import com.intellij.util.ProcessingContext;
import java.util.Arrays;
import static com.intellij.patterns.StandardPatterns.*;
/**
* @author peter
*/
public class StandardPatternsTest extends UsefulTestCase {
public void testNull() throws Throwable {
assertTrue(object().isNull().accepts(null));
assertFalse(object().isNull().accepts(""));
assertFalse(string().isNull().accepts(""));
assertTrue(string().isNull().accepts(null));
}
public void testString() throws Throwable {
final ElementPattern pattern = string();
assertFalse(string().accepts(new Object()));
assertTrue(pattern.accepts(""));
}
public void testStartsWith() throws Throwable {
final ElementPattern pattern = string().startsWith("abc");
assertFalse(pattern.accepts(""));
assertTrue(pattern.accepts("abcd"));
assertTrue(pattern.accepts("abc"));
assertFalse(string().startsWith("abc").accepts(new Object()));
}
public void testEndsWith() throws Throwable {
final ElementPattern pattern = string().endsWith("abc");
assertFalse(pattern.accepts(""));
assertFalse(pattern.accepts("abcd"));
assertTrue(pattern.accepts("abc"));
}
private static void checkPrefixSuffix(final ElementPattern pattern) {
assertFalse(pattern.accepts(""));
assertFalse(pattern.accepts("abcd"));
assertTrue(pattern.accepts("abc"));
assertTrue(pattern.accepts("abcdabc"));
assertFalse(pattern.accepts("abcdab"));
}
public void testPrefixSuffix() throws Throwable {
checkPrefixSuffix(string().endsWith("abc").startsWith("abc"));
}
public void testAnd1() throws Throwable {
checkPrefixSuffix(and(string().endsWith("abc"), string().startsWith("abc")));
}
public void testAnd2() throws Throwable {
checkPrefixSuffix(string().endsWith("abc").and(string().startsWith("abc")));
}
public void testOr1() throws Throwable {
checkOr(or(string().endsWith("abc"), string().startsWith("abc")));
}
public void testNot1() throws Throwable {
final ElementPattern pattern = not(or(string().endsWith("abc"), string().startsWith("abc")));
assertTrue(pattern.accepts(""));
assertTrue(pattern.accepts("xxx"));
assertFalse(pattern.accepts("abcd"));
assertTrue(pattern.accepts("dabcd"));
assertFalse(pattern.accepts("abc"));
assertFalse(pattern.accepts("abcdabc"));
assertFalse(pattern.accepts("abcdab"));
}
private static void checkOr(final ElementPattern filterFactory) {
assertFalse(filterFactory.accepts(""));
assertFalse(filterFactory.accepts("xxx"));
assertTrue(filterFactory.accepts("abcd"));
assertFalse(filterFactory.accepts("dabcd"));
assertTrue(filterFactory.accepts("abc"));
assertTrue(filterFactory.accepts("abcdabc"));
assertTrue(filterFactory.accepts("abcdab"));
}
public void testEquals() throws Throwable {
final Object foo = new Object();
final Object bar = new Object();
ElementPattern objectPattern = object().equalTo(foo);
assertTrue(objectPattern.accepts(foo));
assertFalse(objectPattern.accepts(bar));
ElementPattern stringPattern = string().equalTo("foo");
assertTrue(stringPattern.accepts("foo"));
assertFalse(stringPattern.accepts("bar"));
}
public void testAll() throws Throwable {
ElementPattern pattern = collection(String.class).all(string().startsWith("abc"));
assertTrue(pattern.accepts(Arrays.asList("abc")));
assertTrue(pattern.accepts(Arrays.asList("abc", "abcd")));
assertFalse(pattern.accepts(Arrays.asList("abc", "bcd")));
}
public void testAtLeastOne() throws Throwable {
ElementPattern pattern = collection(String.class).atLeastOne(string().startsWith("abc"));
assertTrue(pattern.accepts(Arrays.asList("abc")));
assertTrue(pattern.accepts(Arrays.asList("abc", "abcd")));
assertTrue(pattern.accepts(Arrays.asList("abc", "bcd")));
assertFalse(pattern.accepts(Arrays.asList("bc", "bcd")));
assertTrue(pattern.accepts(Arrays.asList("bc", "abc")));
}
public void testFilter() throws Throwable {
ElementPattern pattern = collection(String.class).filter(string().endsWith("x"), collection(String.class).all(string().startsWith("abc")));
assertTrue(pattern.accepts(Arrays.asList("abc")));
assertTrue(pattern.accepts(Arrays.asList("abc", "abcd")));
assertFalse(pattern.accepts(Arrays.asList("bcx", "bcd")));
assertTrue(pattern.accepts(Arrays.asList("abcx", "abc")));
}
public void testFirst() throws Throwable {
ElementPattern pattern = collection(String.class).first(string().startsWith("abc"));
assertFalse(pattern.accepts(Arrays.<String>asList()));
assertTrue(pattern.accepts(Arrays.asList("abc")));
assertTrue(pattern.accepts(Arrays.asList("abc", "abcd")));
assertTrue(pattern.accepts(Arrays.asList("abc", "bcd")));
assertFalse(pattern.accepts(Arrays.asList("bc", "bcd")));
assertFalse(pattern.accepts(Arrays.asList("bc", "abc")));
}
public void testLast() throws Throwable {
//collection(String.class)
ElementPattern pattern = collection(String.class).last(string().startsWith("abc"));
assertFalse(pattern.accepts(Arrays.<String>asList()));
assertTrue(pattern.accepts(Arrays.asList("abc")));
assertTrue(pattern.accepts(Arrays.asList("abc", "abcd")));
assertFalse(pattern.accepts(Arrays.asList("abc", "bcd")));
assertFalse(pattern.accepts(Arrays.asList("bc", "bcd")));
assertTrue(pattern.accepts(Arrays.asList("bc", "abc")));
}
public void testSize() throws Throwable {
final CollectionPattern<String> filter = collection(String.class);
assertTrue(filter.size(0).accepts(Arrays.<String>asList()));
assertFalse(filter.size(0).accepts(Arrays.asList("abc")));
assertFalse(filter.size(0).accepts(Arrays.asList("abc", "abc")));
assertFalse(filter.size(1).accepts(Arrays.<String>asList()));
assertTrue(filter.size(1).accepts(Arrays.asList("abc")));
assertFalse(filter.size(1).accepts(Arrays.asList("abc", "abc")));
assertFalse(filter.size(2).accepts(Arrays.<String>asList()));
assertFalse(filter.size(2).accepts(Arrays.asList("abc")));
assertTrue(filter.size(2).accepts(Arrays.asList("abc", "abc")));
}
public void testEmpty() throws Throwable {
final CollectionPattern<String> filter = collection(String.class);
assertTrue(filter.empty().accepts(Arrays.<String>asList()));
assertFalse(filter.empty().accepts(Arrays.asList("abc")));
assertFalse(filter.empty().accepts(Arrays.asList("abc", "abc")));
assertFalse(not(filter.empty()).accepts(Arrays.<String>asList()));
assertTrue(not(filter.empty()).accepts(Arrays.asList("abc")));
assertTrue(not(filter.empty()).accepts(Arrays.asList("abc", "abc")));
}
public void testSave() throws Throwable {
Key<String> key = Key.create("abc");
final ProcessingContext context = new ProcessingContext();
assertFalse(string().contains("abc").save(key).accepts(null));
assertNull(context.get(key));
assertFalse(string().contains("abc").save(key).accepts("def"));
assertNull(context.get(key));
final String s = "defabcdef";
assertTrue(string().contains("abc").save(key).accepts(s, context));
assertSame(s, context.get(key));
}
}

View File

@@ -0,0 +1,42 @@
package com.intellij.psi;
import junit.framework.TestCase;
import java.util.Arrays;
import com.intellij.psi.codeStyle.NameUtil;
/**
* @author dsl
*/
public class PsiNameHelperTest extends TestCase {
public void testSplitIntoWords1() throws Exception {
assertSplitEquals(new String[]{"I", "Base"}, "IBase");
}
public void testSplitIntoWords2() throws Exception {
assertSplitEquals(new String[]{"Order", "Index"}, "OrderIndex");
}
public void testSplitIntoWords3() throws Exception {
assertSplitEquals(new String[]{"order", "Index"}, "orderIndex");
}
public void testSplitIntoWords4() throws Exception {
assertSplitEquals(new String[]{"Order", "Index"}, "Order_Index");
}
public void testSplitIntoWords5() throws Exception {
assertSplitEquals(new String[]{"ORDER", "INDEX"}, "ORDER_INDEX");
}
public void testSplitIntoWords6() throws Exception {
assertSplitEquals(new String[]{"gg", "J"}, "ggJ");
}
private void assertSplitEquals(String[] expected, String name) {
final String[] result = NameUtil.splitNameIntoWords(name);
assertEquals(Arrays.asList(expected).toString(), Arrays.asList(result).toString());
}
}

View File

@@ -0,0 +1,122 @@
package com.intellij.ui;
import com.intellij.testFramework.PlatformTestUtil;
import com.intellij.util.ThrowableRunnable;
import com.intellij.util.ui.FilePathSplittingPolicy;
import junit.framework.TestCase;
import org.jetbrains.annotations.NonNls;
import java.io.File;
/**
* author: lesya
*/
public class FileNameSplittingTest extends TestCase {
private static final File FILE = new File("c:/dir1/dir2/dir3/dir4/file.txt");
private FilePathSplittingPolicy myPolicy;
public void testSplitByLetter() {
myPolicy = FilePathSplittingPolicy.SPLIT_BY_LETTER;
@NonNls String[] expectedStrings = {
"t",
"xt",
"txt",
".txt",
"e.txt",
"le.txt",
"ile.txt",
"file.txt",
".file.txt",
"..file.txt",
"...file.txt",
"c...file.txt",
"c.../file.txt",
"c:.../file.txt",
"c:...4/file.txt",
"c:/...4/file.txt",
"c:/...r4/file.txt",
"c:/d...r4/file.txt",
"c:/d...ir4/file.txt",
"c:/di...ir4/file.txt",
"c:/di...dir4/file.txt",
"c:/dir...dir4/file.txt",
"c:/dir.../dir4/file.txt",
"c:/dir1.../dir4/file.txt",
"c:/dir1/...3/dir4/file.txt",
"c:/dir1/...r3/dir4/file.txt",
"c:/dir1/d...r3/dir4/file.txt",
"c:/dir1/d...ir3/dir4/file.txt",
"c:/dir1/di...ir3/dir4/file.txt",
"c:/dir1/dir2/dir3/dir4/file.txt"
};
for (String expectedString : expectedStrings) {
doTest(expectedString, expectedString.length());
}
}
public void testSplitByFileSeparator(){
myPolicy = FilePathSplittingPolicy.SPLIT_BY_SEPARATOR;
@NonNls String[] expectedStrings = {
"...",
"...",
"...",
"...",
"...",
"...",
"...",
"file.txt",
"file.txt",
"file.txt",
"...file.txt",
"...file.txt",
"c:...file.txt",
"c:.../file.txt",
"c:/.../file.txt",
"c:/.../file.txt",
"c:/.../file.txt",
"c:/.../file.txt",
"c:/...dir4/file.txt",
"c:/...dir4/file.txt",
"c:/...dir4/file.txt",
"c:/...dir4/file.txt",
"c:/dir1...dir4/file.txt",
"c:/dir1.../dir4/file.txt",
"c:/dir1/.../dir4/file.txt",
"c:/dir1/.../dir4/file.txt",
"c:/dir1/.../dir4/file.txt",
"c:/dir1/.../dir4/file.txt",
"c:/dir1/...dir3/dir4/file.txt",
"c:/dir1/...dir3/dir4/file.txt",
"c:/dir1/dir2/dir3/dir4/file.txt"
};
for (int i = 0; i < expectedStrings.length; i++) {
int count = i + 1;
String expectedString = expectedStrings[i];
assertTrue(expectedString, expectedString.length() <= count || i < 3);
doTest(expectedString, count);
}
}
public void testPerformance() {
myPolicy = FilePathSplittingPolicy.SPLIT_BY_SEPARATOR;
PlatformTestUtil.startPerformanceTest("FileNameSplitting performance", 70, new ThrowableRunnable() {
@Override
public void run() throws Exception {
for (int i = 0; i < 100; i++) {
for (int j = 0; j < FILE.getPath().length(); j++)
myPolicy.getPresentableName(FILE, j);
}
}
}).cpuBound().assertTiming();
}
private void doTest(String expected, int count) {
assertEquals(expected.replace('/', File.separatorChar),
myPolicy.getPresentableName(FILE, count));
}
}