From 790457834587b390140bdb6dc61704b2f47410f9 Mon Sep 17 00:00:00 2001 From: Kirill Ivanov Date: Mon, 22 Jul 2024 20:15:02 +0200 Subject: [PATCH] Test that `NaiveWeek` checked functions don't panic --- src/naive/mod.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/naive/mod.rs b/src/naive/mod.rs index 82be3da2e..ebd9ae5d2 100644 --- a/src/naive/mod.rs +++ b/src/naive/mod.rs @@ -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); + } + let date_min = NaiveDate::MIN; + if let Some(first) = date_min.week(Weekday::Mon).checked_first_day() { + assert!(first == date_min); + } + let _ = date_min.week(Weekday::Mon).checked_days(); + let _ = date_max.week(Weekday::Mon).checked_days(); + } }