blob: 2ab675de33d61d123d4f7579fbcf6d163b3c70b4 [file] [log] [blame]
package com.intellij.application.options;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* @author mike
*/
public class ReplacePathToMacroMapTest {
private ReplacePathToMacroMap myMap;
@Before
public final void setupMap() {
myMap = new ReplacePathToMacroMap();
myMap.addMacroReplacement("/tmp/foo", "MODULE_DIR");
}
@Test
public void testSubstitute_NoSubstitute() throws Exception {
assertEquals("/foo/bar", substitute("/foo/bar"));
}
@Test
public void testSubstitute_CompleteMatch() throws Exception {
assertEquals("$MODULE_DIR$", substitute("/tmp/foo"));
assertEquals("jar:$MODULE_DIR$", substitute("jar:/tmp/foo"));
assertEquals("jar:/$MODULE_DIR$", substitute("jar://tmp/foo"));
assertEquals("jar://$MODULE_DIR$", substitute("jar:///tmp/foo"));
assertEquals("file:$MODULE_DIR$", substitute("file:/tmp/foo"));
assertEquals("file:/$MODULE_DIR$", substitute("file://tmp/foo"));
assertEquals("file://$MODULE_DIR$", substitute("file:///tmp/foo"));
}
@Test
public void testSubstitute_PrefixMatch() throws Exception {
assertEquals("$MODULE_DIR$/bar", substitute("/tmp/foo/bar"));
assertEquals("jar:$MODULE_DIR$/bar", substitute("jar:/tmp/foo/bar"));
assertEquals("jar:/$MODULE_DIR$/bar", substitute("jar://tmp/foo/bar"));
assertEquals("jar://$MODULE_DIR$/bar", substitute("jar:///tmp/foo/bar"));
assertEquals("file:$MODULE_DIR$/bar", substitute("file:/tmp/foo/bar"));
assertEquals("file:/$MODULE_DIR$/bar", substitute("file://tmp/foo/bar"));
assertEquals("file://$MODULE_DIR$/bar", substitute("file:///tmp/foo/bar"));
}
@Test
public void testSubstitute_JarPrefixMatch() throws Exception {
assertEquals("$MODULE_DIR$!/bar", substitute("/tmp/foo!/bar"));
assertEquals("jar:$MODULE_DIR$!/bar", substitute("jar:/tmp/foo!/bar"));
assertEquals("jar:/$MODULE_DIR$!/bar", substitute("jar://tmp/foo!/bar"));
assertEquals("jar://$MODULE_DIR$!/bar", substitute("jar:///tmp/foo!/bar"));
assertEquals("file:$MODULE_DIR$!/bar", substitute("file:/tmp/foo!/bar"));
assertEquals("file:/$MODULE_DIR$!/bar", substitute("file://tmp/foo!/bar"));
assertEquals("file://$MODULE_DIR$!/bar", substitute("file:///tmp/foo!/bar"));
}
@Test
public void testSubstitute_WindowsRootSubstitution() throws Exception {
myMap.put("C:/", "../$MODULE_DIR$/");
assertEquals("../$MODULE_DIR$/", substitute("C:/"));
assertEquals("../$MODULE_DIR$/foo", substitute("C:/foo"));
}
@Test
public void testSubstitute_NoSubstituteInTheMiddleOccurs() throws Exception {
assertEquals("/bar/tmp/foo/bar", substitute("/bar/tmp/foo/bar"));
}
@Test
public void testSubstitute_NoDoubleSubstitution() throws Exception {
assertEquals("$MODULE_DIR$/bar/tmp/foo", substitute("/tmp/foo/bar/tmp/foo"));
}
@Test
public void testSubstitute_NoPartialSubstituteIsPerformed() throws Exception {
assertEquals("/tmp/foobar", substitute("/tmp/foobar"));
}
private String substitute(final String s) {
return myMap.substitute(s, true);
}
}