Skip to content

Commit 6f5b809

Browse files
committed
path2: Add more tests to posix impl
1 parent 6d29142 commit 6f5b809

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/libstd/path2/posix.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,13 @@ impl GenericPathUnsafe for Path {
9797
Some(0) if self.repr.len() == 1 && self.repr[0] == sep => {
9898
self.repr = Path::normalize(dirname);
9999
}
100+
Some(idx) if self.repr.slice_from(idx+1) == bytes!("..") => {
101+
self.repr = Path::normalize(dirname);
102+
}
100103
Some(idx) if dirname.is_empty() => {
101104
let v = Path::normalize(self.repr.slice_from(idx+1));
102105
self.repr = v;
103106
}
104-
Some(idx) if self.repr.slice_from(idx+1) == bytes!("..") => {
105-
self.repr = Path::normalize(dirname);
106-
}
107107
Some(idx) => {
108108
let mut v = vec::with_capacity(dirname.len() + self.repr.len() - idx);
109109
v.push_all(dirname);
@@ -444,7 +444,9 @@ mod tests {
444444
t!(s: Path::from_str(""), ".");
445445
t!(s: Path::from_str("/"), "/");
446446
t!(s: Path::from_str("hi"), "hi");
447+
t!(s: Path::from_str("hi/"), "hi");
447448
t!(s: Path::from_str("/lib"), "/lib");
449+
t!(s: Path::from_str("/lib/"), "/lib");
448450
t!(s: Path::from_str("hi/there"), "hi/there");
449451
t!(s: Path::from_str("hi/there.txt"), "hi/there.txt");
450452

@@ -800,6 +802,8 @@ mod tests {
800802
t!(s: Path::from_str("/foo").with_dirname_str("bar"), "bar/foo");
801803
t!(s: Path::from_str("..").with_dirname_str("foo"), "foo");
802804
t!(s: Path::from_str("../..").with_dirname_str("foo"), "foo");
805+
t!(s: Path::from_str("..").with_dirname_str(""), ".");
806+
t!(s: Path::from_str("../..").with_dirname_str(""), ".");
803807
t!(s: Path::from_str("foo").with_dirname_str(".."), "../foo");
804808
t!(s: Path::from_str("foo").with_dirname_str("../.."), "../../foo");
805809
@@ -813,6 +817,8 @@ mod tests {
813817
t!(s: Path::from_str("/").with_filename_str("foo"), "/foo");
814818
t!(s: Path::from_str("/a").with_filename_str("foo"), "/foo");
815819
t!(s: Path::from_str("foo").with_filename_str("bar"), "bar");
820+
t!(s: Path::from_str("/").with_filename_str("foo/"), "/foo");
821+
t!(s: Path::from_str("/a").with_filename_str("foo/"), "/foo");
816822
t!(s: Path::from_str("a/b/c").with_filename_str(""), "a/b");
817823
t!(s: Path::from_str("a/b/c").with_filename_str("."), "a/b");
818824
t!(s: Path::from_str("a/b/c").with_filename_str(".."), "a");
@@ -822,6 +828,8 @@ mod tests {
822828
t!(s: Path::from_str("a/b/c").with_filename_str("/d"), "a/b/d");
823829
t!(s: Path::from_str("..").with_filename_str("foo"), "../foo");
824830
t!(s: Path::from_str("../..").with_filename_str("foo"), "../../foo");
831+
t!(s: Path::from_str("..").with_filename_str(""), "..");
832+
t!(s: Path::from_str("../..").with_filename_str(""), "../..");
825833
826834
t!(v: Path::new(b!("hi/there", 0x80, ".txt")).with_filestem(b!(0xff)),
827835
b!("hi/", 0xff, ".txt"));

0 commit comments

Comments
 (0)