Skip to content

Commit

Permalink
Substitute variables in tests
Browse files Browse the repository at this point in the history
Having to check exactly what path `bar` and `quux` refer to when reading
the tests makes it challenging to use them as a reference for behavior.
  • Loading branch information
9999years committed Jun 12, 2024
1 parent a78acde commit 4ec30a1
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,20 @@ use std::path::*;
/// use pathdiff::diff_paths;
/// use std::path::*;
///
/// let baz = "/foo/bar/baz";
/// let bar = "/foo/bar";
/// let quux = "/foo/bar/quux";
/// assert_eq!(diff_paths(bar, baz), Some("../".into()));
/// assert_eq!(diff_paths(baz, bar), Some("baz".into()));
/// assert_eq!(diff_paths(quux, baz), Some("../quux".into()));
/// assert_eq!(diff_paths(baz, quux), Some("../baz".into()));
/// assert_eq!(diff_paths(bar, quux), Some("../".into()));
/// assert_eq!(diff_paths("/foo/bar", "/foo/bar/baz"), Some("../".into()));
/// assert_eq!(diff_paths("/foo/bar/baz", "/foo/bar"), Some("baz".into()));
/// assert_eq!(diff_paths("/foo/bar/quux", "/foo/bar/baz"), Some("../quux".into()));
/// assert_eq!(diff_paths("/foo/bar/baz", "/foo/bar/quux"), Some("../baz".into()));
/// assert_eq!(diff_paths("/foo/bar", "/foo/bar/quux"), Some("../".into()));
///
/// assert_eq!(diff_paths(&baz, &bar.to_string()), Some("baz".into()));
/// assert_eq!(diff_paths(Path::new(baz), Path::new(bar).to_path_buf()), Some("baz".into()));
/// assert_eq!(
/// diff_paths(&"/foo/bar/baz", "/foo/bar".to_string()),
/// Some("baz".into())
/// );
/// assert_eq!(
/// diff_paths(Path::new("/foo/bar/baz"), Path::new("/foo/bar").to_path_buf()),
/// Some("baz".into())
/// );
/// ```
pub fn diff_paths<P, B>(path: P, base: B) -> Option<PathBuf>
where
Expand Down Expand Up @@ -89,17 +92,20 @@ mod utf8_paths {
/// use camino::*;
/// use pathdiff::diff_utf8_paths;
///
/// let baz = "/foo/bar/baz";
/// let bar = "/foo/bar";
/// let quux = "/foo/bar/quux";
/// assert_eq!(diff_utf8_paths(bar, baz), Some("../".into()));
/// assert_eq!(diff_utf8_paths(baz, bar), Some("baz".into()));
/// assert_eq!(diff_utf8_paths(quux, baz), Some("../quux".into()));
/// assert_eq!(diff_utf8_paths(baz, quux), Some("../baz".into()));
/// assert_eq!(diff_utf8_paths(bar, quux), Some("../".into()));
/// assert_eq!(diff_utf8_paths("/foo/bar", "/foo/bar/baz"), Some("../".into()));
/// assert_eq!(diff_utf8_paths("/foo/bar/baz", "/foo/bar"), Some("baz".into()));
/// assert_eq!(diff_utf8_paths("/foo/bar/quux", "/foo/bar/baz"), Some("../quux".into()));
/// assert_eq!(diff_utf8_paths("/foo/bar/baz", "/foo/bar/quux"), Some("../baz".into()));
/// assert_eq!(diff_utf8_paths("/foo/bar", "/foo/bar/quux"), Some("../".into()));
///
/// assert_eq!(diff_utf8_paths(&baz, &bar.to_string()), Some("baz".into()));
/// assert_eq!(diff_utf8_paths(Utf8Path::new(baz), Utf8Path::new(bar).to_path_buf()), Some("baz".into()));
/// assert_eq!(
/// diff_utf8_paths(&"/foo/bar/baz", "/foo/bar".to_string()),
/// Some("baz".into())
/// );
/// assert_eq!(
/// diff_utf8_paths(Utf8Path::new("/foo/bar/baz"), Utf8Path::new("/foo/bar").to_path_buf()),
/// Some("baz".into())
/// );
/// ```
#[cfg_attr(docsrs, doc(cfg(feature = "camino")))]
pub fn diff_utf8_paths<P, B>(path: P, base: B) -> Option<Utf8PathBuf>
Expand Down

0 comments on commit 4ec30a1

Please sign in to comment.