Skip to content

Commit

Permalink
Test ISO 8601 parser can parse Debug output
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Sep 15, 2023
1 parent af1b19d commit 6b77095
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/datetime/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1549,3 +1549,12 @@ fn test_parse_from_iso8601() {
);
assert_eq!(parse("1985102T2350,5+01"), Ok(datetime(1985, 4, 12, 23, 50, 30, 0, 3600)));
}

#[test]
fn test_iso8601_parses_debug() {
let parse = |s| DateTime::<FixedOffset>::parse_from_iso8601(s).map(|(dt, _)| dt);

let dt = FixedOffset::east_opt(3600).unwrap().with_ymd_and_hms(12345, 6, 7, 8, 9, 10).unwrap();
let debug = format!("{:?}", dt);
assert_eq!(parse(&debug), Ok(dt));
}
9 changes: 9 additions & 0 deletions src/naive/datetime/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,3 +453,12 @@ fn test_parse_from_iso8601() {
// Test 24:00:00 wraps to the next day
assert_eq!(parse("2023-06-09T24:00:00"), Ok(datetime(2023, 6, 10, 0, 0, 0, 0)));
}

#[test]
fn test_iso8601_parses_debug() {
let parse = |s| NaiveDateTime::parse_from_iso8601(s).map(|(dt, _)| dt);

let dt = NaiveDate::from_ymd_opt(12345, 6, 7).unwrap().and_hms_nano_opt(8, 9, 10, 11).unwrap();
let debug = format!("{:?}", dt);
assert_eq!(parse(&debug), Ok(dt));
}

0 comments on commit 6b77095

Please sign in to comment.