package com.intellij.util;

import com.intellij.openapi.util.SystemInfo;
import junit.framework.Assert;
import junit.framework.TestCase;

/**
 * @author traff
 */
public class PathMappingSettingsTest extends TestCase {

  public static final String LOCAL_PATH_TO_FILE = "C:\\PythonSources\\src\\runner\\run.py";
  public static final String REMOTE_PATH_TO_FILE = "/home/testPrj/runner/run.py";

  public void testTrailingSlashes() {
    PathMappingSettings mappingSettings = create();

    mappingSettings.addMapping("C:\\PythonSources\\src\\", "/home/testPrj");

    Assert.assertEquals("C:/PythonSources/src/runner/run.py", mappingSettings.convertToLocal(REMOTE_PATH_TO_FILE));
    Assert.assertEquals("/home/testPrj/runner/run.py", mappingSettings.convertToRemote(LOCAL_PATH_TO_FILE));
  }

  public void testCaseNormalizingOnWin() {
    PathMappingSettings mappingSettings = create();

    mappingSettings.addMapping("c:/pythonsources/src", "/home/testPrj/");

    if (SystemInfo.isWindows) {
      Assert.assertEquals(REMOTE_PATH_TO_FILE, mappingSettings.convertToRemote(LOCAL_PATH_TO_FILE));
    }
    else {
      Assert.assertEquals(LOCAL_PATH_TO_FILE, mappingSettings.convertToRemote(LOCAL_PATH_TO_FILE)); //don't convert
    }
  }

  public void testOverlappingPaths() {
    PathMappingSettings mappingSettings = create();
    mappingSettings.addMapping("V:/site-packages", "/usr/lib/python2.6/site-packages");
    mappingSettings.addMapping("V:/site-packages64", "/usr/lib64/python2.6/site-packages");
    mappingSettings.addMapping("V:/bfms/django_root", "/opt/bfms");
    mappingSettings.addMapping("V:/bfms", "/opt/bfms_trunk");

    Assert.assertEquals("/usr/lib64/python2.6/site-packages/django", mappingSettings.convertToRemote("V:\\site-packages64\\django"));
    Assert.assertEquals("V:/site-packages64/django", mappingSettings.convertToLocal("/usr/lib64/python2.6/site-packages/django"));
    Assert.assertEquals("/opt/bfms/myapp", mappingSettings.convertToRemote("V:/bfms/django_root/myapp"));
    Assert.assertEquals("V:/bfms/django_root/myapp", mappingSettings.convertToLocal("/opt/bfms/myapp"));
  }

  private static PathMappingSettings create() {
    return new PathMappingSettings();
  }
}

@@ -73,32 +73,26 @@
 %0Aimport 
+org.
 junit.
-framework.
 Assert;%0A
@@ -102,32 +102,47 @@
 ort 
+org.
 junit.
-framework
+Before;%0Aimport org.junit
 .Test
-Case
 ;%0A%0A/
@@ -206,25 +206,8 @@
 est 
-extends TestCase 
 %7B%0A%0A 
@@ -387,51 +387,112 @@
 %0A  p
-ublic void testTrailingSlashes()
+rivate PathMappingSettings myMappingSettings;%0A%0A  @Before%0A  public void setUp() throws Exception
  %7B%0A    
-Path
+my
 Mapp
@@ -495,33 +495,43 @@
 MappingSettings 
-m
+= new PathM
 appingSettings =
@@ -528,35 +528,78 @@
 Settings
- = create();%0A
+();%0A  %7D%0A%0A  @Test%0A  public void testTrailingSlashes() %7B
 %0A    m
+yM
 appingSe
@@ -718,32 +718,34 @@
 unner/run.py%22, m
+yM
 appingSettings.c
@@ -833,24 +833,26 @@
 r/run.py%22, m
+yM
 appingSettin
@@ -893,24 +893,32 @@
 ILE));%0A  %7D%0A%0A
+  @Test%0A
   public voi
@@ -956,62 +956,11 @@
     
-PathMappingSettings mappingSettings = create();%0A%0A    m
+myM
 appi
@@ -1097,32 +1097,34 @@
 _PATH_TO_FILE, m
+yM
 appingSettings.c
@@ -1224,16 +1224,18 @@
 _FILE, m
+yM
 appingSe
@@ -1308,981 +1308,7 @@
 %0A  %7D
-%0A%0A  public void testOverlappingPaths() %7B%0A    PathMappingSettings mappingSettings = create();%0A    mappingSettings.addMapping(%22V:/site-packages%22, %22/usr/lib/python2.6/site-packages%22);%0A    mappingSettings.addMapping(%22V:/site-packages64%22, %22/usr/lib64/python2.6/site-packages%22);%0A    mappingSettings.addMapping(%22V:/bfms/django_root%22, %22/opt/bfms%22);%0A    mappingSettings.addMapping(%22V:/bfms%22, %22/opt/bfms_trunk%22);%0A%0A    Assert.assertEquals(%22/usr/lib64/python2.6/site-packages/django%22, mappingSettings.convertToRemote(%22V:%5C%5Csite-packages64%5C%5Cdjango%22));%0A    Assert.assertEquals(%22V:/site-packages64/django%22, mappingSettings.convertToLocal(%22/usr/lib64/python2.6/site-packages/django%22));%0A    Assert.assertEquals(%22/opt/bfms/myapp%22, mappingSettings.convertToRemote(%22V:/bfms/django_root/myapp%22));%0A    Assert.assertEquals(%22V:/bfms/django_root/myapp%22, mappingSettings.convertToLocal(%22/opt/bfms/myapp%22));%0A  %7D%0A%0A  private static PathMappingSettings create() %7B%0A    return new PathMappingSettings();%0A  %7D
 %0A%7D%0A

Migrate to JUnit4