Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: add contents_first with min & max depth #164

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 123 additions & 8 deletions src/tests/recursive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ fn min_depth_1() {
r.assert_no_errors();

let expected = vec![dir.join("a"), dir.join("a").join("b")];
assert_eq!(expected, r.sorted_paths());
assert_eq!(expected, r.paths());
}

#[test]
Expand All @@ -735,7 +735,7 @@ fn min_depth_2() {
r.assert_no_errors();

let expected = vec![dir.join("a").join("b")];
assert_eq!(expected, r.sorted_paths());
assert_eq!(expected, r.paths());
}

#[test]
Expand All @@ -748,7 +748,7 @@ fn max_depth_0() {
r.assert_no_errors();

let expected = vec![dir.path().to_path_buf()];
assert_eq!(expected, r.sorted_paths());
assert_eq!(expected, r.paths());
}

#[test]
Expand All @@ -761,7 +761,7 @@ fn max_depth_1() {
r.assert_no_errors();

let expected = vec![dir.path().to_path_buf(), dir.join("a")];
assert_eq!(expected, r.sorted_paths());
assert_eq!(expected, r.paths());
}

#[test]
Expand All @@ -775,7 +775,7 @@ fn max_depth_2() {

let expected =
vec![dir.path().to_path_buf(), dir.join("a"), dir.join("a").join("b")];
assert_eq!(expected, r.sorted_paths());
assert_eq!(expected, r.paths());
}

// FIXME: This test seems wrong. It should return nothing!
Expand All @@ -789,7 +789,7 @@ fn min_max_depth_diff_nada() {
r.assert_no_errors();

let expected = vec![dir.join("a").join("b").join("c")];
assert_eq!(expected, r.sorted_paths());
assert_eq!(expected, r.paths());
}

#[test]
Expand All @@ -802,7 +802,7 @@ fn min_max_depth_diff_0() {
r.assert_no_errors();

let expected = vec![dir.join("a").join("b")];
assert_eq!(expected, r.sorted_paths());
assert_eq!(expected, r.paths());
}

#[test]
Expand All @@ -815,7 +815,122 @@ fn min_max_depth_diff_1() {
r.assert_no_errors();

let expected = vec![dir.join("a"), dir.join("a").join("b")];
assert_eq!(expected, r.sorted_paths());
assert_eq!(expected, r.paths());
}

#[test]
fn contents_first_min_depth_1() {
let dir = Dir::tmp();
dir.mkdirp("a/b");

let wd = WalkDir::new(dir.path()).contents_first(true).min_depth(1);
let r = dir.run_recursive(wd);
r.assert_no_errors();

let expected = vec![dir.join("a").join("b"), dir.join("a")];
assert_eq!(expected, r.paths());
}

#[test]
fn contents_first_min_depth_2() {
let dir = Dir::tmp();
dir.mkdirp("a/b");

let wd = WalkDir::new(dir.path()).contents_first(true).min_depth(2);
let r = dir.run_recursive(wd);
r.assert_no_errors();

let expected = vec![dir.join("a").join("b")];
assert_eq!(expected, r.paths());
}

#[test]
fn contents_first_max_depth_0() {
let dir = Dir::tmp();
dir.mkdirp("a/b");

let wd = WalkDir::new(dir.path()).contents_first(true).max_depth(0);
let r = dir.run_recursive(wd);
r.assert_no_errors();

let expected = vec![dir.path().to_path_buf()];
assert_eq!(expected, r.paths());
}

#[test]
fn contents_first_max_depth_1() {
let dir = Dir::tmp();
dir.mkdirp("a/b");

let wd = WalkDir::new(dir.path()).contents_first(true).max_depth(1);
let r = dir.run_recursive(wd);
r.assert_no_errors();

let expected = vec![dir.join("a"), dir.path().to_path_buf()];
assert_eq!(expected, r.paths());
}

#[test]
fn contents_first_max_depth_2() {
let dir = Dir::tmp();
dir.mkdirp("a/b");

let wd = WalkDir::new(dir.path()).contents_first(true).max_depth(2);
let r = dir.run_recursive(wd);
r.assert_no_errors();

let expected =
vec![dir.join("a").join("b"), dir.join("a"), dir.path().to_path_buf()];
assert_eq!(expected, r.paths());
}

// FIXME: This test seems wrong. It should return nothing!
#[test]
fn contents_first_min_max_depth_diff_nada() {
let dir = Dir::tmp();
dir.mkdirp("a/b/c");

let wd = WalkDir::new(dir.path())
.contents_first(true)
.min_depth(3)
.max_depth(2);
let r = dir.run_recursive(wd);
r.assert_no_errors();

let expected = vec![dir.join("a").join("b").join("c")];
assert_eq!(expected, r.paths());
}

#[test]
fn contents_first_min_max_depth_diff_0() {
let dir = Dir::tmp();
dir.mkdirp("a/b/c");

let wd = WalkDir::new(dir.path())
.contents_first(true)
.min_depth(2)
.max_depth(2);
let r = dir.run_recursive(wd);
r.assert_no_errors();

let expected = vec![dir.join("a").join("b")];
assert_eq!(expected, r.paths());
}

#[test]
fn contents_first_min_max_depth_diff_1() {
let dir = Dir::tmp();
dir.mkdirp("a/b/c");

let wd = WalkDir::new(dir.path())
.contents_first(true)
.min_depth(1)
.max_depth(2);
let r = dir.run_recursive(wd);
r.assert_no_errors();

let expected = vec![dir.join("a").join("b"), dir.join("a")];
assert_eq!(expected, r.paths());
}

#[test]
Expand Down