Skip to content

Commit

Permalink
Merge pull request #409 from oblac/windows
Browse files Browse the repository at this point in the history
Windows fixxx
  • Loading branch information
igr authored May 5, 2017
2 parents cd5d627 + 28f1831 commit 50451f5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
19 changes: 13 additions & 6 deletions jodd-core/src/test/java/jodd/io/FileNameUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@

package jodd.io;

import jodd.util.StringUtil;
import jodd.util.SystemUtil;
import org.junit.Test;

import java.io.File;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -148,15 +151,19 @@ public void testResolveHome() {
assertEquals("qwe", FileNameUtil.resolveHome("qwe"));
assertEquals("", FileNameUtil.resolveHome(""));
assertEquals(SystemUtil.userHome(), FileNameUtil.resolveHome("~"));
assertEquals(SystemUtil.userHome() + "/", FileNameUtil.resolveHome("~/"));
assertEquals(SystemUtil.userHome() + "/foo", FileNameUtil.resolveHome("~/foo"));
assertEquals(fixpath(SystemUtil.userHome() + "/"), FileNameUtil.resolveHome(fixpath("~/")));
assertEquals(fixpath(SystemUtil.userHome() + "/foo"), FileNameUtil.resolveHome(fixpath("~/foo")));
}

@Test
public void testGetRelativePaths() {
assertEquals("../../b/c", FileNameUtil.relativePath("/a/b/c", "/a/x/y/"));
assertEquals("../../b/c", FileNameUtil.relativePath("/m/n/o/a/b/c", "/m/n/o/a/x/y/"));
assertEquals("stuff/xyz.dat", FileNameUtil.relativePath("/var/data/stuff/xyz.dat", "/var/data/"));
assertEquals("../../../a/b/c", FileNameUtil.relativePath("/a/b/c", "/m/n/o"));
assertEquals(fixpath("../../b/c"), FileNameUtil.relativePath("/a/b/c", "/a/x/y/"));
assertEquals(fixpath("../../b/c"), FileNameUtil.relativePath("/m/n/o/a/b/c", "/m/n/o/a/x/y/"));
assertEquals(fixpath("stuff/xyz.dat"), FileNameUtil.relativePath("/var/data/stuff/xyz.dat", "/var/data/"));
assertEquals(fixpath("../../../a/b/c"), FileNameUtil.relativePath("/a/b/c", "/m/n/o"));
}

private static String fixpath(String path) {
return StringUtil.replace(path, "/", File.separator);
}
}
27 changes: 16 additions & 11 deletions jodd-core/src/test/java/jodd/util/PathUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import jodd.io.PathUtil;
import org.junit.Test;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;

Expand All @@ -37,24 +38,28 @@ public class PathUtilTest {

@Test
public void testResolve() {
Path base = Paths.get("/aaa/bbb");
Path base = Paths.get(fixpath("/aaa/bbb"));

Path path = PathUtil.resolve(base, "ccc");
assertEquals("/aaa/bbb/ccc", path.toString());
assertEquals(fixpath("/aaa/bbb/ccc"), path.toString());

path = PathUtil.resolve(base, "ccc/");
assertEquals("/aaa/bbb/ccc", path.toString());
path = PathUtil.resolve(base, fixpath("ccc/"));
assertEquals(fixpath("/aaa/bbb/ccc"), path.toString());

path = PathUtil.resolve(base, "/ccc");
assertEquals("/aaa/bbb/ccc", path.toString());
path = PathUtil.resolve(base, fixpath("/ccc"));
assertEquals(fixpath("/aaa/bbb/ccc"), path.toString());

path = PathUtil.resolve(base, "ccc", "ddd");
assertEquals("/aaa/bbb/ccc/ddd", path.toString());
assertEquals(fixpath("/aaa/bbb/ccc/ddd"), path.toString());

path = PathUtil.resolve(base, "/ccc", "ddd/");
assertEquals("/aaa/bbb/ccc/ddd", path.toString());
path = PathUtil.resolve(base, fixpath("/ccc"), fixpath("ddd/"));
assertEquals(fixpath("/aaa/bbb/ccc/ddd"), path.toString());

path = PathUtil.resolve(base, "/ccc/", "/ddd/");
assertEquals("/aaa/bbb/ccc/ddd", path.toString());
path = PathUtil.resolve(base, fixpath("/ccc/"), fixpath("/ddd/"));
assertEquals(fixpath("/aaa/bbb/ccc/ddd"), path.toString());
}

private String fixpath(String path) {
return StringUtil.replace(path, "/", File.separator);
}
}

0 comments on commit 50451f5

Please sign in to comment.