Skip to content

Commit

Permalink
Test panic in to_rfc2822
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Sep 28, 2023
1 parent 7623426 commit 99444ed
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/datetime/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ fn test_datetime_with_timezone() {

#[test]
#[cfg(feature = "alloc")]
#[allow(deprecated)]
fn test_datetime_rfc2822() {
let edt = FixedOffset::east_opt(5 * 60 * 60).unwrap();

Expand Down Expand Up @@ -576,6 +577,31 @@ fn test_datetime_rfc2822() {
assert!(DateTime::parse_from_rfc2822("Wed. 18 Feb 2015 23:16:09 +0000").is_err());
// *trailing* space causes failure
assert!(DateTime::parse_from_rfc2822("Wed, 18 Feb 2015 23:16:09 +0000 ").is_err());

const RFC_2822_YEAR_MAX: i32 = 9999;
const RFC_2822_YEAR_MIN: i32 = 0;

let dt = Utc.with_ymd_and_hms(RFC_2822_YEAR_MAX, 1, 2, 3, 4, 5).unwrap();
assert_eq!(dt.to_rfc2822(), "Sat, 2 Jan 9999 03:04:05 +0000");

let dt = Utc.with_ymd_and_hms(RFC_2822_YEAR_MIN, 1, 2, 3, 4, 5).unwrap();
assert_eq!(dt.to_rfc2822(), "Sun, 2 Jan 0000 03:04:05 +0000");
}

#[test]
#[should_panic]
#[cfg(feature = "alloc")]
#[allow(deprecated)]
fn test_rfc_2822_year_range_panic_high() {
let _ = Utc.with_ymd_and_hms(10000, 1, 2, 3, 4, 5).unwrap().to_rfc2822();
}

#[test]
#[should_panic]
#[cfg(feature = "alloc")]
#[allow(deprecated)]
fn test_rfc_2822_year_range_panic_low() {
let _ = Utc.with_ymd_and_hms(-1, 1, 2, 3, 4, 5).unwrap().to_rfc2822();
}

#[test]
Expand Down

0 comments on commit 99444ed

Please sign in to comment.