diff options
author | Marvin Löbel <loebel.marvin@gmail.com> | 2021-03-02 14:09:23 +0300 |
---|---|---|
committer | Andrew Gallant <jamslam@gmail.com> | 2021-03-22 17:30:20 +0300 |
commit | 461f4a8708eed4ea6cf14ac6f775a197ec61eee8 (patch) | |
tree | e73335cb79e6e546f845af025ae6cbf96331a14d /src/tests/recursive.rs | |
parent | 3d1f2f252a9e57f6950fcd2856d1127ded47dd1a (diff) |
api: add convenience sort routines
This commit adds sort_by_key and sort_by_file_name convenience routines
for common sorting needs. The signature for sort_by_key in particular
mirrors the eponymous method on slices in the standard library.
Closes #147
Diffstat (limited to 'src/tests/recursive.rs')
-rw-r--r-- | src/tests/recursive.rs | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/src/tests/recursive.rs b/src/tests/recursive.rs index bbb1ce1..4119f46 100644 --- a/src/tests/recursive.rs +++ b/src/tests/recursive.rs @@ -879,7 +879,7 @@ fn filter_entry() { } #[test] -fn sort() { +fn sort_by() { let dir = Dir::tmp(); dir.mkdirp("foo/bar/baz/abc"); dir.mkdirp("quux"); @@ -901,6 +901,49 @@ fn sort() { } #[test] +fn sort_by_key() { + let dir = Dir::tmp(); + dir.mkdirp("foo/bar/baz/abc"); + dir.mkdirp("quux"); + + let wd = + WalkDir::new(dir.path()).sort_by_key(|a| a.file_name().to_owned()); + let r = dir.run_recursive(wd); + r.assert_no_errors(); + + let expected = vec![ + dir.path().to_path_buf(), + dir.join("foo"), + dir.join("foo").join("bar"), + dir.join("foo").join("bar").join("baz"), + dir.join("foo").join("bar").join("baz").join("abc"), + dir.join("quux"), + ]; + assert_eq!(expected, r.paths()); +} + +#[test] +fn sort_by_file_name() { + let dir = Dir::tmp(); + dir.mkdirp("foo/bar/baz/abc"); + dir.mkdirp("quux"); + + let wd = WalkDir::new(dir.path()).sort_by_file_name(); + let r = dir.run_recursive(wd); + r.assert_no_errors(); + + let expected = vec![ + dir.path().to_path_buf(), + dir.join("foo"), + dir.join("foo").join("bar"), + dir.join("foo").join("bar").join("baz"), + dir.join("foo").join("bar").join("baz").join("abc"), + dir.join("quux"), + ]; + assert_eq!(expected, r.paths()); +} + +#[test] fn sort_max_open() { let dir = Dir::tmp(); dir.mkdirp("foo/bar/baz/abc"); |