From 6f5b809775fb1f8dbf27edded8e955d64377749c Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Sun, 1 Sep 2013 23:35:32 -0700 Subject: path2: Add more tests to posix impl --- src/libstd/path2/posix.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/path2/posix.rs b/src/libstd/path2/posix.rs index fa6d1e32ebd..d66f51894b5 100644 --- a/src/libstd/path2/posix.rs +++ b/src/libstd/path2/posix.rs @@ -97,13 +97,13 @@ impl GenericPathUnsafe for Path { Some(0) if self.repr.len() == 1 && self.repr[0] == sep => { self.repr = Path::normalize(dirname); } + Some(idx) if self.repr.slice_from(idx+1) == bytes!("..") => { + self.repr = Path::normalize(dirname); + } Some(idx) if dirname.is_empty() => { let v = Path::normalize(self.repr.slice_from(idx+1)); self.repr = v; } - Some(idx) if self.repr.slice_from(idx+1) == bytes!("..") => { - self.repr = Path::normalize(dirname); - } Some(idx) => { let mut v = vec::with_capacity(dirname.len() + self.repr.len() - idx); v.push_all(dirname); @@ -444,7 +444,9 @@ mod tests { t!(s: Path::from_str(""), "."); t!(s: Path::from_str("/"), "/"); t!(s: Path::from_str("hi"), "hi"); + t!(s: Path::from_str("hi/"), "hi"); t!(s: Path::from_str("/lib"), "/lib"); + t!(s: Path::from_str("/lib/"), "/lib"); t!(s: Path::from_str("hi/there"), "hi/there"); t!(s: Path::from_str("hi/there.txt"), "hi/there.txt"); @@ -800,6 +802,8 @@ mod tests { t!(s: Path::from_str("/foo").with_dirname_str("bar"), "bar/foo"); t!(s: Path::from_str("..").with_dirname_str("foo"), "foo"); t!(s: Path::from_str("../..").with_dirname_str("foo"), "foo"); + t!(s: Path::from_str("..").with_dirname_str(""), "."); + t!(s: Path::from_str("../..").with_dirname_str(""), "."); t!(s: Path::from_str("foo").with_dirname_str(".."), "../foo"); t!(s: Path::from_str("foo").with_dirname_str("../.."), "../../foo"); @@ -813,6 +817,8 @@ mod tests { t!(s: Path::from_str("/").with_filename_str("foo"), "/foo"); t!(s: Path::from_str("/a").with_filename_str("foo"), "/foo"); t!(s: Path::from_str("foo").with_filename_str("bar"), "bar"); + t!(s: Path::from_str("/").with_filename_str("foo/"), "/foo"); + t!(s: Path::from_str("/a").with_filename_str("foo/"), "/foo"); t!(s: Path::from_str("a/b/c").with_filename_str(""), "a/b"); t!(s: Path::from_str("a/b/c").with_filename_str("."), "a/b"); t!(s: Path::from_str("a/b/c").with_filename_str(".."), "a"); @@ -822,6 +828,8 @@ mod tests { t!(s: Path::from_str("a/b/c").with_filename_str("/d"), "a/b/d"); t!(s: Path::from_str("..").with_filename_str("foo"), "../foo"); t!(s: Path::from_str("../..").with_filename_str("foo"), "../../foo"); + t!(s: Path::from_str("..").with_filename_str(""), ".."); + t!(s: Path::from_str("../..").with_filename_str(""), "../.."); t!(v: Path::new(b!("hi/there", 0x80, ".txt")).with_filestem(b!(0xff)), b!("hi/", 0xff, ".txt")); -- cgit 1.4.1-3-g733a5