Skip to content

Commit

Permalink
test: refactor some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nokazn committed Feb 10, 2024
1 parent 6709e92 commit 73176b7
Showing 1 changed file with 41 additions and 33 deletions.
74 changes: 41 additions & 33 deletions src/utils/glob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ mod tests {
use tempfile::TempDir;

struct CollectTestCase {
input: (Vec<String>, bool),
input: (Vec<&'static str>, bool),
file_system: Vec<PathBuf>,
expected: Vec<PathBuf>,
}
Expand All @@ -117,7 +117,15 @@ mod tests {
assert_eq!(
collect(
&tmp_dir.as_ref().to_path_buf(),
Some(case.input.clone().0),
Some(
case
.input
.clone()
.0
.iter()
.map(|s| s.to_string())
.collect::<Vec<_>>()
),
case.input.1
),
case
Expand All @@ -132,61 +140,61 @@ mod tests {
test_each! {
test_collect,
0 => &CollectTestCase {
input: (vec!["foo".to_string()], true),
input: (vec!["foo"], true),
file_system: vec![PathBuf::from("./foo")],
expected: vec![PathBuf::from("./foo")],
},
1 => &CollectTestCase {
input: (vec!["bar".to_string()], true),
input: (vec!["bar"], true),
file_system: vec![PathBuf::from("./foo")],
expected: vec![],
},
2 => &CollectTestCase {
input: (vec!["f*".to_string()], true),
input: (vec!["f*"], true),
file_system: vec![PathBuf::from("./foo")],
expected: vec![PathBuf::from("./foo")],
},
3 => &CollectTestCase {
input: (vec!["*fo*".to_string()], true),
input: (vec!["*fo*"], true),
file_system: vec![PathBuf::from("./foo")],
expected: vec![PathBuf::from("./foo")],
},
4 => &CollectTestCase {
input: (vec!["**/foo".to_string()], true),
input: (vec!["**/foo"], true),
file_system: vec![PathBuf::from("./foo")],
expected: vec![PathBuf::from("./foo")],
},
5 => &CollectTestCase {
input: (vec!["**/baz".to_string()], true),
input: (vec!["**/baz"], true),
file_system: vec![PathBuf::from("./foo/bar/baz/qux")],
expected: vec![PathBuf::from("./foo/bar/baz/")],
},
6 => &CollectTestCase {
input: (vec!["**/bar".to_string()], true),
input: (vec!["**/bar"], true),
file_system: vec![PathBuf::from("./foo/bar")],
expected: vec![PathBuf::from("./foo/bar")],
},
7 => &CollectTestCase {
input: (vec!["foo".to_string(), "!foo".to_string()], true),
input: (vec!["foo", "!foo"], true),
file_system: vec![PathBuf::from("./foo/bar")],
expected: vec![],
},
8 => &CollectTestCase {
input: (vec!["!foo".to_string(), "foo".to_string()], true),
input: (vec!["!foo", "foo"], true),
file_system: vec![PathBuf::from("./foo/bar")],
expected: vec![PathBuf::from("./foo/")],
},
9 => &CollectTestCase {
input: (
vec!["foo".to_string(), "!foo".to_string(), "bar".to_string()],
vec!["foo", "!foo", "bar"],
true,
),
file_system: vec![PathBuf::from("./foo"), PathBuf::from("./bar")],
expected: vec![PathBuf::from("./bar")],
},
10 => &CollectTestCase {
input: (
vec!["!foo".to_string(), "foo".to_string(), "bar".to_string()],
vec!["!foo", "foo", "bar"],
true,
),
file_system: vec![PathBuf::from("./foo"), PathBuf::from("./bar")],
Expand All @@ -195,10 +203,10 @@ mod tests {
11 => &CollectTestCase {
input: (
vec![
"foo".to_string(),
"!foo".to_string(),
"bar".to_string(),
"!bar".to_string(),
"foo",
"!foo",
"bar",
"!bar",
],
true,
),
Expand All @@ -208,44 +216,44 @@ mod tests {
}

struct ParseNegateTestCase {
input: (String, bool),
expected: (String, bool),
input: (&'static str, bool),
expected: (&'static str, bool),
}

fn test_parse_negate_each(case: &ParseNegateTestCase) {
use super::*;

assert_eq!(
parse_negate(case.input.0.clone(), case.input.1),
case.expected
parse_negate(case.input.0.to_string(), case.input.1),
(case.expected.0.to_string(), case.expected.1)
);
}

test_each!(
test_parse_negate,
0 => &ParseNegateTestCase {
input: (String::from("foo"), true),
expected: (String::from("foo"), false),
input: ("foo", true),
expected: ("foo", false),
},
1 => &ParseNegateTestCase {
input: (String::from("!foo"), true),
expected: (String::from("foo"), true),
input: ("!foo", true),
expected: ("foo", true),
},
2 => &ParseNegateTestCase {
input: (String::from("!!foo"), true),
expected: (String::from("foo"), false),
input: ("!!foo", true),
expected: ("foo", false),
},
3 => &ParseNegateTestCase {
input: (String::from("!!!foo"), true),
expected: (String::from("foo"), true),
input: ("!!!foo", true),
expected: ("foo", true),
},
4 => &ParseNegateTestCase {
input: (String::from("foo!bar"), true),
expected: (String::from("foo!bar"), false),
input: ("foo!bar", true),
expected: ("foo!bar", false),
},
5 => &ParseNegateTestCase {
input: (String::from("foo!!!!!!!!!!bar"), true),
expected: (String::from("foo!!!!!!!!!!bar"), false),
input: ("foo!!!!!!!!!!bar", true),
expected: ("foo!!!!!!!!!!bar", false),
},
);
}

0 comments on commit 73176b7

Please sign in to comment.