Skip to content

Commit

Permalink
Merge pull request #349 from sylvestre/clipp2
Browse files Browse the repository at this point in the history
Run clippy pedantic fixes on the recent changes
  • Loading branch information
sylvestre authored Apr 3, 2024
2 parents 49d870d + da0de66 commit b801c97
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 24 deletions.
15 changes: 7 additions & 8 deletions src/find/matchers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ fn convert_arg_to_comparable_value_and_suffix(
/// such as: "jan 01, 2025" = "jan 01, 2025 00:00:00" -> 1735689600000
fn parse_date_str_to_timestamps(date_str: &str) -> Option<i64> {
let regex_pattern =
r#"^(?P<month_day>\w{3} \d{2})?(?:, (?P<year>\d{4}))?(?: (?P<time>\d{2}:\d{2}:\d{2}))?$"#;
r"^(?P<month_day>\w{3} \d{2})?(?:, (?P<year>\d{4}))?(?: (?P<time>\d{2}:\d{2}:\d{2}))?$";
let re = Regex::new(regex_pattern);

if let Some(captures) = re.ok()?.captures(date_str) {
Expand All @@ -283,7 +283,7 @@ fn parse_date_str_to_timestamps(date_str: &str) -> Option<i64> {
.map_or(now.year(), |m| m.as_str().parse().unwrap());
// If the user does not enter a specific time, it will be filled with 0
let time_str = captures.get(3).map_or("00:00:00", |m| m.as_str());
let date_time_str = format!("{}, {} {}", month_day, year, time_str);
let date_time_str = format!("{month_day}, {year} {time_str}");
let datetime = NaiveDateTime::parse_from_str(&date_time_str, "%b %d, %Y %H:%M:%S").ok()?;
let utc_datetime = DateTime::<Utc>::from_naive_utc_and_offset(datetime, Utc);
Some(utc_datetime.timestamp_millis())
Expand Down Expand Up @@ -1265,13 +1265,12 @@ mod tests {
let x_options = ["a", "B", "c", "m"];
let y_options = ["a", "B", "c", "m", "t"];

x_options.iter().for_each(|&x| {
y_options.iter().for_each(|&y| {
for &x in x_options.iter() {
for &y in &y_options {
let eq: (String, String) = (String::from(x), String::from(y));
let arg =
parse_str_to_newer_args(&format!("-newer{}{}", x, y).to_string()).unwrap();
let arg = parse_str_to_newer_args(&format!("-newer{x}{y}").to_string()).unwrap();
assert_eq!(eq, arg);
});
});
}
}
}
}
8 changes: 4 additions & 4 deletions src/find/matchers/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,8 +526,8 @@ mod tests {
let old_file = get_dir_entry_for("test_data", "simple");
let deps = FakeDependencies::new();
let matcher = NewerOptionMatcher::new(
x_option.to_string(),
y_option.to_string(),
(*x_option).to_string(),
(*y_option).to_string(),
&old_file.path().to_string_lossy(),
);

Expand All @@ -542,8 +542,8 @@ mod tests {
// thus causing the Matcher to generate an IO error after matching.
let _ = fs::remove_file(&*new_file.path().to_string_lossy());
let matcher = NewerOptionMatcher::new(
x_option.to_string(),
y_option.to_string(),
(*x_option).to_string(),
(*y_option).to_string(),
&old_file.path().to_string_lossy(),
);
assert!(
Expand Down
24 changes: 12 additions & 12 deletions src/find/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -869,9 +869,9 @@ mod tests {
#[cfg(not(target_os = "linux"))]
let y_options = ["a", "B", "c", "m"];

x_options.iter().for_each(|&x| {
y_options.iter().for_each(|&y| {
let arg = &format!("-newer{}{}", x, y).to_string();
for &x in x_options.iter() {
for &y in &y_options {
let arg = &format!("-newer{x}{y}").to_string();
let deps = FakeDependencies::new();
let rc = find_main(
&[
Expand All @@ -884,16 +884,16 @@ mod tests {
);

assert_eq!(rc, 0);
});
});
}
}
}

#[test]
#[cfg(target_os = "linux")]
fn test_find_newer_xy_have_not_birthed_time_filesystem() {
let y_options = ["a", "c", "m"];
y_options.iter().for_each(|&y| {
let arg = &format!("-newerB{}", y).to_string();
for &y in &y_options {
let arg = &format!("-newerB{y}").to_string();
let deps = FakeDependencies::new();
let rc = find_main(
&[
Expand All @@ -906,7 +906,7 @@ mod tests {
);

assert_eq!(rc, 1);
});
}
}

#[test]
Expand Down Expand Up @@ -960,14 +960,14 @@ mod tests {
let args = ["-newerat", "-newerBt", "-newerct", "-newermt"];
let time = "";

args.iter().for_each(|&arg| {
for &arg in &args {
let deps = FakeDependencies::new();
let rc = find_main(&["find", "./test_data/simple/subdir", arg, time], &deps);

assert_eq!(rc, 0);
// Output comparison has been temporarily removed to account for the possibility that
// migration out of the repository started before 00:00 and testing was completed after 00:00.
});
}
}

#[test]
Expand All @@ -979,11 +979,11 @@ mod tests {
let args = ["-newerat", "-newerBt", "-newerct", "-newermt"];
let time = "2037, jan 01";

args.iter().for_each(|&arg| {
for &arg in &args {
let deps = FakeDependencies::new();
let rc = find_main(&["find", "./test_data/simple/subdir", arg, time], &deps);

assert_eq!(rc, 1);
});
}
}
}

0 comments on commit b801c97

Please sign in to comment.