Skip to content

Commit

Permalink
explicit PathBuf impl, test Path trait
Browse files Browse the repository at this point in the history
  • Loading branch information
danreeves committed Feb 24, 2023
1 parent 131dd14 commit 2778a91
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//! any symlink resolution or absolute path resolution. For more information you can see ["Getting Dot-Dot
//! Right"](https://9p.io/sys/doc/lexnames.html).
//!
//! For convenience, the [`PathClean`] trait is exposed and comes implemented for [`std::path::PathBuf`].
//! For convenience, the [`PathClean`] trait is exposed and comes implemented for [`std::path::{Path, PathBuf}`].
//!
//! ```rust
//! use std::path::PathBuf;
Expand All @@ -40,6 +40,13 @@ impl PathClean for Path {
}
}

/// PathClean implemented for `PathBuf`
impl PathClean for PathBuf {
fn clean(&self) -> PathBuf {
clean(self)
}
}

/// The core implementation. It performs the following, lexically:
/// 1. Reduce multiple slashes to a single slash.
/// 2. Eliminate `.` path name elements (the current directory).
Expand Down Expand Up @@ -81,7 +88,7 @@ where
#[cfg(test)]
mod tests {
use super::{clean, PathClean};
use std::path::PathBuf;
use std::path::{Path, PathBuf};

#[test]
fn test_empty_path_is_current_dir() {
Expand Down Expand Up @@ -169,6 +176,11 @@ mod tests {
);
}

#[test]
fn test_path_trait() {
assert_eq!(Path::new("/test/../path/").clean(), PathBuf::from("/path"));
}

#[test]
#[cfg(target_os = "windows")]
fn test_windows_paths() {
Expand Down

0 comments on commit 2778a91

Please sign in to comment.