about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorKevin Ballard <kevin@sb.org>2013-09-01 23:35:32 -0700
committerKevin Ballard <kevin@sb.org>2013-10-15 20:10:11 -0700
commit6f5b809775fb1f8dbf27edded8e955d64377749c (patch)
treed210f7da10e8acf6605580f95a675f82d63df593 /src/libstd
parent6d29142219d92f886124057e9ecfdb51ffca19f2 (diff)
downloadrust-6f5b809775fb1f8dbf27edded8e955d64377749c.tar.gz
rust-6f5b809775fb1f8dbf27edded8e955d64377749c.zip
path2: Add more tests to posix impl
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/path2/posix.rs14
1 files changed, 11 insertions, 3 deletions
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"));