Skip to content

Commit

Permalink
Test that NaiveWeek checked functions don't panic
Browse files Browse the repository at this point in the history
  • Loading branch information
bragov4ik committed Aug 8, 2024
1 parent e0d7ff8 commit 7904578
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/naive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,18 @@ mod test {
let date_min = NaiveDate::MIN;
assert!(date_min.week(Weekday::Mon).last_day() >= date_min);
}

#[test]
fn test_naiveweek_checked_no_panic() {
let date_max = NaiveDate::MAX;
if let Some(last) = date_max.week(Weekday::Mon).checked_last_day() {
assert!(last == date_max);

Check warning on line 273 in src/naive/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/naive/mod.rs#L273

Added line #L273 was not covered by tests
}
let date_min = NaiveDate::MIN;
if let Some(first) = date_min.week(Weekday::Mon).checked_first_day() {
assert!(first == date_min);

Check warning on line 277 in src/naive/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/naive/mod.rs#L277

Added line #L277 was not covered by tests
}
let _ = date_min.week(Weekday::Mon).checked_days();
let _ = date_max.week(Weekday::Mon).checked_days();
}
}

0 comments on commit 7904578

Please sign in to comment.