|
|
@@ -8,6 +8,7 @@ package net.ranides.assira.io;
|
|
|
|
|
|
import static net.ranides.assira.junit.NewAssert.*;
|
|
|
|
|
|
+import java.io.File;
|
|
|
import java.net.MalformedURLException;
|
|
|
import java.net.URL;
|
|
|
import java.nio.file.FileSystemNotFoundException;
|
|
|
@@ -120,6 +121,40 @@ public class PathUtilsTest {
|
|
|
fail("implement");
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void canonnical() {
|
|
|
+ Assume.assumeTrue(HostSystem.WINDOWS.detected());
|
|
|
+
|
|
|
+ assertEquals(Paths.get("c:/ms/Home"), PathUtils.normalize(Paths.get("c:/ms/Home")));
|
|
|
+ assertEquals(Paths.get("c:/ms/Home"), PathUtils.normalize(Paths.get("C:\\ms\\home")));
|
|
|
+
|
|
|
+ assertTrue(PathUtils.normalize(Paths.get("C:\\ms\\home")).startsWith(Paths.get("c:/MS")));
|
|
|
+
|
|
|
+ assertEquals(Paths.get("c:/dir/other/end"), PathUtils.normalize(Paths.get("c:/dir/something/../other/./end")));
|
|
|
+
|
|
|
+ assertFalse(Paths.get("c:/dir/something/../other/./end").startsWith("c:/dir/other") );
|
|
|
+ assertTrue(PathUtils.normalize(Paths.get("c:/dir/something/../other/./end")).startsWith("c:/dir/other"));
|
|
|
+
|
|
|
+ assertTrue(PathUtils.normalize(Paths.get("other/./end")).isAbsolute());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void canonnicalString() {
|
|
|
+ Assume.assumeTrue(HostSystem.WINDOWS.detected());
|
|
|
+
|
|
|
+ assertEquals("c:\\ms\\Home", PathUtils.normalize("c:/ms/Home"));
|
|
|
+ assertNotEquals("c:\\ms\\Home", PathUtils.normalize("C:\\ms\\home"));
|
|
|
+
|
|
|
+ assertTrue(PathUtils.normalize("c:\\ms\\home").startsWith("c:\\ms"));
|
|
|
+ assertFalse(PathUtils.normalize("C:\\ms\\home").startsWith("c:\\MS"));
|
|
|
+
|
|
|
+ assertEquals("c:\\dir\\other\\end", PathUtils.normalize("c:/dir/something/../other/./end"));
|
|
|
+
|
|
|
+ assertTrue(PathUtils.normalize("c:/dir/something/../other/./end").startsWith("c:\\dir\\other") );
|
|
|
+
|
|
|
+ assertTrue(new File(PathUtils.normalize("other/./end")).isAbsolute());
|
|
|
+ }
|
|
|
+
|
|
|
private static Path pce(String path, String ext) {
|
|
|
return PathUtils.changeExtension(Paths.get(path), ext);
|
|
|
}
|