Skip to content

Commit

Permalink
tests .to_rfc2822 panics
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielfalcao committed Dec 5, 2024
1 parent 65c47f3 commit 5e3bb0b
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/datetime/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1901,3 +1901,47 @@ fn nano_roundrip() {
assert_eq!(nanos, nanos2);
}
}

#[cfg(feature = "alloc")]
#[test]
fn try_to_rfc2822() {
let ndt = NaiveDateTime::new(
NaiveDate::from_ymd_opt(9999, 12, 31).unwrap(),
NaiveTime::from_hms_nano_opt(
60,
60,
60,
999999999,
)
.or(NaiveTime::from_hms_opt(
60,
60,
60,
))
.unwrap_or_default(),
).and_utc();
let res = ndt.to_rfc2822();
assert_eq!(res, "Fri, 31 Dec 9999 00:00:00 +0000");
}


#[cfg(feature = "alloc")]
#[should_panic]
#[test]
fn try_to_rfc2822_panics_year_greater_than_9999() {
NaiveDateTime::new(
NaiveDate::from_ymd_opt(10000, 12, 31).unwrap(),
NaiveTime::from_hms_nano_opt(
60,
60,
60,
999999999,
)
.or(NaiveTime::from_hms_opt(
60,
60,
60,
))
.unwrap_or_default(),
).and_utc().to_rfc2822();
}

0 comments on commit 5e3bb0b

Please sign in to comment.