diff options
| author | Kevin Ballard <kevin@sb.org> | 2013-12-03 19:15:12 -0800 |
|---|---|---|
| committer | Kevin Ballard <kevin@sb.org> | 2013-12-04 22:33:53 -0800 |
| commit | 408dc5ad1b657eb2261e7ac680b8d100469e5477 (patch) | |
| tree | bf2b7e8a7c1a5161b5fe531925fa2e0d9e5f34f5 /src/libstd | |
| parent | bd5305fbc818d0f59eaabcfd08f19e8c23ea931f (diff) | |
| download | rust-408dc5ad1b657eb2261e7ac680b8d100469e5477.tar.gz rust-408dc5ad1b657eb2261e7ac680b8d100469e5477.zip | |
Revert "libstd: Change `Path::new` to `Path::init`."
This reverts commit c54427ddfbbab41a39d14f2b1dc4f080cbc2d41b. Leave the #[ignores] in that were added to rustpkg tests. Conflicts: src/librustc/driver/driver.rs src/librustc/metadata/creader.rs
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/io/fs.rs | 48 | ||||
| -rw-r--r-- | src/libstd/io/mod.rs | 2 | ||||
| -rw-r--r-- | src/libstd/io/native/file.rs | 17 | ||||
| -rw-r--r-- | src/libstd/io/native/process.rs | 2 | ||||
| -rw-r--r-- | src/libstd/os.rs | 34 | ||||
| -rw-r--r-- | src/libstd/path/mod.rs | 26 | ||||
| -rw-r--r-- | src/libstd/path/posix.rs | 342 | ||||
| -rw-r--r-- | src/libstd/path/windows.rs | 344 | ||||
| -rw-r--r-- | src/libstd/rand/os.rs | 2 | ||||
| -rw-r--r-- | src/libstd/rt/test.rs | 2 | ||||
| -rw-r--r-- | src/libstd/run.rs | 4 | ||||
| -rw-r--r-- | src/libstd/unstable/dynamic_lib.rs | 2 |
12 files changed, 412 insertions, 413 deletions
diff --git a/src/libstd/io/fs.rs b/src/libstd/io/fs.rs index f0b51a2c3e0..23bf5cdc564 100644 --- a/src/libstd/io/fs.rs +++ b/src/libstd/io/fs.rs @@ -29,7 +29,7 @@ particular bits of it, etc. use std::io::{File, fs}; - let path = Path::init("foo.txt"); + let path = Path::new("foo.txt"); // create the file, whether it exists or not let mut file = File::create(&path); @@ -40,7 +40,7 @@ particular bits of it, etc. file.read_to_end(); println!("{}", path.stat().size); - fs::symlink(&path, &Path::init("bar.txt")); + fs::symlink(&path, &Path::new("bar.txt")); fs::unlink(&path); */ @@ -95,7 +95,7 @@ impl File { /// /// use std::io::{File, io_error, Open, ReadWrite}; /// - /// let p = Path::init("/some/file/path.txt"); + /// let p = Path::new("/some/file/path.txt"); /// /// io_error::cond.trap(|_| { /// // hoo-boy... @@ -157,7 +157,7 @@ impl File { /// /// use std::io::File; /// - /// let contents = File::open(&Path::init("foo.txt")).read_to_end(); + /// let contents = File::open(&Path::new("foo.txt")).read_to_end(); pub fn open(path: &Path) -> Option<File> { File::open_mode(path, Open, Read) } @@ -172,7 +172,7 @@ impl File { /// /// use std::io::File; /// - /// let mut f = File::create(&Path::init("foo.txt")); + /// let mut f = File::create(&Path::new("foo.txt")); /// f.write(bytes!("This is a sample file")); pub fn create(path: &Path) -> Option<File> { File::open_mode(path, Truncate, Write) @@ -229,7 +229,7 @@ impl File { /// /// use std::io::fs; /// -/// let p = Path::init("/some/file/path.txt"); +/// let p = Path::new("/some/file/path.txt"); /// fs::unlink(&p); /// // if we made it here without failing, then the /// // unlink operation was successful @@ -260,7 +260,7 @@ pub fn unlink(path: &Path) { /// use std::io; /// use std::io::fs; /// -/// let p = Path::init("/some/file/path.txt"); +/// let p = Path::new("/some/file/path.txt"); /// match io::result(|| fs::stat(&p)) { /// Ok(stat) => { /* ... */ } /// Err(e) => { /* handle error */ } @@ -277,7 +277,7 @@ pub fn stat(path: &Path) -> FileStat { fn dummystat() -> FileStat { FileStat { - path: Path::init(""), + path: Path::new(""), size: 0, kind: io::TypeFile, perm: 0, @@ -317,7 +317,7 @@ pub fn lstat(path: &Path) -> FileStat { /// /// use std::io::fs; /// -/// fs::rename(&Path::init("foo"), &Path::init("bar")); +/// fs::rename(&Path::new("foo"), &Path::new("bar")); /// // Oh boy, nothing was raised! /// /// # Errors @@ -339,7 +339,7 @@ pub fn rename(from: &Path, to: &Path) { /// /// use std::io::fs; /// -/// fs::copy(&Path::init("foo.txt"), &Path::init("bar.txt")); +/// fs::copy(&Path::new("foo.txt"), &Path::new("bar.txt")); /// // Oh boy, nothing was raised! /// /// # Errors @@ -386,10 +386,10 @@ pub fn copy(from: &Path, to: &Path) { /// use std::io; /// use std::io::fs; /// -/// fs::chmod(&Path::init("file.txt"), io::UserFile); -/// fs::chmod(&Path::init("file.txt"), io::UserRead | io::UserWrite); -/// fs::chmod(&Path::init("dir"), io::UserDir); -/// fs::chmod(&Path::init("file.exe"), io::UserExec); +/// fs::chmod(&Path::new("file.txt"), io::UserFile); +/// fs::chmod(&Path::new("file.txt"), io::UserRead | io::UserWrite); +/// fs::chmod(&Path::new("dir"), io::UserDir); +/// fs::chmod(&Path::new("file.exe"), io::UserExec); /// /// # Errors /// @@ -448,7 +448,7 @@ pub fn readlink(path: &Path) -> Option<Path> { /// use std::libc::S_IRWXU; /// use std::io::fs; /// -/// let p = Path::init("/some/dir"); +/// let p = Path::new("/some/dir"); /// fs::mkdir(&p, S_IRWXU as int); /// // If we got here, our directory exists! Horray! /// @@ -467,7 +467,7 @@ pub fn mkdir(path: &Path, mode: FilePermission) { /// /// use std::io::fs; /// -/// let p = Path::init("/some/dir"); +/// let p = Path::new("/some/dir"); /// fs::rmdir(&p); /// // good riddance, you mean ol' directory /// @@ -987,12 +987,12 @@ mod test { }) test!(fn recursive_mkdir_slash() { - mkdir_recursive(&Path::init("/"), io::UserRWX); + mkdir_recursive(&Path::new("/"), io::UserRWX); }) test!(fn unicode_path_is_dir() { - assert!(Path::init(".").is_dir()); - assert!(!Path::init("test/stdtest/fs.rs").is_dir()); + assert!(Path::new(".").is_dir()); + assert!(!Path::new("test/stdtest/fs.rs").is_dir()); let tmpdir = tmpdir(); @@ -1009,20 +1009,20 @@ mod test { }) test!(fn unicode_path_exists() { - assert!(Path::init(".").exists()); - assert!(!Path::init("test/nonexistent-bogus-path").exists()); + assert!(Path::new(".").exists()); + assert!(!Path::new("test/nonexistent-bogus-path").exists()); let tmpdir = tmpdir(); let unicode = tmpdir.clone(); let unicode = unicode.join(format!("test-각丁ー再见")); mkdir(&unicode, io::UserRWX); assert!(unicode.exists()); - assert!(!Path::init("test/unicode-bogus-path-각丁ー再见").exists()); + assert!(!Path::new("test/unicode-bogus-path-각丁ー再见").exists()); }) test!(fn copy_file_does_not_exist() { - let from = Path::init("test/nonexistent-bogus-path"); - let to = Path::init("test/other-bogus-path"); + let from = Path::new("test/nonexistent-bogus-path"); + let to = Path::new("test/other-bogus-path"); match io::result(|| copy(&from, &to)) { Ok(..) => fail!(), Err(..) => { diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 208c64f5ef4..edc6728a0c1 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -450,7 +450,7 @@ pub trait Reader { /// /// # Example /// - /// let reader = File::open(&Path::init("foo.txt")) + /// let reader = File::open(&Path::new("foo.txt")) /// while !reader.eof() { /// println(reader.read_line()); /// } diff --git a/src/libstd/io/native/file.rs b/src/libstd/io/native/file.rs index c3c7540df86..218040b72d6 100644 --- a/src/libstd/io/native/file.rs +++ b/src/libstd/io/native/file.rs @@ -278,7 +278,6 @@ impl rtio::RtioFileStream for FileDesc { self.seek(orig_pos as i64, io::SeekSet); return ret; } - #[cfg(unix)] fn truncate(&mut self, offset: i64) -> Result<(), IoError> { super::mkerr_libc(unsafe { @@ -481,7 +480,7 @@ pub fn mkdir(p: &CString, mode: io::FilePermission) -> IoResult<()> { pub fn readdir(p: &CString) -> IoResult<~[Path]> { fn prune(root: &CString, dirs: ~[Path]) -> ~[Path] { let root = unsafe { CString::new(root.with_ref(|p| p), false) }; - let root = Path::init(root); + let root = Path::new(root); dirs.move_iter().filter(|path| { path.as_vec() != bytes!(".") && path.as_vec() != bytes!("..") @@ -506,7 +505,7 @@ pub fn readdir(p: &CString) -> IoResult<~[Path]> { let mut entry_ptr = readdir(dir_ptr); while (entry_ptr as uint != 0) { let cstr = CString::new(rust_list_dir_val(entry_ptr), false); - paths.push(Path::init(cstr)); + paths.push(Path::new(cstr)); entry_ptr = readdir(dir_ptr); } closedir(dir_ptr); @@ -537,7 +536,7 @@ pub fn readdir(p: &CString) -> IoResult<~[Path]> { fn rust_list_dir_wfd_fp_buf(wfd: *libc::c_void) -> *u16; } let p = CString::new(p.with_ref(|p| p), false); - let p = Path::init(p); + let p = Path::new(p); let star = p.join("*"); as_utf16_p(star.as_str().unwrap(), |path_ptr| { let wfd_ptr = malloc_raw(rust_list_dir_wfd_size() as uint); @@ -554,7 +553,7 @@ pub fn readdir(p: &CString) -> IoResult<~[Path]> { let fp_vec = vec::from_buf( fp_buf, wcslen(fp_buf) as uint); let fp_str = str::from_utf16(fp_vec); - paths.push(Path::init(fp_str)); + paths.push(Path::new(fp_str)); } more_files = FindNextFileW(find_handle, wfd_ptr as HANDLE); } @@ -684,7 +683,7 @@ pub fn readlink(p: &CString) -> IoResult<Path> { } }); let ret = match ret { - Some(s) => Ok(Path::init(s)), + Some(s) => Ok(Path::new(s)), None => Err(super::last_error()), }; unsafe { libc::CloseHandle(handle) }; @@ -708,7 +707,7 @@ pub fn readlink(p: &CString) -> IoResult<Path> { n => { assert!(n > 0); unsafe { vec::raw::set_len(&mut buf, n as uint); } - Ok(Path::init(buf)) + Ok(Path::new(buf)) } } } @@ -771,7 +770,7 @@ fn mkstat(stat: &libc::stat, path: &CString) -> io::FileStat { }; io::FileStat { - path: Path::init(path), + path: Path::new(path), size: stat.st_size as u64, kind: kind, perm: (stat.st_mode) as io::FilePermission & io::AllPermissions, @@ -820,7 +819,7 @@ fn mkstat(stat: &libc::stat, path: &CString) -> io::FileStat { fn gen(_stat: &libc::stat) -> u64 { 0 } io::FileStat { - path: Path::init(path), + path: Path::new(path), size: stat.st_size as u64, kind: kind, perm: (stat.st_mode) as io::FilePermission & io::AllPermissions, diff --git a/src/libstd/io/native/process.rs b/src/libstd/io/native/process.rs index 3113fbeb095..1b614852737 100644 --- a/src/libstd/io/native/process.rs +++ b/src/libstd/io/native/process.rs @@ -95,7 +95,7 @@ impl Process { let (err_pipe, err_fd) = get_io(config.io, &mut ret_io, 2); let env = config.env.map(|a| a.to_owned()); - let cwd = config.cwd.map(|a| Path::init(a)); + let cwd = config.cwd.map(|a| Path::new(a)); let res = spawn_process_os(config.program, config.args, env, cwd.as_ref(), in_fd, out_fd, err_fd); diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 265a2453ca6..34331769614 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -64,7 +64,7 @@ pub fn getcwd() -> Path { fail!() } - Path::init(CString::new(buf as *c_char, false)) + Path::new(CString::new(buf as *c_char, false)) } }) } @@ -81,7 +81,7 @@ pub fn getcwd() -> Path { } } }); - Path::init(str::from_utf16(buf)) + Path::new(str::from_utf16(buf)) } #[cfg(windows)] @@ -384,7 +384,7 @@ pub fn self_exe_path() -> Option<Path> { fn load_self() -> Option<~[u8]> { use std::io; - match io::result(|| io::fs::readlink(&Path::init("/proc/self/exe"))) { + match io::result(|| io::fs::readlink(&Path::new("/proc/self/exe"))) { Ok(Some(path)) => Some(path.as_vec().to_owned()), Ok(None) | Err(..) => None } @@ -418,7 +418,7 @@ pub fn self_exe_path() -> Option<Path> { } } - load_self().and_then(|path| Path::init_opt(path).map(|mut p| { p.pop(); p })) + load_self().and_then(|path| Path::new_opt(path).map(|mut p| { p.pop(); p })) } /** @@ -437,7 +437,7 @@ pub fn self_exe_path() -> Option<Path> { pub fn homedir() -> Option<Path> { // FIXME (#7188): getenv needs a ~[u8] variant return match getenv("HOME") { - Some(ref p) if !p.is_empty() => Path::init_opt(p.as_slice()), + Some(ref p) if !p.is_empty() => Path::new_opt(p.as_slice()), _ => secondary() }; @@ -450,7 +450,7 @@ pub fn homedir() -> Option<Path> { fn secondary() -> Option<Path> { getenv("USERPROFILE").and_then(|p| { if !p.is_empty() { - Path::init_opt(p) + Path::new_opt(p) } else { None } @@ -479,7 +479,7 @@ pub fn tmpdir() -> Path { if x.is_empty() { None } else { - Path::init_opt(x) + Path::new_opt(x) }, _ => None } @@ -488,9 +488,9 @@ pub fn tmpdir() -> Path { #[cfg(unix)] fn lookup() -> Path { if cfg!(target_os = "android") { - Path::init("/data/tmp") + Path::new("/data/tmp") } else { - getenv_nonempty("TMPDIR").unwrap_or(Path::init("/tmp")) + getenv_nonempty("TMPDIR").unwrap_or(Path::new("/tmp")) } } @@ -499,7 +499,7 @@ pub fn tmpdir() -> Path { getenv_nonempty("TMP").or( getenv_nonempty("TEMP").or( getenv_nonempty("USERPROFILE").or( - getenv_nonempty("WINDIR")))).unwrap_or(Path::init("C:\\Windows")) + getenv_nonempty("WINDIR")))).unwrap_or(Path::new("C:\\Windows")) } } @@ -1366,13 +1366,13 @@ mod tests { #[test] fn test() { - assert!((!Path::init("test-path").is_absolute())); + assert!((!Path::new("test-path").is_absolute())); let cwd = getcwd(); debug!("Current working directory: {}", cwd.display()); - debug!("{:?}", make_absolute(&Path::init("test-path"))); - debug!("{:?}", make_absolute(&Path::init("/usr/bin"))); + debug!("{:?}", make_absolute(&Path::new("test-path"))); + debug!("{:?}", make_absolute(&Path::new("/usr/bin"))); } #[test] @@ -1381,7 +1381,7 @@ mod tests { let oldhome = getenv("HOME"); setenv("HOME", "/home/MountainView"); - assert_eq!(os::homedir(), Some(Path::init("/home/MountainView"))); + assert_eq!(os::homedir(), Some(Path::new("/home/MountainView"))); setenv("HOME", ""); assert!(os::homedir().is_none()); @@ -1402,16 +1402,16 @@ mod tests { assert!(os::homedir().is_none()); setenv("HOME", "/home/MountainView"); - assert_eq!(os::homedir(), Some(Path::init("/home/MountainView"))); + assert_eq!(os::homedir(), Some(Path::new("/home/MountainView"))); setenv("HOME", ""); setenv("USERPROFILE", "/home/MountainView"); - assert_eq!(os::homedir(), Some(Path::init("/home/MountainView"))); + assert_eq!(os::homedir(), Some(Path::new("/home/MountainView"))); setenv("HOME", "/home/MountainView"); setenv("USERPROFILE", "/home/PaloAlto"); - assert_eq!(os::homedir(), Some(Path::init("/home/MountainView"))); + assert_eq!(os::homedir(), Some(Path::new("/home/MountainView"))); for s in oldhome.iter() { setenv("HOME", *s) } for s in olduserprofile.iter() { setenv("USERPROFILE", *s) } diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs index 79989b838f6..303bb470991 100644 --- a/src/libstd/path/mod.rs +++ b/src/libstd/path/mod.rs @@ -32,8 +32,8 @@ no restriction on paths beyond disallowing NUL). Usage of this module is fairly straightforward. Unless writing platform-specific code, `Path` should be used to refer to the platform-native path. -Creation of a path is typically done with either `Path::init(some_str)` or -`Path::init(some_vec)`. This path can be modified with `.push()` and +Creation of a path is typically done with either `Path::new(some_str)` or +`Path::new(some_vec)`. This path can be modified with `.push()` and `.pop()` (and other setters). The resulting Path can either be passed to another API that expects a path, or can be turned into a &[u8] with `.as_vec()` or a Option<&str> with `.as_str()`. Similarly, attributes of the path can be queried @@ -41,7 +41,7 @@ with methods such as `.filename()`. There are also methods that return a new path instead of modifying the receiver, such as `.join()` or `.dir_path()`. Paths are always kept in normalized form. This means that creating the path -`Path::init("a/b/../c")` will return the path `a/c`. Similarly any attempt +`Path::new("a/b/../c")` will return the path `a/c`. Similarly any attempt to mutate the path will always leave it in normalized form. When rendering a path to some form of output, there is a method `.display()` @@ -53,7 +53,7 @@ actually operates on the path; it is only intended for display. ## Example ```rust -let mut path = Path::from_str("/tmp/path"); +let mut path = Path::new("/tmp/path"); debug!("path: {}", path.display()); path.set_filename("foo"); path.push("bar"); @@ -151,24 +151,24 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// /// See individual Path impls for additional restrictions. #[inline] - fn init<T: BytesContainer>(path: T) -> Self { + fn new<T: BytesContainer>(path: T) -> Self { if contains_nul(path.container_as_bytes()) { let path = self::null_byte::cond.raise(path.container_into_owned_bytes()); assert!(!contains_nul(path)); - unsafe { GenericPathUnsafe::init_unchecked(path) } + unsafe { GenericPathUnsafe::new_unchecked(path) } } else { - unsafe { GenericPathUnsafe::init_unchecked(path) } + unsafe { GenericPathUnsafe::new_unchecked(path) } } } /// Creates a new Path from a byte vector or string, if possible. /// The resulting Path will always be normalized. #[inline] - fn init_opt<T: BytesContainer>(path: T) -> Option<Self> { + fn new_opt<T: BytesContainer>(path: T) -> Option<Self> { if contains_nul(path.container_as_bytes()) { None } else { - Some(unsafe { GenericPathUnsafe::init_unchecked(path) }) + Some(unsafe { GenericPathUnsafe::new_unchecked(path) }) } } @@ -382,7 +382,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// If `self` represents the root of the filesystem hierarchy, returns `self`. fn dir_path(&self) -> Self { // self.dirname() returns a NUL-free vector - unsafe { GenericPathUnsafe::init_unchecked(self.dirname()) } + unsafe { GenericPathUnsafe::new_unchecked(self.dirname()) } } /// Returns a Path that represents the filesystem root that `self` is rooted in. @@ -510,7 +510,7 @@ pub trait BytesContainer { pub trait GenericPathUnsafe { /// Creates a new Path without checking for null bytes. /// The resulting Path will always be normalized. - unsafe fn init_unchecked<T: BytesContainer>(path: T) -> Self; + unsafe fn new_unchecked<T: BytesContainer>(path: T) -> Self; /// Replaces the filename portion of the path without checking for null /// bytes. @@ -694,11 +694,11 @@ mod tests { #[test] fn test_cstring() { let input = "/foo/bar/baz"; - let path: PosixPath = PosixPath::init(input.to_c_str()); + let path: PosixPath = PosixPath::new(input.to_c_str()); assert_eq!(path.as_vec(), input.as_bytes()); let input = r"\foo\bar\baz"; - let path: WindowsPath = WindowsPath::init(input.to_c_str()); + let path: WindowsPath = WindowsPath::new(input.to_c_str()); assert_eq!(path.as_str().unwrap(), input.as_slice()); } } diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index ddf2cce21b0..10ce06f7e03 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -68,7 +68,7 @@ impl Eq for Path { impl FromStr for Path { fn from_str(s: &str) -> Option<Path> { - Path::init_opt(s) + Path::new_opt(s) } } @@ -111,7 +111,7 @@ impl<'self> BytesContainer for &'self Path { } impl GenericPathUnsafe for Path { - unsafe fn init_unchecked<T: BytesContainer>(path: T) -> Path { + unsafe fn new_unchecked<T: BytesContainer>(path: T) -> Path { let path = Path::normalize(path.container_as_bytes()); assert!(!path.is_empty()); let idx = path.rposition_elem(&sep_byte); @@ -218,7 +218,7 @@ impl GenericPath for Path { fn root_path(&self) -> Option<Path> { if self.is_absolute() { - Some(Path::init("/")) + Some(Path::new("/")) } else { None } @@ -287,7 +287,7 @@ impl GenericPath for Path { } } } - Some(Path::init(comps.connect_vec(&sep_byte))) + Some(Path::new(comps.connect_vec(&sep_byte))) } } @@ -314,14 +314,14 @@ impl Path { /// /// Raises the `null_byte` condition if the vector contains a NUL. #[inline] - pub fn init<T: BytesContainer>(path: T) -> Path { - GenericPath::init(path) + pub fn new<T: BytesContainer>(path: T) -> Path { + GenericPath::new(path) } /// Returns a new Path from a byte vector or string, if possible #[inline] - pub fn init_opt<T: BytesContainer>(path: T) -> Option<Path> { - GenericPath::init_opt(path) + pub fn new_opt<T: BytesContainer>(path: T) -> Option<Path> { + GenericPath::new_opt(path) } /// Returns a normalized byte vector representation of a path, by removing all empty @@ -471,51 +471,51 @@ mod tests { #[test] fn test_paths() { let empty: &[u8] = []; - t!(v: Path::init(empty), b!(".")); - t!(v: Path::init(b!("/")), b!("/")); - t!(v: Path::init(b!("a/b/c")), b!("a/b/c")); - t!(v: Path::init(b!("a/b/c", 0xff)), b!("a/b/c", 0xff)); - t!(v: Path::init(b!(0xff, "/../foo", 0x80)), b!("foo", 0x80)); - let p = Path::init(b!("a/b/c", 0xff)); + t!(v: Path::new(empty), b!(".")); + t!(v: Path::new(b!("/")), b!("/")); + t!(v: Path::new(b!("a/b/c")), b!("a/b/c")); + t!(v: Path::new(b!("a/b/c", 0xff)), b!("a/b/c", 0xff)); + t!(v: Path::new(b!(0xff, "/../foo", 0x80)), b!("foo", 0x80)); + let p = Path::new(b!("a/b/c", 0xff)); assert_eq!(p.as_str(), None); - t!(s: Path::init(""), "."); - t!(s: Path::init("/"), "/"); - t!(s: Path::init("hi"), "hi"); - t!(s: Path::init("hi/"), "hi"); - t!(s: Path::init("/lib"), "/lib"); - t!(s: Path::init("/lib/"), "/lib"); - t!(s: Path::init("hi/there"), "hi/there"); - t!(s: Path::init("hi/there.txt"), "hi/there.txt"); - - t!(s: Path::init("hi/there/"), "hi/there"); - t!(s: Path::init("hi/../there"), "there"); - t!(s: Path::init("../hi/there"), "../hi/there"); - t!(s: Path::init("/../hi/there"), "/hi/there"); - t!(s: Path::init("foo/.."), "."); - t!(s: Path::init("/foo/.."), "/"); - t!(s: Path::init("/foo/../.."), "/"); - t!(s: Path::init("/foo/../../bar"), "/bar"); - t!(s: Path::init("/./hi/./there/."), "/hi/there"); - t!(s: Path::init("/./hi/./there/./.."), "/hi"); - t!(s: Path::init("foo/../.."), ".."); - t!(s: Path::init("foo/../../.."), "../.."); - t!(s: Path::init("foo/../../bar"), "../bar"); - - assert_eq!(Path::init(b!("foo/bar")).into_vec(), b!("foo/bar").to_owned()); - assert_eq!(Path::init(b!("/foo/../../bar")).into_vec(), + t!(s: Path::new(""), "."); + t!(s: Path::new("/"), "/"); + t!(s: Path::new("hi"), "hi"); + t!(s: Path::new("hi/"), "hi"); + t!(s: Path::new("/lib"), "/lib"); + t!(s: Path::new("/lib/"), "/lib"); + t!(s: Path::new("hi/there"), "hi/there"); + t!(s: Path::new("hi/there.txt"), "hi/there.txt"); + + t!(s: Path::new("hi/there/"), "hi/there"); + t!(s: Path::new("hi/../there"), "there"); + t!(s: Path::new("../hi/there"), "../hi/there"); + t!(s: Path::new("/../hi/there"), "/hi/there"); + t!(s: Path::new("foo/.."), "."); + t!(s: Path::new("/foo/.."), "/"); + t!(s: Path::new("/foo/../.."), "/"); + t!(s: Path::new("/foo/../../bar"), "/bar"); + t!(s: Path::new("/./hi/./there/."), "/hi/there"); + t!(s: Path::new("/./hi/./there/./.."), "/hi"); + t!(s: Path::new("foo/../.."), ".."); + t!(s: Path::new("foo/../../.."), "../.."); + t!(s: Path::new("foo/../../bar"), "../bar"); + + assert_eq!(Path::new(b!("foo/bar")).into_vec(), b!("foo/bar").to_owned()); + assert_eq!(Path::new(b!("/foo/../../bar")).into_vec(), b!("/bar").to_owned()); - let p = Path::init(b!("foo/bar", 0x80)); + let p = Path::new(b!("foo/bar", 0x80)); assert_eq!(p.as_str(), None); } #[test] fn test_opt_paths() { - assert_eq!(Path::init_opt(b!("foo/bar", 0)), None); - t!(v: Path::init_opt(b!("foo/bar")).unwrap(), b!("foo/bar")); - assert_eq!(Path::init_opt("foo/bar\0"), None); - t!(s: Path::init_opt("foo/bar").unwrap(), "foo/bar"); + assert_eq!(Path::new_opt(b!("foo/bar", 0)), None); + t!(v: Path::new_opt(b!("foo/bar")).unwrap(), b!("foo/bar")); + assert_eq!(Path::new_opt("foo/bar\0"), None); + t!(s: Path::new_opt("foo/bar").unwrap(), "foo/bar"); } #[test] @@ -528,7 +528,7 @@ mod tests { assert_eq!(v.as_slice(), b!("foo/bar", 0)); (b!("/bar").to_owned()) }).inside(|| { - Path::init(b!("foo/bar", 0)) + Path::new(b!("foo/bar", 0)) }); assert!(handled); assert_eq!(p.as_vec(), b!("/bar")); @@ -576,12 +576,12 @@ mod tests { cond.trap(|_| { (b!("null", 0).to_owned()) }).inside(|| { - Path::init(b!("foo/bar", 0)) + Path::new(b!("foo/bar", 0)) }); }) t!(~"set_filename w/nul" => { - let mut p = Path::init(b!("foo/bar")); + let mut p = Path::new(b!("foo/bar")); cond.trap(|_| { (b!("null", 0).to_owned()) }).inside(|| { @@ -590,7 +590,7 @@ mod tests { }) t!(~"push w/nul" => { - let mut p = Path::init(b!("foo/bar")); + let mut p = Path::new(b!("foo/bar")); cond.trap(|_| { (b!("null", 0).to_owned()) }).inside(|| { @@ -604,7 +604,7 @@ mod tests { macro_rules! t( ($path:expr, $disp:ident, $exp:expr) => ( { - let path = Path::init($path); + let path = Path::new($path); assert_eq!(path.$disp().to_str(), ~$exp); } ) @@ -620,7 +620,7 @@ mod tests { ($path:expr, $exp:expr) => ( { let mut called = false; - let path = Path::init($path); + let path = Path::new($path); path.display().with_str(|s| { assert_eq!(s, $exp); called = true; @@ -631,7 +631,7 @@ mod tests { ($path:expr, $exp:expr, filename) => ( { let mut called = false; - let path = Path::init($path); + let path = Path::new($path); path.filename_display().with_str(|s| { assert_eq!(s, $exp); called = true; @@ -654,7 +654,7 @@ mod tests { macro_rules! t( ($path:expr, $exp:expr, $expf:expr) => ( { - let path = Path::init($path); + let path = Path::new($path); let f = format!("{}", path.display()); assert_eq!(f.as_slice(), $exp); let f = format!("{}", path.filename_display()); @@ -677,20 +677,20 @@ mod tests { macro_rules! t( (s: $path:expr, $op:ident, $exp:expr) => ( { - let path = Path::init($path); + let path = Path::new($path); assert_eq!(path.$op(), ($exp).as_bytes()); } ); (s: $path:expr, $op:ident, $exp:expr, opt) => ( { - let path = Path::init($path); + let path = Path::new($path); let left = path.$op().map(|x| str::from_utf8(x)); assert_eq!(left, $exp); } ); (v: $path:expr, $op:ident, $exp:expr) => ( { - let path = Path::init($path); + let path = Path::new($path); assert_eq!(path.$op(), $exp); } ); @@ -762,7 +762,7 @@ mod tests { { let path = ($path); let join = ($join); - let mut p1 = Path::init(path); + let mut p1 = Path::new(path); let p2 = p1.clone(); p1.push(join); assert_eq!(p1, p2.join(join)); @@ -781,8 +781,8 @@ mod tests { macro_rules! t( (s: $path:expr, $push:expr, $exp:expr) => ( { - let mut p = Path::init($path); - let push = Path::init($push); + let mut p = Path::new($path); + let push = Path::new($push); p.push(&push); assert_eq!(p.as_str(), Some($exp)); } @@ -804,14 +804,14 @@ mod tests { macro_rules! t( (s: $path:expr, $push:expr, $exp:expr) => ( { - let mut p = Path::init($path); + let mut p = Path::new($path); p.push_many($push); assert_eq!(p.as_str(), Some($exp)); } ); (v: $path:expr, $push:expr, $exp:expr) => ( { - let mut p = Path::init($path); + let mut p = Path::new($path); p.push_many($push); assert_eq!(p.as_vec(), $exp); } @@ -835,7 +835,7 @@ mod tests { macro_rules! t( (s: $path:expr, $left:expr, $right:expr) => ( { - let mut p = Path::init($path); + let mut p = Path::new($path); let result = p.pop(); assert_eq!(p.as_str(), Some($left)); assert_eq!(result, $right); @@ -843,7 +843,7 @@ mod tests { ); (v: [$($path:expr),+], [$($left:expr),+], $right:expr) => ( { - let mut p = Path::init(b!($($path),+)); + let mut p = Path::new(b!($($path),+)); let result = p.pop(); assert_eq!(p.as_vec(), b!($($left),+)); assert_eq!(result, $right); @@ -869,21 +869,21 @@ mod tests { #[test] fn test_root_path() { - assert_eq!(Path::init(b!("a/b/c")).root_path(), None); - assert_eq!(Path::init(b!("/a/b/c")).root_path(), Some(Path::init("/"))); + assert_eq!(Path::new(b!("a/b/c")).root_path(), None); + assert_eq!(Path::new(b!("/a/b/c")).root_path(), Some(Path::new("/"))); } #[test] fn test_join() { - t!(v: Path::init(b!("a/b/c")).join(b!("..")), b!("a/b")); - t!(v: Path::init(b!("/a/b/c")).join(b!("d")), b!("/a/b/c/d")); - t!(v: Path::init(b!("a/", 0x80, "/c")).join(b!(0xff)), b!("a/", 0x80, "/c/", 0xff)); - t!(s: Path::init("a/b/c").join(".."), "a/b"); - t!(s: Path::init("/a/b/c").join("d"), "/a/b/c/d"); - t!(s: Path::init("a/b").join("c/d"), "a/b/c/d"); - t!(s: Path::init("a/b").join("/c/d"), "/c/d"); - t!(s: Path::init(".").join("a/b"), "a/b"); - t!(s: Path::init("/").join("a/b"), "/a/b"); + t!(v: Path::new(b!("a/b/c")).join(b!("..")), b!("a/b")); + t!(v: Path::new(b!("/a/b/c")).join(b!("d")), b!("/a/b/c/d")); + t!(v: Path::new(b!("a/", 0x80, "/c")).join(b!(0xff)), b!("a/", 0x80, "/c/", 0xff)); + t!(s: Path::new("a/b/c").join(".."), "a/b"); + t!(s: Path::new("/a/b/c").join("d"), "/a/b/c/d"); + t!(s: Path::new("a/b").join("c/d"), "a/b/c/d"); + t!(s: Path::new("a/b").join("/c/d"), "/c/d"); + t!(s: Path::new(".").join("a/b"), "a/b"); + t!(s: Path::new("/").join("a/b"), "/a/b"); } #[test] @@ -891,8 +891,8 @@ mod tests { macro_rules! t( (s: $path:expr, $join:expr, $exp:expr) => ( { - let path = Path::init($path); - let join = Path::init($join); + let path = Path::new($path); + let join = Path::new($join); let res = path.join(&join); assert_eq!(res.as_str(), Some($exp)); } @@ -914,14 +914,14 @@ mod tests { macro_rules! t( (s: $path:expr, $join:expr, $exp:expr) => ( { - let path = Path::init($path); + let path = Path::new($path); let res = path.join_many($join); assert_eq!(res.as_str(), Some($exp)); } ); (v: $path:expr, $join:expr, $exp:expr) => ( { - let path = Path::init($path); + let path = Path::new($path); let res = path.join_many($join); assert_eq!(res.as_vec(), $exp); } @@ -943,51 +943,51 @@ mod tests { fn test_with_helpers() { let empty: &[u8] = []; - t!(v: Path::init(b!("a/b/c")).with_filename(b!("d")), b!("a/b/d")); - t!(v: Path::init(b!("a/b/c", 0xff)).with_filename(b!(0x80)), b!("a/b/", 0x80)); - t!(v: Path::init(b!("/", 0xff, "/foo")).with_filename(b!(0xcd)), + t!(v: Path::new(b!("a/b/c")).with_filename(b!("d")), b!("a/b/d")); + t!(v: Path::new(b!("a/b/c", 0xff)).with_filename(b!(0x80)), b!("a/b/", 0x80)); + t!(v: Path::new(b!("/", 0xff, "/foo")).with_filename(b!(0xcd)), b!("/", 0xff, "/", 0xcd)); - t!(s: Path::init("a/b/c").with_filename("d"), "a/b/d"); - t!(s: Path::init(".").with_filename("foo"), "foo"); - t!(s: Path::init("/a/b/c").with_filename("d"), "/a/b/d"); - t!(s: Path::init("/").with_filename("foo"), "/foo"); - t!(s: Path::init("/a").with_filename("foo"), "/foo"); - t!(s: Path::init("foo").with_filename("bar"), "bar"); - t!(s: Path::init("/").with_filename("foo/"), "/foo"); - t!(s: Path::init("/a").with_filename("foo/"), "/foo"); - t!(s: Path::init("a/b/c").with_filename(""), "a/b"); - t!(s: Path::init("a/b/c").with_filename("."), "a/b"); - t!(s: Path::init("a/b/c").with_filename(".."), "a"); - t!(s: Path::init("/a").with_filename(""), "/"); - t!(s: Path::init("foo").with_filename(""), "."); - t!(s: Path::init("a/b/c").with_filename("d/e"), "a/b/d/e"); - t!(s: Path::init("a/b/c").with_filename("/d"), "a/b/d"); - t!(s: Path::init("..").with_filename("foo"), "../foo"); - t!(s: Path::init("../..").with_filename("foo"), "../../foo"); - t!(s: Path::init("..").with_filename(""), ".."); - t!(s: Path::init("../..").with_filename(""), "../.."); - - t!(v: Path::init(b!("hi/there", 0x80, ".txt")).with_extension(b!("exe")), + t!(s: Path::new("a/b/c").with_filename("d"), "a/b/d"); + t!(s: Path::new(".").with_filename("foo"), "foo"); + t!(s: Path::new("/a/b/c").with_filename("d"), "/a/b/d"); + t!(s: Path::new("/").with_filename("foo"), "/foo"); + t!(s: Path::new("/a").with_filename("foo"), "/foo"); + t!(s: Path::new("foo").with_filename("bar"), "bar"); + t!(s: Path::new("/").with_filename("foo/"), "/foo"); + t!(s: Path::new("/a").with_filename("foo/"), "/foo"); + t!(s: Path::new("a/b/c").with_filename(""), "a/b"); + t!(s: Path::new("a/b/c").with_filename("."), "a/b"); + t!(s: Path::new("a/b/c").with_filename(".."), "a"); + t!(s: Path::new("/a").with_filename(""), "/"); + t!(s: Path::new("foo").with_filename(""), "."); + t!(s: Path::new("a/b/c").with_filename("d/e"), "a/b/d/e"); + t!(s: Path::new("a/b/c").with_filename("/d"), "a/b/d"); + t!(s: Path::new("..").with_filename("foo"), "../foo"); + t!(s: Path::new("../..").with_filename("foo"), "../../foo"); + t!(s: Path::new("..").with_filename(""), ".."); + t!(s: Path::new("../..").with_filename(""), "../.."); + + t!(v: Path::new(b!("hi/there", 0x80, ".txt")).with_extension(b!("exe")), b!("hi/there", 0x80, ".exe")); - t!(v: Path::init(b!("hi/there.txt", 0x80)).with_extension(b!(0xff)), + t!(v: Path::new(b!("hi/there.txt", 0x80)).with_extension(b!(0xff)), b!("hi/there.", 0xff)); - t!(v: Path::init(b!("hi/there", 0x80)).with_extension(b!(0xff)), + t!(v: Path::new(b!("hi/there", 0x80)).with_extension(b!(0xff)), b!("hi/there", 0x80, ".", 0xff)); - t!(v: Path::init(b!("hi/there.", 0xff)).with_extension(empty), b!("hi/there")); - t!(s: Path::init("hi/there.txt").with_extension("exe"), "hi/there.exe"); - t!(s: Path::init("hi/there.txt").with_extension(""), "hi/there"); - t!(s: Path::init("hi/there.txt").with_extension("."), "hi/there.."); - t!(s: Path::init("hi/there.txt").with_extension(".."), "hi/there..."); - t!(s: Path::init("hi/there").with_extension("txt"), "hi/there.txt"); - t!(s: Path::init("hi/there").with_extension("."), "hi/there.."); - t!(s: Path::init("hi/there").with_extension(".."), "hi/there..."); - t!(s: Path::init("hi/there.").with_extension("txt"), "hi/there.txt"); - t!(s: Path::init("hi/.foo").with_extension("txt"), "hi/.foo.txt"); - t!(s: Path::init("hi/there.txt").with_extension(".foo"), "hi/there..foo"); - t!(s: Path::init("/").with_extension("txt"), "/"); - t!(s: Path::init("/").with_extension("."), "/"); - t!(s: Path::init("/").with_extension(".."), "/"); - t!(s: Path::init(".").with_extension("txt"), "."); + t!(v: Path::new(b!("hi/there.", 0xff)).with_extension(empty), b!("hi/there")); + t!(s: Path::new("hi/there.txt").with_extension("exe"), "hi/there.exe"); + t!(s: Path::new("hi/there.txt").with_extension(""), "hi/there"); + t!(s: Path::new("hi/there.txt").with_extension("."), "hi/there.."); + t!(s: Path::new("hi/there.txt").with_extension(".."), "hi/there..."); + t!(s: Path::new("hi/there").with_extension("txt"), "hi/there.txt"); + t!(s: Path::new("hi/there").with_extension("."), "hi/there.."); + t!(s: Path::new("hi/there").with_extension(".."), "hi/there..."); + t!(s: Path::new("hi/there.").with_extension("txt"), "hi/there.txt"); + t!(s: Path::new("hi/.foo").with_extension("txt"), "hi/.foo.txt"); + t!(s: Path::new("hi/there.txt").with_extension(".foo"), "hi/there..foo"); + t!(s: Path::new("/").with_extension("txt"), "/"); + t!(s: Path::new("/").with_extension("."), "/"); + t!(s: Path::new("/").with_extension(".."), "/"); + t!(s: Path::new(".").with_extension("txt"), "."); } #[test] @@ -997,9 +997,9 @@ mod tests { { let path = $path; let arg = $arg; - let mut p1 = Path::init(path); + let mut p1 = Path::new(path); p1.$set(arg); - let p2 = Path::init(path); + let p2 = Path::new(path); assert_eq!(p1, p2.$with(arg)); } ); @@ -1007,9 +1007,9 @@ mod tests { { let path = $path; let arg = $arg; - let mut p1 = Path::init(path); + let mut p1 = Path::new(path); p1.$set(arg); - let p2 = Path::init(path); + let p2 = Path::new(path); assert_eq!(p1, p2.$with(arg)); } ) @@ -1069,39 +1069,39 @@ mod tests { ) ) - t!(v: Path::init(b!("a/b/c")), Some(b!("c")), b!("a/b"), Some(b!("c")), None); - t!(v: Path::init(b!("a/b/", 0xff)), Some(b!(0xff)), b!("a/b"), Some(b!(0xff)), None); - t!(v: Path::init(b!("hi/there.", 0xff)), Some(b!("there.", 0xff)), b!("hi"), + t!(v: Path::new(b!("a/b/c")), Some(b!("c")), b!("a/b"), Some(b!("c")), None); + t!(v: Path::new(b!("a/b/", 0xff)), Some(b!(0xff)), b!("a/b"), Some(b!(0xff)), None); + t!(v: Path::new(b!("hi/there.", 0xff)), Some(b!("there.", 0xff)), b!("hi"), Some(b!("there")), Some(b!(0xff))); - t!(s: Path::init("a/b/c"), Some("c"), Some("a/b"), Some("c"), None); - t!(s: Path::init("."), None, Some("."), None, None); - t!(s: Path::init("/"), None, Some("/"), None, None); - t!(s: Path::init(".."), None, Some(".."), None, None); - t!(s: Path::init("../.."), None, Some("../.."), None, None); - t!(s: Path::init("hi/there.txt"), Some("there.txt"), Some("hi"), + t!(s: Path::new("a/b/c"), Some("c"), Some("a/b"), Some("c"), None); + t!(s: Path::new("."), None, Some("."), None, None); + t!(s: Path::new("/"), None, Some("/"), None, None); + t!(s: Path::new(".."), None, Some(".."), None, None); + t!(s: Path::new("../.."), None, Some("../.."), None, None); + t!(s: Path::new("hi/there.txt"), Some("there.txt"), Some("hi"), Some("there"), Some("txt")); - t!(s: Path::init("hi/there"), Some("there"), Some("hi"), Some("there"), None); - t!(s: Path::init("hi/there."), Some("there."), Some("hi"), + t!(s: Path::new("hi/there"), Some("there"), Some("hi"), Some("there"), None); + t!(s: Path::new("hi/there."), Some("there."), Some("hi"), Some("there"), Some("")); - t!(s: Path::init("hi/.there"), Some(".there"), Some("hi"), Some(".there"), None); - t!(s: Path::init("hi/..there"), Some("..there"), Some("hi"), + t!(s: Path::new("hi/.there"), Some(".there"), Some("hi"), Some(".there"), None); + t!(s: Path::new("hi/..there"), Some("..there"), Some("hi"), Some("."), Some("there")); - t!(s: Path::init(b!("a/b/", 0xff)), None, Some("a/b"), None, None); - t!(s: Path::init(b!("a/b/", 0xff, ".txt")), None, Some("a/b"), None, Some("txt")); - t!(s: Path::init(b!("a/b/c.", 0x80)), None, Some("a/b"), Some("c"), None); - t!(s: Path::init(b!(0xff, "/b")), Some("b"), None, Some("b"), None); + t!(s: Path::new(b!("a/b/", 0xff)), None, Some("a/b"), None, None); + t!(s: Path::new(b!("a/b/", 0xff, ".txt")), None, Some("a/b"), None, Some("txt")); + t!(s: Path::new(b!("a/b/c.", 0x80)), None, Some("a/b"), Some("c"), None); + t!(s: Path::new(b!(0xff, "/b")), Some("b"), None, Some("b"), None); } #[test] fn test_dir_path() { - t!(v: Path::init(b!("hi/there", 0x80)).dir_path(), b!("hi")); - t!(v: Path::init(b!("hi", 0xff, "/there")).dir_path(), b!("hi", 0xff)); - t!(s: Path::init("hi/there").dir_path(), "hi"); - t!(s: Path::init("hi").dir_path(), "."); - t!(s: Path::init("/hi").dir_path(), "/"); - t!(s: Path::init("/").dir_path(), "/"); - t!(s: Path::init("..").dir_path(), ".."); - t!(s: Path::init("../..").dir_path(), "../.."); + t!(v: Path::new(b!("hi/there", 0x80)).dir_path(), b!("hi")); + t!(v: Path::new(b!("hi", 0xff, "/there")).dir_path(), b!("hi", 0xff)); + t!(s: Path::new("hi/there").dir_path(), "hi"); + t!(s: Path::new("hi").dir_path(), "."); + t!(s: Path::new("/hi").dir_path(), "/"); + t!(s: Path::new("/").dir_path(), "/"); + t!(s: Path::new("..").dir_path(), ".."); + t!(s: Path::new("../..").dir_path(), "../.."); } #[test] @@ -1109,7 +1109,7 @@ mod tests { macro_rules! t( (s: $path:expr, $abs:expr, $rel:expr) => ( { - let path = Path::init($path); + let path = Path::new($path); assert_eq!(path.is_absolute(), $abs); assert_eq!(path.is_relative(), $rel); } @@ -1130,8 +1130,8 @@ mod tests { macro_rules! t( (s: $path:expr, $dest:expr, $exp:expr) => ( { - let path = Path::init($path); - let dest = Path::init($dest); + let path = Path::new($path); + let dest = Path::new($dest); assert_eq!(path.is_ancestor_of(&dest), $exp); } ) @@ -1164,15 +1164,15 @@ mod tests { macro_rules! t( (s: $path:expr, $child:expr, $exp:expr) => ( { - let path = Path::init($path); - let child = Path::init($child); + let path = Path::new($path); + let child = Path::new($child); assert_eq!(path.ends_with_path(&child), $exp); } ); (v: $path:expr, $child:expr, $exp:expr) => ( { - let path = Path::init($path); - let child = Path::init($child); + let path = Path::new($path); + let child = Path::new($child); assert_eq!(path.ends_with_path(&child), $exp); } ) @@ -1203,8 +1203,8 @@ mod tests { macro_rules! t( (s: $path:expr, $other:expr, $exp:expr) => ( { - let path = Path::init($path); - let other = Path::init($other); + let path = Path::new($path); + let other = Path::new($other); let res = path.path_relative_from(&other); assert_eq!(res.as_ref().and_then(|x| x.as_str()), $exp); } @@ -1248,7 +1248,7 @@ mod tests { macro_rules! t( (s: $path:expr, $exp:expr) => ( { - let path = Path::init($path); + let path = Path::new($path); let comps = path.components().to_owned_vec(); let exp: &[&str] = $exp; let exps = exp.iter().map(|x| x.as_bytes()).to_owned_vec(); @@ -1262,7 +1262,7 @@ mod tests { ); (v: [$($arg:expr),+], [$([$($exp:expr),*]),*]) => ( { - let path = Path::init(b!($($arg),+)); + let path = Path::new(b!($($arg),+)); let comps = path.components().to_owned_vec(); let exp: &[&[u8]] = [$(b!($($exp),*)),*]; assert!(comps.as_slice() == exp, "components: Expected {:?}, found {:?}", @@ -1297,7 +1297,7 @@ mod tests { macro_rules! t( (v: [$($arg:expr),+], $exp:expr) => ( { - let path = Path::init(b!($($arg),+)); + let path = Path::new(b!($($arg),+)); let comps = path.str_components().to_owned_vec(); let exp: &[Option<&str>] = $exp; assert!(comps.as_slice() == exp, @@ -1327,7 +1327,7 @@ mod bench { #[bench] fn join_home_dir(bh: &mut BenchHarness) { - let posix_path = Path::init("/"); + let posix_path = Path::new("/"); bh.iter(|| { posix_path.join("home"); }); @@ -1335,7 +1335,7 @@ mod bench { #[bench] fn join_abs_path_home_dir(bh: &mut BenchHarness) { - let posix_path = Path::init("/"); + let posix_path = Path::new("/"); bh.iter(|| { posix_path.join("/home"); }); @@ -1343,7 +1343,7 @@ mod bench { #[bench] fn join_many_home_dir(bh: &mut BenchHarness) { - let posix_path = Path::init("/"); + let posix_path = Path::new("/"); bh.iter(|| { posix_path.join_many(&["home"]); }); @@ -1351,7 +1351,7 @@ mod bench { #[bench] fn join_many_abs_path_home_dir(bh: &mut BenchHarness) { - let posix_path = Path::init("/"); + let posix_path = Path::new("/"); bh.iter(|| { posix_path.join_many(&["/home"]); }); @@ -1359,7 +1359,7 @@ mod bench { #[bench] fn push_home_dir(bh: &mut BenchHarness) { - let mut posix_path = Path::init("/"); + let mut posix_path = Path::new("/"); bh.iter(|| { posix_path.push("home"); }); @@ -1367,7 +1367,7 @@ mod bench { #[bench] fn push_abs_path_home_dir(bh: &mut BenchHarness) { - let mut posix_path = Path::init("/"); + let mut posix_path = Path::new("/"); bh.iter(|| { posix_path.push("/home"); }); @@ -1375,7 +1375,7 @@ mod bench { #[bench] fn push_many_home_dir(bh: &mut BenchHarness) { - let mut posix_path = Path::init("/"); + let mut posix_path = Path::new("/"); bh.iter(|| { posix_path.push_many(&["home"]); }); @@ -1383,7 +1383,7 @@ mod bench { #[bench] fn push_many_abs_path_home_dir(bh: &mut BenchHarness) { - let mut posix_path = Path::init("/"); + let mut posix_path = Path::new("/"); bh.iter(|| { posix_path.push_many(&["/home"]); }); @@ -1391,17 +1391,17 @@ mod bench { #[bench] fn ends_with_path_home_dir(bh: &mut BenchHarness) { - let posix_home_path = Path::init("/home"); + let posix_home_path = Path::new("/home"); bh.iter(|| { - posix_home_path.ends_with_path(&Path::init("home")); + posix_home_path.ends_with_path(&Path::new("home")); }); } #[bench] fn ends_with_path_missmatch_jome_home(bh: &mut BenchHarness) { - let posix_home_path = Path::init("/home"); + let posix_home_path = Path::new("/home"); bh.iter(|| { - posix_home_path.ends_with_path(&Path::init("jome")); + posix_home_path.ends_with_path(&Path::new("jome")); }); } } diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index abbb97981a6..cc2af54fd10 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -93,7 +93,7 @@ impl Eq for Path { impl FromStr for Path { fn from_str(s: &str) -> Option<Path> { - Path::init_opt(s) + Path::new_opt(s) } } @@ -162,7 +162,7 @@ impl GenericPathUnsafe for Path { /// /// Raises the `str::not_utf8` condition if not valid UTF-8. #[inline] - unsafe fn init_unchecked<T: BytesContainer>(path: T) -> Path { + unsafe fn new_unchecked<T: BytesContainer>(path: T) -> Path { let (prefix, path) = Path::normalize_(path.container_as_str()); assert!(!path.is_empty()); let mut ret = Path{ repr: path, prefix: prefix, sepidx: None }; @@ -303,7 +303,7 @@ impl GenericPathUnsafe for Path { impl GenericPath for Path { #[inline] - fn init_opt<T: BytesContainer>(path: T) -> Option<Path> { + fn new_opt<T: BytesContainer>(path: T) -> Option<Path> { let s = path.container_as_str_opt(); match s { None => None, @@ -311,7 +311,7 @@ impl GenericPath for Path { if contains_nul(s.as_bytes()) { None } else { - Some(unsafe { GenericPathUnsafe::init_unchecked(s) }) + Some(unsafe { GenericPathUnsafe::new_unchecked(s) }) } } } @@ -395,7 +395,7 @@ impl GenericPath for Path { } fn dir_path(&self) -> Path { - unsafe { GenericPathUnsafe::init_unchecked(self.dirname_str().unwrap()) } + unsafe { GenericPathUnsafe::new_unchecked(self.dirname_str().unwrap()) } } #[inline] @@ -426,14 +426,14 @@ impl GenericPath for Path { fn root_path(&self) -> Option<Path> { if self.is_absolute() { - Some(Path::init(match self.prefix { + Some(Path::new(match self.prefix { Some(VerbatimDiskPrefix)|Some(DiskPrefix) => { self.repr.slice_to(self.prefix_len()+1) } _ => self.repr.slice_to(self.prefix_len()) })) } else if is_vol_relative(self) { - Some(Path::init(self.repr.slice_to(1))) + Some(Path::new(self.repr.slice_to(1))) } else { None } @@ -563,7 +563,7 @@ impl GenericPath for Path { } } } - Some(Path::init(comps.connect("\\"))) + Some(Path::new(comps.connect("\\"))) } } @@ -591,14 +591,14 @@ impl Path { /// Raises the `null_byte` condition if the vector contains a NUL. /// Raises the `str::not_utf8` condition if invalid UTF-8. #[inline] - pub fn init<T: BytesContainer>(path: T) -> Path { - GenericPath::init(path) + pub fn new<T: BytesContainer>(path: T) -> Path { + GenericPath::new(path) } /// Returns a new Path from a byte vector or string, if possible #[inline] - pub fn init_opt<T: BytesContainer>(path: T) -> Option<Path> { - GenericPath::init_opt(path) + pub fn new_opt<T: BytesContainer>(path: T) -> Option<Path> { + GenericPath::new_opt(path) } /// Returns an iterator that yields each component of the path in turn as a Option<&str>. @@ -1147,100 +1147,100 @@ mod tests { #[test] fn test_paths() { let empty: &[u8] = []; - t!(v: Path::init(empty), b!(".")); - t!(v: Path::init(b!("\\")), b!("\\")); - t!(v: Path::init(b!("a\\b\\c")), b!("a\\b\\c")); - - t!(s: Path::init(""), "."); - t!(s: Path::init("\\"), "\\"); - t!(s: Path::init("hi"), "hi"); - t!(s: Path::init("hi\\"), "hi"); - t!(s: Path::init("\\lib"), "\\lib"); - t!(s: Path::init("\\lib\\"), "\\lib"); - t!(s: Path::init("hi\\there"), "hi\\there"); - t!(s: Path::init("hi\\there.txt"), "hi\\there.txt"); - t!(s: Path::init("/"), "\\"); - t!(s: Path::init("hi/"), "hi"); - t!(s: Path::init("/lib"), "\\lib"); - t!(s: Path::init("/lib/"), "\\lib"); - t!(s: Path::init("hi/there"), "hi\\there"); - - t!(s: Path::init("hi\\there\\"), "hi\\there"); - t!(s: Path::init("hi\\..\\there"), "there"); - t!(s: Path::init("hi/../there"), "there"); - t!(s: Path::init("..\\hi\\there"), "..\\hi\\there"); - t!(s: Path::init("\\..\\hi\\there"), "\\hi\\there"); - t!(s: Path::init("/../hi/there"), "\\hi\\there"); - t!(s: Path::init("foo\\.."), "."); - t!(s: Path::init("\\foo\\.."), "\\"); - t!(s: Path::init("\\foo\\..\\.."), "\\"); - t!(s: Path::init("\\foo\\..\\..\\bar"), "\\bar"); - t!(s: Path::init("\\.\\hi\\.\\there\\."), "\\hi\\there"); - t!(s: Path::init("\\.\\hi\\.\\there\\.\\.."), "\\hi"); - t!(s: Path::init("foo\\..\\.."), ".."); - t!(s: Path::init("foo\\..\\..\\.."), "..\\.."); - t!(s: Path::init("foo\\..\\..\\bar"), "..\\bar"); - - assert_eq!(Path::init(b!("foo\\bar")).into_vec(), b!("foo\\bar").to_owned()); - assert_eq!(Path::init(b!("\\foo\\..\\..\\bar")).into_vec(), + t!(v: Path::new(empty), b!(".")); + t!(v: Path::new(b!("\\")), b!("\\")); + t!(v: Path::new(b!("a\\b\\c")), b!("a\\b\\c")); + + t!(s: Path::new(""), "."); + t!(s: Path::new("\\"), "\\"); + t!(s: Path::new("hi"), "hi"); + t!(s: Path::new("hi\\"), "hi"); + t!(s: Path::new("\\lib"), "\\lib"); + t!(s: Path::new("\\lib\\"), "\\lib"); + t!(s: Path::new("hi\\there"), "hi\\there"); + t!(s: Path::new("hi\\there.txt"), "hi\\there.txt"); + t!(s: Path::new("/"), "\\"); + t!(s: Path::new("hi/"), "hi"); + t!(s: Path::new("/lib"), "\\lib"); + t!(s: Path::new("/lib/"), "\\lib"); + t!(s: Path::new("hi/there"), "hi\\there"); + + t!(s: Path::new("hi\\there\\"), "hi\\there"); + t!(s: Path::new("hi\\..\\there"), "there"); + t!(s: Path::new("hi/../there"), "there"); + t!(s: Path::new("..\\hi\\there"), "..\\hi\\there"); + t!(s: Path::new("\\..\\hi\\there"), "\\hi\\there"); + t!(s: Path::new("/../hi/there"), "\\hi\\there"); + t!(s: Path::new("foo\\.."), "."); + t!(s: Path::new("\\foo\\.."), "\\"); + t!(s: Path::new("\\foo\\..\\.."), "\\"); + t!(s: Path::new("\\foo\\..\\..\\bar"), "\\bar"); + t!(s: Path::new("\\.\\hi\\.\\there\\."), "\\hi\\there"); + t!(s: Path::new("\\.\\hi\\.\\there\\.\\.."), "\\hi"); + t!(s: Path::new("foo\\..\\.."), ".."); + t!(s: Path::new("foo\\..\\..\\.."), "..\\.."); + t!(s: Path::new("foo\\..\\..\\bar"), "..\\bar"); + + assert_eq!(Path::new(b!("foo\\bar")).into_vec(), b!("foo\\bar").to_owned()); + assert_eq!(Path::new(b!("\\foo\\..\\..\\bar")).into_vec(), b!("\\bar").to_owned()); - t!(s: Path::init("\\\\a"), "\\a"); - t!(s: Path::init("\\\\a\\"), "\\a"); - t!(s: Path::init("\\\\a\\b"), "\\\\a\\b"); - t!(s: Path::init("\\\\a\\b\\"), "\\\\a\\b"); - t!(s: Path::init("\\\\a\\b/"), "\\\\a\\b"); - t!(s: Path::init("\\\\\\b"), "\\b"); - t!(s: Path::init("\\\\a\\\\b"), "\\a\\b"); - t!(s: Path::init("\\\\a\\b\\c"), "\\\\a\\b\\c"); - t!(s: Path::init("\\\\server\\share/path"), "\\\\server\\share\\path"); - t!(s: Path::init("\\\\server/share/path"), "\\\\server\\share\\path"); - t!(s: Path::init("C:a\\b.txt"), "C:a\\b.txt"); - t!(s: Path::init("C:a/b.txt"), "C:a\\b.txt"); - t!(s: Path::init("z:\\a\\b.txt"), "Z:\\a\\b.txt"); - t!(s: Path::init("z:/a/b.txt"), "Z:\\a\\b.txt"); - t!(s: Path::init("ab:/a/b.txt"), "ab:\\a\\b.txt"); - t!(s: Path::init("C:\\"), "C:\\"); - t!(s: Path::init("C:"), "C:"); - t!(s: Path::init("q:"), "Q:"); - t!(s: Path::init("C:/"), "C:\\"); - t!(s: Path::init("C:\\foo\\.."), "C:\\"); - t!(s: Path::init("C:foo\\.."), "C:"); - t!(s: Path::init("C:\\a\\"), "C:\\a"); - t!(s: Path::init("C:\\a/"), "C:\\a"); - t!(s: Path::init("C:\\a\\b\\"), "C:\\a\\b"); - t!(s: Path::init("C:\\a\\b/"), "C:\\a\\b"); - t!(s: Path::init("C:a\\"), "C:a"); - t!(s: Path::init("C:a/"), "C:a"); - t!(s: Path::init("C:a\\b\\"), "C:a\\b"); - t!(s: Path::init("C:a\\b/"), "C:a\\b"); - t!(s: Path::init("\\\\?\\z:\\a\\b.txt"), "\\\\?\\z:\\a\\b.txt"); - t!(s: Path::init("\\\\?\\C:/a/b.txt"), "\\\\?\\C:/a/b.txt"); - t!(s: Path::init("\\\\?\\C:\\a/b.txt"), "\\\\?\\C:\\a/b.txt"); - t!(s: Path::init("\\\\?\\test\\a\\b.txt"), "\\\\?\\test\\a\\b.txt"); - t!(s: Path::init("\\\\?\\foo\\bar\\"), "\\\\?\\foo\\bar\\"); - t!(s: Path::init("\\\\.\\foo\\bar"), "\\\\.\\foo\\bar"); - t!(s: Path::init("\\\\.\\"), "\\\\.\\"); - t!(s: Path::init("\\\\?\\UNC\\server\\share\\foo"), "\\\\?\\UNC\\server\\share\\foo"); - t!(s: Path::init("\\\\?\\UNC\\server/share"), "\\\\?\\UNC\\server/share\\"); - t!(s: Path::init("\\\\?\\UNC\\server"), "\\\\?\\UNC\\server\\"); - t!(s: Path::init("\\\\?\\UNC\\"), "\\\\?\\UNC\\\\"); - t!(s: Path::init("\\\\?\\UNC"), "\\\\?\\UNC"); + t!(s: Path::new("\\\\a"), "\\a"); + t!(s: Path::new("\\\\a\\"), "\\a"); + t!(s: Path::new("\\\\a\\b"), "\\\\a\\b"); + t!(s: Path::new("\\\\a\\b\\"), "\\\\a\\b"); + t!(s: Path::new("\\\\a\\b/"), "\\\\a\\b"); + t!(s: Path::new("\\\\\\b"), "\\b"); + t!(s: Path::new("\\\\a\\\\b"), "\\a\\b"); + t!(s: Path::new("\\\\a\\b\\c"), "\\\\a\\b\\c"); + t!(s: Path::new("\\\\server\\share/path"), "\\\\server\\share\\path"); + t!(s: Path::new("\\\\server/share/path"), "\\\\server\\share\\path"); + t!(s: Path::new("C:a\\b.txt"), "C:a\\b.txt"); + t!(s: Path::new("C:a/b.txt"), "C:a\\b.txt"); + t!(s: Path::new("z:\\a\\b.txt"), "Z:\\a\\b.txt"); + t!(s: Path::new("z:/a/b.txt"), "Z:\\a\\b.txt"); + t!(s: Path::new("ab:/a/b.txt"), "ab:\\a\\b.txt"); + t!(s: Path::new("C:\\"), "C:\\"); + t!(s: Path::new("C:"), "C:"); + t!(s: Path::new("q:"), "Q:"); + t!(s: Path::new("C:/"), "C:\\"); + t!(s: Path::new("C:\\foo\\.."), "C:\\"); + t!(s: Path::new("C:foo\\.."), "C:"); + t!(s: Path::new("C:\\a\\"), "C:\\a"); + t!(s: Path::new("C:\\a/"), "C:\\a"); + t!(s: Path::new("C:\\a\\b\\"), "C:\\a\\b"); + t!(s: Path::new("C:\\a\\b/"), "C:\\a\\b"); + t!(s: Path::new("C:a\\"), "C:a"); + t!(s: Path::new("C:a/"), "C:a"); + t!(s: Path::new("C:a\\b\\"), "C:a\\b"); + t!(s: Path::new("C:a\\b/"), "C:a\\b"); + t!(s: Path::new("\\\\?\\z:\\a\\b.txt"), "\\\\?\\z:\\a\\b.txt"); + t!(s: Path::new("\\\\?\\C:/a/b.txt"), "\\\\?\\C:/a/b.txt"); + t!(s: Path::new("\\\\?\\C:\\a/b.txt"), "\\\\?\\C:\\a/b.txt"); + t!(s: Path::new("\\\\?\\test\\a\\b.txt"), "\\\\?\\test\\a\\b.txt"); + t!(s: Path::new("\\\\?\\foo\\bar\\"), "\\\\?\\foo\\bar\\"); + t!(s: Path::new("\\\\.\\foo\\bar"), "\\\\.\\foo\\bar"); + t!(s: Path::new("\\\\.\\"), "\\\\.\\"); + t!(s: Path::new("\\\\?\\UNC\\server\\share\\foo"), "\\\\?\\UNC\\server\\share\\foo"); + t!(s: Path::new("\\\\?\\UNC\\server/share"), "\\\\?\\UNC\\server/share\\"); + t!(s: Path::new("\\\\?\\UNC\\server"), "\\\\?\\UNC\\server\\"); + t!(s: Path::new("\\\\?\\UNC\\"), "\\\\?\\UNC\\\\"); + t!(s: Path::new("\\\\?\\UNC"), "\\\\?\\UNC"); // I'm not sure whether \\.\foo/bar should normalize to \\.\foo\bar // as information is sparse and this isn't really googleable. // I'm going to err on the side of not normalizing it, as this skips the filesystem - t!(s: Path::init("\\\\.\\foo/bar"), "\\\\.\\foo/bar"); - t!(s: Path::init("\\\\.\\foo\\bar"), "\\\\.\\foo\\bar"); + t!(s: Path::new("\\\\.\\foo/bar"), "\\\\.\\foo/bar"); + t!(s: Path::new("\\\\.\\foo\\bar"), "\\\\.\\foo\\bar"); } #[test] fn test_opt_paths() { - assert_eq!(Path::init_opt(b!("foo\\bar", 0)), None); - assert_eq!(Path::init_opt(b!("foo\\bar", 0x80)), None); - t!(v: Path::init_opt(b!("foo\\bar")).unwrap(), b!("foo\\bar")); - assert_eq!(Path::init_opt("foo\\bar\0"), None); - t!(s: Path::init_opt("foo\\bar").unwrap(), "foo\\bar"); + assert_eq!(Path::new_opt(b!("foo\\bar", 0)), None); + assert_eq!(Path::new_opt(b!("foo\\bar", 0x80)), None); + t!(v: Path::new_opt(b!("foo\\bar")).unwrap(), b!("foo\\bar")); + assert_eq!(Path::new_opt("foo\\bar\0"), None); + t!(s: Path::new_opt("foo\\bar").unwrap(), "foo\\bar"); } #[test] @@ -1253,7 +1253,7 @@ mod tests { assert_eq!(v.as_slice(), b!("foo\\bar", 0)); (b!("\\bar").to_owned()) }).inside(|| { - Path::init(b!("foo\\bar", 0)) + Path::new(b!("foo\\bar", 0)) }); assert!(handled); assert_eq!(p.as_vec(), b!("\\bar")); @@ -1301,12 +1301,12 @@ mod tests { cond.trap(|_| { (b!("null", 0).to_owned()) }).inside(|| { - Path::init(b!("foo\\bar", 0)) + Path::new(b!("foo\\bar", 0)) }); }) t!(~"set_filename w\\nul" => { - let mut p = Path::init(b!("foo\\bar")); + let mut p = Path::new(b!("foo\\bar")); cond.trap(|_| { (b!("null", 0).to_owned()) }).inside(|| { @@ -1315,7 +1315,7 @@ mod tests { }) t!(~"push w\\nul" => { - let mut p = Path::init(b!("foo\\bar")); + let mut p = Path::new(b!("foo\\bar")); cond.trap(|_| { (b!("null", 0).to_owned()) }).inside(|| { @@ -1327,25 +1327,25 @@ mod tests { #[test] #[should_fail] fn test_not_utf8_fail() { - Path::init(b!("hello", 0x80, ".txt")); + Path::new(b!("hello", 0x80, ".txt")); } #[test] fn test_display_str() { - let path = Path::init("foo"); + let path = Path::new("foo"); assert_eq!(path.display().to_str(), ~"foo"); - let path = Path::init(b!("\\")); + let path = Path::new(b!("\\")); assert_eq!(path.filename_display().to_str(), ~""); let mut called = false; - let path = Path::init("foo"); + let path = Path::new("foo"); path.display().with_str(|s| { assert_eq!(s, "foo"); called = true; }); assert!(called); called = false; - let path = Path::init(b!("\\")); + let path = Path::new(b!("\\")); path.filename_display().with_str(|s| { assert_eq!(s, ""); called = true; @@ -1358,7 +1358,7 @@ mod tests { macro_rules! t( ($path:expr, $exp:expr, $expf:expr) => ( { - let path = Path::init($path); + let path = Path::new($path); let f = format!("{}", path.display()); assert_eq!(f.as_slice(), $exp); let f = format!("{}", path.filename_display()); @@ -1377,20 +1377,20 @@ mod tests { macro_rules! t( (s: $path:expr, $op:ident, $exp:expr) => ( { - let path = Path::init($path); + let path = Path::new($path); assert_eq!(path.$op(), Some($exp)); } ); (s: $path:expr, $op:ident, $exp:expr, opt) => ( { - let path = Path::init($path); + let path = Path::new($path); let left = path.$op(); assert_eq!(left, $exp); } ); (v: $path:expr, $op:ident, $exp:expr) => ( { - let path = Path::init($path); + let path = Path::new($path); assert_eq!(path.$op(), $exp); } ) @@ -1499,7 +1499,7 @@ mod tests { { let path = ($path); let join = ($join); - let mut p1 = Path::init(path); + let mut p1 = Path::new(path); let p2 = p1.clone(); p1.push(join); assert_eq!(p1, p2.join(join)); @@ -1515,14 +1515,14 @@ mod tests { // so there's no need for the full set of prefix tests // we do want to check one odd case though to ensure the prefix is re-parsed - let mut p = Path::init("\\\\?\\C:"); + let mut p = Path::new("\\\\?\\C:"); assert_eq!(prefix(&p), Some(VerbatimPrefix(2))); p.push("foo"); assert_eq!(prefix(&p), Some(VerbatimDiskPrefix)); assert_eq!(p.as_str(), Some("\\\\?\\C:\\foo")); // and another with verbatim non-normalized paths - let mut p = Path::init("\\\\?\\C:\\a\\"); + let mut p = Path::new("\\\\?\\C:\\a\\"); p.push("foo"); assert_eq!(p.as_str(), Some("\\\\?\\C:\\a\\foo")); } @@ -1532,8 +1532,8 @@ mod tests { macro_rules! t( (s: $path:expr, $push:expr, $exp:expr) => ( { - let mut p = Path::init($path); - let push = Path::init($push); + let mut p = Path::new($path); + let push = Path::new($push); p.push(&push); assert_eq!(p.as_str(), Some($exp)); } @@ -1584,14 +1584,14 @@ mod tests { macro_rules! t( (s: $path:expr, $push:expr, $exp:expr) => ( { - let mut p = Path::init($path); + let mut p = Path::new($path); p.push_many($push); assert_eq!(p.as_str(), Some($exp)); } ); (v: $path:expr, $push:expr, $exp:expr) => ( { - let mut p = Path::init($path); + let mut p = Path::new($path); p.push_many($push); assert_eq!(p.as_vec(), $exp); } @@ -1616,7 +1616,7 @@ mod tests { (s: $path:expr, $left:expr, $right:expr) => ( { let pstr = $path; - let mut p = Path::init(pstr); + let mut p = Path::new(pstr); let result = p.pop(); let left = $left; assert!(p.as_str() == Some(left), @@ -1627,7 +1627,7 @@ mod tests { ); (v: [$($path:expr),+], [$($left:expr),+], $right:expr) => ( { - let mut p = Path::init(b!($($path),+)); + let mut p = Path::new(b!($($path),+)); let result = p.pop(); assert_eq!(p.as_vec(), b!($($left),+)); assert_eq!(result, $right); @@ -1673,28 +1673,28 @@ mod tests { #[test] fn test_root_path() { - assert_eq!(Path::init("a\\b\\c").root_path(), None); - assert_eq!(Path::init("\\a\\b\\c").root_path(), Some(Path::init("\\"))); - assert_eq!(Path::init("C:a").root_path(), None); - assert_eq!(Path::init("C:\\a").root_path(), Some(Path::init("C:\\"))); - assert_eq!(Path::init("\\\\a\\b\\c").root_path(), Some(Path::init("\\\\a\\b"))); - assert_eq!(Path::init("\\\\?\\a\\b").root_path(), Some(Path::init("\\\\?\\a"))); - assert_eq!(Path::init("\\\\?\\C:\\a").root_path(), Some(Path::init("\\\\?\\C:\\"))); - assert_eq!(Path::init("\\\\?\\UNC\\a\\b\\c").root_path(), - Some(Path::init("\\\\?\\UNC\\a\\b"))); - assert_eq!(Path::init("\\\\.\\a\\b").root_path(), Some(Path::init("\\\\.\\a"))); + assert_eq!(Path::new("a\\b\\c").root_path(), None); + assert_eq!(Path::new("\\a\\b\\c").root_path(), Some(Path::new("\\"))); + assert_eq!(Path::new("C:a").root_path(), None); + assert_eq!(Path::new("C:\\a").root_path(), Some(Path::new("C:\\"))); + assert_eq!(Path::new("\\\\a\\b\\c").root_path(), Some(Path::new("\\\\a\\b"))); + assert_eq!(Path::new("\\\\?\\a\\b").root_path(), Some(Path::new("\\\\?\\a"))); + assert_eq!(Path::new("\\\\?\\C:\\a").root_path(), Some(Path::new("\\\\?\\C:\\"))); + assert_eq!(Path::new("\\\\?\\UNC\\a\\b\\c").root_path(), + Some(Path::new("\\\\?\\UNC\\a\\b"))); + assert_eq!(Path::new("\\\\.\\a\\b").root_path(), Some(Path::new("\\\\.\\a"))); } #[test] fn test_join() { - t!(s: Path::init("a\\b\\c").join(".."), "a\\b"); - t!(s: Path::init("\\a\\b\\c").join("d"), "\\a\\b\\c\\d"); - t!(s: Path::init("a\\b").join("c\\d"), "a\\b\\c\\d"); - t!(s: Path::init("a\\b").join("\\c\\d"), "\\c\\d"); - t!(s: Path::init(".").join("a\\b"), "a\\b"); - t!(s: Path::init("\\").join("a\\b"), "\\a\\b"); - t!(v: Path::init(b!("a\\b\\c")).join(b!("..")), b!("a\\b")); - t!(v: Path::init(b!("\\a\\b\\c")).join(b!("d")), b!("\\a\\b\\c\\d")); + t!(s: Path::new("a\\b\\c").join(".."), "a\\b"); + t!(s: Path::new("\\a\\b\\c").join("d"), "\\a\\b\\c\\d"); + t!(s: Path::new("a\\b").join("c\\d"), "a\\b\\c\\d"); + t!(s: Path::new("a\\b").join("\\c\\d"), "\\c\\d"); + t!(s: Path::new(".").join("a\\b"), "a\\b"); + t!(s: Path::new("\\").join("a\\b"), "\\a\\b"); + t!(v: Path::new(b!("a\\b\\c")).join(b!("..")), b!("a\\b")); + t!(v: Path::new(b!("\\a\\b\\c")).join(b!("d")), b!("\\a\\b\\c\\d")); // full join testing is covered under test_push_path, so no need for // the full set of prefix tests } @@ -1704,8 +1704,8 @@ mod tests { macro_rules! t( (s: $path:expr, $join:expr, $exp:expr) => ( { - let path = Path::init($path); - let join = Path::init($join); + let path = Path::new($path); + let join = Path::new($join); let res = path.join(&join); assert_eq!(res.as_str(), Some($exp)); } @@ -1729,14 +1729,14 @@ mod tests { macro_rules! t( (s: $path:expr, $join:expr, $exp:expr) => ( { - let path = Path::init($path); + let path = Path::new($path); let res = path.join_many($join); assert_eq!(res.as_str(), Some($exp)); } ); (v: $path:expr, $join:expr, $exp:expr) => ( { - let path = Path::init($path); + let path = Path::new($path); let res = path.join_many($join); assert_eq!(res.as_vec(), $exp); } @@ -1760,7 +1760,7 @@ mod tests { (s: $path:expr, $op:ident, $arg:expr, $res:expr) => ( { let pstr = $path; - let path = Path::init(pstr); + let path = Path::new(pstr); let arg = $arg; let res = path.$op(arg); let exp = $res; @@ -1846,9 +1846,9 @@ mod tests { { let path = $path; let arg = $arg; - let mut p1 = Path::init(path); + let mut p1 = Path::new(path); p1.$set(arg); - let p2 = Path::init(path); + let p2 = Path::new(path); assert_eq!(p1, p2.$with(arg)); } ); @@ -1856,9 +1856,9 @@ mod tests { { let path = $path; let arg = $arg; - let mut p1 = Path::init(path); + let mut p1 = Path::new(path); p1.$set(arg); - let p2 = Path::init(path); + let p2 = Path::new(path); assert_eq!(p1, p2.$with(arg)); } ) @@ -1919,19 +1919,19 @@ mod tests { ) ) - t!(v: Path::init(b!("a\\b\\c")), Some(b!("c")), b!("a\\b"), Some(b!("c")), None); - t!(s: Path::init("a\\b\\c"), Some("c"), Some("a\\b"), Some("c"), None); - t!(s: Path::init("."), None, Some("."), None, None); - t!(s: Path::init("\\"), None, Some("\\"), None, None); - t!(s: Path::init(".."), None, Some(".."), None, None); - t!(s: Path::init("..\\.."), None, Some("..\\.."), None, None); - t!(s: Path::init("hi\\there.txt"), Some("there.txt"), Some("hi"), + t!(v: Path::new(b!("a\\b\\c")), Some(b!("c")), b!("a\\b"), Some(b!("c")), None); + t!(s: Path::new("a\\b\\c"), Some("c"), Some("a\\b"), Some("c"), None); + t!(s: Path::new("."), None, Some("."), None, None); + t!(s: Path::new("\\"), None, Some("\\"), None, None); + t!(s: Path::new(".."), None, Some(".."), None, None); + t!(s: Path::new("..\\.."), None, Some("..\\.."), None, None); + t!(s: Path::new("hi\\there.txt"), Some("there.txt"), Some("hi"), Some("there"), Some("txt")); - t!(s: Path::init("hi\\there"), Some("there"), Some("hi"), Some("there"), None); - t!(s: Path::init("hi\\there."), Some("there."), Some("hi"), + t!(s: Path::new("hi\\there"), Some("there"), Some("hi"), Some("there"), None); + t!(s: Path::new("hi\\there."), Some("there."), Some("hi"), Some("there"), Some("")); - t!(s: Path::init("hi\\.there"), Some(".there"), Some("hi"), Some(".there"), None); - t!(s: Path::init("hi\\..there"), Some("..there"), Some("hi"), + t!(s: Path::new("hi\\.there"), Some(".there"), Some("hi"), Some(".there"), None); + t!(s: Path::new("hi\\..there"), Some("..there"), Some("hi"), Some("."), Some("there")); // these are already tested in test_components, so no need for extended tests @@ -1939,12 +1939,12 @@ mod tests { #[test] fn test_dir_path() { - t!(s: Path::init("hi\\there").dir_path(), "hi"); - t!(s: Path::init("hi").dir_path(), "."); - t!(s: Path::init("\\hi").dir_path(), "\\"); - t!(s: Path::init("\\").dir_path(), "\\"); - t!(s: Path::init("..").dir_path(), ".."); - t!(s: Path::init("..\\..").dir_path(), "..\\.."); + t!(s: Path::new("hi\\there").dir_path(), "hi"); + t!(s: Path::new("hi").dir_path(), "."); + t!(s: Path::new("\\hi").dir_path(), "\\"); + t!(s: Path::new("\\").dir_path(), "\\"); + t!(s: Path::new("..").dir_path(), ".."); + t!(s: Path::new("..\\..").dir_path(), "..\\.."); // dir_path is just dirname interpreted as a path. // No need for extended tests @@ -1955,7 +1955,7 @@ mod tests { macro_rules! t( ($path:expr, $abs:expr, $vol:expr, $cwd:expr, $rel:expr) => ( { - let path = Path::init($path); + let path = Path::new($path); let (abs, vol, cwd, rel) = ($abs, $vol, $cwd, $rel); let b = path.is_absolute(); assert!(b == abs, "Path '{}'.is_absolute(): expected {:?}, found {:?}", @@ -1995,8 +1995,8 @@ mod tests { macro_rules! t( (s: $path:expr, $dest:expr, $exp:expr) => ( { - let path = Path::init($path); - let dest = Path::init($dest); + let path = Path::new($path); + let dest = Path::new($dest); let exp = $exp; let res = path.is_ancestor_of(&dest); assert!(res == exp, @@ -2098,8 +2098,8 @@ mod tests { macro_rules! t( (s: $path:expr, $child:expr, $exp:expr) => ( { - let path = Path::init($path); - let child = Path::init($child); + let path = Path::new($path); + let child = Path::new($child); assert_eq!(path.ends_with_path(&child), $exp); } ); @@ -2130,8 +2130,8 @@ mod tests { macro_rules! t( (s: $path:expr, $other:expr, $exp:expr) => ( { - let path = Path::init($path); - let other = Path::init($other); + let path = Path::new($path); + let other = Path::new($other); let res = path.path_relative_from(&other); let exp = $exp; assert!(res.as_ref().and_then(|x| x.as_str()) == exp, @@ -2264,7 +2264,7 @@ mod tests { macro_rules! t( (s: $path:expr, $exp:expr) => ( { - let path = Path::init($path); + let path = Path::new($path); let comps = path.str_components().map(|x|x.unwrap()).to_owned_vec(); let exp: &[&str] = $exp; assert!(comps.as_slice() == exp, @@ -2279,7 +2279,7 @@ mod tests { ); (v: [$($arg:expr),+], $exp:expr) => ( { - let path = Path::init(b!($($arg),+)); + let path = Path::new(b!($($arg),+)); let comps = path.str_components().map(|x|x.unwrap()).to_owned_vec(); let exp: &[&str] = $exp; assert!(comps.as_slice() == exp, @@ -2339,7 +2339,7 @@ mod tests { macro_rules! t( (s: $path:expr, $exp:expr) => ( { - let path = Path::init($path); + let path = Path::new($path); let comps = path.components().to_owned_vec(); let exp: &[&[u8]] = $exp; assert!(comps.as_slice() == exp, "components: Expected {:?}, found {:?}", diff --git a/src/libstd/rand/os.rs b/src/libstd/rand/os.rs index a31522c642e..5558b8b3348 100644 --- a/src/libstd/rand/os.rs +++ b/src/libstd/rand/os.rs @@ -61,7 +61,7 @@ impl OSRng { #[cfg(unix)] pub fn new() -> OSRng { use path::Path; - let reader = File::open(&Path::init("/dev/urandom")); + let reader = File::open(&Path::new("/dev/urandom")); let reader = reader.expect("Error opening /dev/urandom"); let reader_rng = ReaderRng::new(reader); diff --git a/src/libstd/rt/test.rs b/src/libstd/rt/test.rs index 51ad37a2583..825116a4048 100644 --- a/src/libstd/rt/test.rs +++ b/src/libstd/rt/test.rs @@ -381,7 +381,7 @@ pub fn next_test_unix() -> Path { if cfg!(unix) { os::tmpdir().join(rand::task_rng().gen_ascii_str(20)) } else { - Path::init(r"\\.\pipe\" + rand::task_rng().gen_ascii_str(20)) + Path::new(r"\\.\pipe\" + rand::task_rng().gen_ascii_str(20)) } } diff --git a/src/libstd/run.rs b/src/libstd/run.rs index 6cc5e5cc9f2..d29b7388fe2 100644 --- a/src/libstd/run.rs +++ b/src/libstd/run.rs @@ -506,7 +506,7 @@ mod tests { let output = str::from_utf8_owned(prog.finish_with_output().output); let parent_dir = os::getcwd(); - let child_dir = Path::init(output.trim()); + let child_dir = Path::new(output.trim()); let parent_stat = parent_dir.stat(); let child_stat = child_dir.stat(); @@ -523,7 +523,7 @@ mod tests { let mut prog = run_pwd(Some(&parent_dir)); let output = str::from_utf8_owned(prog.finish_with_output().output); - let child_dir = Path::init(output.trim()); + let child_dir = Path::new(output.trim()); let parent_stat = parent_dir.stat(); let child_stat = child_dir.stat(); diff --git a/src/libstd/unstable/dynamic_lib.rs b/src/libstd/unstable/dynamic_lib.rs index bc8c01afc1d..2a6e40dc3a0 100644 --- a/src/libstd/unstable/dynamic_lib.rs +++ b/src/libstd/unstable/dynamic_lib.rs @@ -122,7 +122,7 @@ mod test { fn test_errors_do_not_crash() { // Open /dev/null as a library to get an error, and make sure // that only causes an error, and not a crash. - let path = GenericPath::init("/dev/null"); + let path = GenericPath::new("/dev/null"); match DynamicLibrary::open(Some(&path)) { Err(_) => {} Ok(_) => fail!("Successfully opened the empty library.") |
