Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a72d980

Browse files
committedSep 28, 2023·
Test panic in to_rfc2822
1 parent 7b59d5d commit a72d980

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
 

‎src/datetime/tests.rs

+26
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ fn test_datetime_with_timezone() {
452452

453453
#[test]
454454
#[cfg(feature = "alloc")]
455+
#[allow(deprecated)]
455456
fn test_datetime_rfc2822() {
456457
let edt = FixedOffset::east_opt(5 * 60 * 60).unwrap();
457458

@@ -576,6 +577,31 @@ fn test_datetime_rfc2822() {
576577
assert!(DateTime::parse_from_rfc2822("Wed. 18 Feb 2015 23:16:09 +0000").is_err());
577578
// *trailing* space causes failure
578579
assert!(DateTime::parse_from_rfc2822("Wed, 18 Feb 2015 23:16:09 +0000 ").is_err());
580+
581+
const RFC_2822_YEAR_MAX: i32 = 9999;
582+
const RFC_2822_YEAR_MIN: i32 = 0;
583+
584+
let dt = Utc.with_ymd_and_hms(RFC_2822_YEAR_MAX, 1, 2, 3, 4, 5).unwrap();
585+
assert_eq!(dt.to_rfc2822(), "Sat, 2 Jan 9999 03:04:05 +0000");
586+
587+
let dt = Utc.with_ymd_and_hms(RFC_2822_YEAR_MIN, 1, 2, 3, 4, 5).unwrap();
588+
assert_eq!(dt.to_rfc2822(), "Sun, 2 Jan 0000 03:04:05 +0000");
589+
}
590+
591+
#[test]
592+
#[should_panic]
593+
#[cfg(feature = "alloc")]
594+
#[allow(deprecated)]
595+
fn test_rfc_2822_year_range_panic_high() {
596+
let _ = Utc.with_ymd_and_hms(10000, 1, 2, 3, 4, 5).unwrap().to_rfc2822();
597+
}
598+
599+
#[test]
600+
#[should_panic]
601+
#[cfg(feature = "alloc")]
602+
#[allow(deprecated)]
603+
fn test_rfc_2822_year_range_panic_low() {
604+
let _ = Utc.with_ymd_and_hms(-1, 1, 2, 3, 4, 5).unwrap().to_rfc2822();
579605
}
580606

581607
#[test]

0 commit comments

Comments
 (0)
Please sign in to comment.