Skip to content

Commit 4ec30a1

Browse files
committed
Substitute variables in tests
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.
1 parent a78acde commit 4ec30a1

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

src/lib.rs

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,20 @@ use std::path::*;
1919
/// use pathdiff::diff_paths;
2020
/// use std::path::*;
2121
///
22-
/// let baz = "/foo/bar/baz";
23-
/// let bar = "/foo/bar";
24-
/// let quux = "/foo/bar/quux";
25-
/// assert_eq!(diff_paths(bar, baz), Some("../".into()));
26-
/// assert_eq!(diff_paths(baz, bar), Some("baz".into()));
27-
/// assert_eq!(diff_paths(quux, baz), Some("../quux".into()));
28-
/// assert_eq!(diff_paths(baz, quux), Some("../baz".into()));
29-
/// assert_eq!(diff_paths(bar, quux), Some("../".into()));
22+
/// assert_eq!(diff_paths("/foo/bar", "/foo/bar/baz"), Some("../".into()));
23+
/// assert_eq!(diff_paths("/foo/bar/baz", "/foo/bar"), Some("baz".into()));
24+
/// assert_eq!(diff_paths("/foo/bar/quux", "/foo/bar/baz"), Some("../quux".into()));
25+
/// assert_eq!(diff_paths("/foo/bar/baz", "/foo/bar/quux"), Some("../baz".into()));
26+
/// assert_eq!(diff_paths("/foo/bar", "/foo/bar/quux"), Some("../".into()));
3027
///
31-
/// assert_eq!(diff_paths(&baz, &bar.to_string()), Some("baz".into()));
32-
/// assert_eq!(diff_paths(Path::new(baz), Path::new(bar).to_path_buf()), Some("baz".into()));
28+
/// assert_eq!(
29+
/// diff_paths(&"/foo/bar/baz", "/foo/bar".to_string()),
30+
/// Some("baz".into())
31+
/// );
32+
/// assert_eq!(
33+
/// diff_paths(Path::new("/foo/bar/baz"), Path::new("/foo/bar").to_path_buf()),
34+
/// Some("baz".into())
35+
/// );
3336
/// ```
3437
pub fn diff_paths<P, B>(path: P, base: B) -> Option<PathBuf>
3538
where
@@ -89,17 +92,20 @@ mod utf8_paths {
8992
/// use camino::*;
9093
/// use pathdiff::diff_utf8_paths;
9194
///
92-
/// let baz = "/foo/bar/baz";
93-
/// let bar = "/foo/bar";
94-
/// let quux = "/foo/bar/quux";
95-
/// assert_eq!(diff_utf8_paths(bar, baz), Some("../".into()));
96-
/// assert_eq!(diff_utf8_paths(baz, bar), Some("baz".into()));
97-
/// assert_eq!(diff_utf8_paths(quux, baz), Some("../quux".into()));
98-
/// assert_eq!(diff_utf8_paths(baz, quux), Some("../baz".into()));
99-
/// assert_eq!(diff_utf8_paths(bar, quux), Some("../".into()));
95+
/// assert_eq!(diff_utf8_paths("/foo/bar", "/foo/bar/baz"), Some("../".into()));
96+
/// assert_eq!(diff_utf8_paths("/foo/bar/baz", "/foo/bar"), Some("baz".into()));
97+
/// assert_eq!(diff_utf8_paths("/foo/bar/quux", "/foo/bar/baz"), Some("../quux".into()));
98+
/// assert_eq!(diff_utf8_paths("/foo/bar/baz", "/foo/bar/quux"), Some("../baz".into()));
99+
/// assert_eq!(diff_utf8_paths("/foo/bar", "/foo/bar/quux"), Some("../".into()));
100100
///
101-
/// assert_eq!(diff_utf8_paths(&baz, &bar.to_string()), Some("baz".into()));
102-
/// assert_eq!(diff_utf8_paths(Utf8Path::new(baz), Utf8Path::new(bar).to_path_buf()), Some("baz".into()));
101+
/// assert_eq!(
102+
/// diff_utf8_paths(&"/foo/bar/baz", "/foo/bar".to_string()),
103+
/// Some("baz".into())
104+
/// );
105+
/// assert_eq!(
106+
/// diff_utf8_paths(Utf8Path::new("/foo/bar/baz"), Utf8Path::new("/foo/bar").to_path_buf()),
107+
/// Some("baz".into())
108+
/// );
103109
/// ```
104110
#[cfg_attr(docsrs, doc(cfg(feature = "camino")))]
105111
pub fn diff_utf8_paths<P, B>(path: P, base: B) -> Option<Utf8PathBuf>

0 commit comments

Comments
 (0)