mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
a more behavioural PathMacroManagerTest
This commit is contained in:
+20
-14
@@ -96,14 +96,14 @@ public class PathMacroManagerTest {
|
||||
}
|
||||
|
||||
@Before
|
||||
public final void setupFileSystem() throws Exception {
|
||||
public final void setupFileSystem() {
|
||||
myOldFileSystem = FileSystem.FILE_SYSTEM;
|
||||
myFileSystem = new MockFileSystem();
|
||||
FileSystem.FILE_SYSTEM = myFileSystem;
|
||||
}
|
||||
|
||||
@After
|
||||
public final void restoreFilesystem() throws Exception {
|
||||
public final void restoreFilesystem() {
|
||||
FileSystem.FILE_SYSTEM = myOldFileSystem;
|
||||
}
|
||||
|
||||
@@ -132,12 +132,11 @@ public class PathMacroManagerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRightMacrosOrder_RelativeValues_NoVariables() throws Exception {
|
||||
public void testRightMacrosOrder_RelativeValues_NoVariables() {
|
||||
setUpMocks("/tmp/foo");
|
||||
|
||||
final ReplacePathToMacroMap replacePathMap = new ModulePathMacroManager(myPathMacros, myModule).getReplacePathMap();
|
||||
final String s = replacePathMap.mapToString();
|
||||
assertEquals("file:/tmp/foo/module -> file:$MODULE_DIR$\n" +
|
||||
assertReplacements(replacePathMap, "file:/tmp/foo/module -> file:$MODULE_DIR$\n" +
|
||||
"file://tmp/foo/module -> file:/$MODULE_DIR$\n" +
|
||||
"file:///tmp/foo/module -> file://$MODULE_DIR$\n" +
|
||||
"jar:/tmp/foo/module -> jar:$MODULE_DIR$\n" +
|
||||
@@ -171,16 +170,15 @@ public class PathMacroManagerTest {
|
||||
"jar:/tmp -> jar:$MODULE_DIR$/../..\n" +
|
||||
"jar://tmp -> jar:/$MODULE_DIR$/../..\n" +
|
||||
"jar:///tmp -> jar://$MODULE_DIR$/../..\n" +
|
||||
"/tmp -> $MODULE_DIR$/../..", s);
|
||||
"/tmp -> $MODULE_DIR$/../..");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPathsOutsideProject() throws Exception {
|
||||
public void testPathsOutsideProject() {
|
||||
setUpMocks("/tmp/foo");
|
||||
|
||||
final ReplacePathToMacroMap replacePathMap = new ProjectPathMacroManager(myPathMacros, myProject).getReplacePathMap();
|
||||
final String s = replacePathMap.mapToString();
|
||||
assertEquals("file:/tmp/foo -> file:$PROJECT_DIR$\n" +
|
||||
assertReplacements(replacePathMap, "file:/tmp/foo -> file:$PROJECT_DIR$\n" +
|
||||
"file://tmp/foo -> file:/$PROJECT_DIR$\n" +
|
||||
"file:///tmp/foo -> file://$PROJECT_DIR$\n" +
|
||||
"jar:/tmp/foo -> jar:$PROJECT_DIR$\n" +
|
||||
@@ -207,7 +205,16 @@ public class PathMacroManagerTest {
|
||||
"jar:/tmp -> jar:$PROJECT_DIR$/..\n" +
|
||||
"jar://tmp -> jar:/$PROJECT_DIR$/..\n" +
|
||||
"jar:///tmp -> jar://$PROJECT_DIR$/..\n" +
|
||||
"/tmp -> $PROJECT_DIR$/..", s);
|
||||
"/tmp -> $PROJECT_DIR$/..");
|
||||
}
|
||||
|
||||
private static void assertReplacements(ReplacePathToMacroMap map, String replacements) {
|
||||
for (String s : replacements.split("\n")) {
|
||||
String[] split = s.split(" -> ");
|
||||
String path = split[0];
|
||||
String replaced = split[1];
|
||||
assertEquals(replaced, map.substitute(path, true));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -221,12 +228,11 @@ public class PathMacroManagerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProjectUnderUserHome() throws Exception {
|
||||
public void testProjectUnderUserHome() {
|
||||
setUpMocks(USER_HOME + "/IdeaProjects/foo");
|
||||
|
||||
final ReplacePathToMacroMap replacePathMap = new ModulePathMacroManager(myPathMacros, myModule).getReplacePathMap();
|
||||
final String s = replacePathMap.mapToString();
|
||||
assertEquals("file:" + USER_HOME + "/IdeaProjects/foo/module -> file:$MODULE_DIR$\n" +
|
||||
assertReplacements(replacePathMap, "file:" + USER_HOME + "/IdeaProjects/foo/module -> file:$MODULE_DIR$\n" +
|
||||
"file:/" + USER_HOME + "/IdeaProjects/foo/module -> file:/$MODULE_DIR$\n" +
|
||||
"file://" + USER_HOME + "/IdeaProjects/foo/module -> file://$MODULE_DIR$\n" +
|
||||
"jar:" + USER_HOME + "/IdeaProjects/foo/module -> jar:$MODULE_DIR$\n" +
|
||||
@@ -260,6 +266,6 @@ public class PathMacroManagerTest {
|
||||
"file://" + USER_HOME + " -> file://$USER_HOME$\n" +
|
||||
"jar:" + USER_HOME + " -> jar:$USER_HOME$\n" +
|
||||
"jar:/" + USER_HOME + " -> jar:/$USER_HOME$\n" +
|
||||
"jar://" + USER_HOME + " -> jar://$USER_HOME$", s);
|
||||
"jar://" + USER_HOME + " -> jar://$USER_HOME$");
|
||||
}
|
||||
}
|
||||
|
||||
-18
@@ -23,7 +23,6 @@ import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.ContainerUtilRt;
|
||||
import gnu.trove.TObjectIntHashMap;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
@@ -237,21 +236,4 @@ public class ReplacePathToMacroMap extends PathMacroMap {
|
||||
myMacroMap.put(path, replacement);
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
public String mapToString() {
|
||||
final StringBuilder buf = new StringBuilder();
|
||||
|
||||
final List<String> pathIndex = getPathIndex();
|
||||
for (String s : pathIndex) {
|
||||
if (buf.length() > 0) buf.append("\n");
|
||||
buf.append(s);
|
||||
buf.append(" -> ");
|
||||
buf.append(myMacroMap.get(s));
|
||||
}
|
||||
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user