Skip to content

Commit

Permalink
add more testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
titaneric committed Jan 11, 2025
1 parent ea723d6 commit 7a111f6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/format/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,7 @@ mod tests {
&[num(Year), Space(" "), Literal("x"), Space(" "), Literal("1235")],
parsed!(year: 1234),
);
check("12341235", &[num(Year), Literal("1235")], parsed!(year: 1234));

// signed numeric
check("-42", &[num(Year)], parsed!(year: -42));
Expand All @@ -806,9 +807,12 @@ mod tests {
check(" -42195", &[num(Year)], parsed!(year: -42195));
check(" +42195", &[num(Year)], parsed!(year: 42195));
check(" -42195", &[num(Year)], parsed!(year: -42195));
check(" -42195123", &[num(Year), Literal("123")], parsed!(year: -42195));
check(" +42195", &[num(Year)], parsed!(year: 42195));
check(" +42195123", &[num(Year), Literal("123")], parsed!(year: 42195));
check("-42195 ", &[num(Year)], Err(TOO_LONG));
check("+42195 ", &[num(Year)], Err(TOO_LONG));
check("+42195123 ", &[num(Year), Literal("123")], Err(TOO_LONG));
check(" - 42", &[num(Year)], Err(INVALID));
check(" + 42", &[num(Year)], Err(INVALID));
check(" -42195", &[Space(" "), num(Year)], parsed!(year: -42195));
Expand Down
16 changes: 16 additions & 0 deletions src/naive/datetime/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ fn test_datetime_parse_from_str() {
NaiveDateTime::parse_from_str("2014-5-7T12:34:56+09:30", "%Y-%m-%dT%H:%M:%S%z"),
Ok(ymdhms(2014, 5, 7, 12, 34, 56))
); // ignore offset
assert_eq!(
NaiveDateTime::parse_from_str("2014123-5-7T12:34:56+09:30", "%Y123-%m-%dT%H:%M:%S%z"),
Ok(ymdhms(2014, 5, 7, 12, 34, 56))
); // ignore offset
assert_eq!(
NaiveDateTime::parse_from_str("2015-W06-1 000000", "%G-W%V-%u%H%M%S"),
Ok(ymdhms(2015, 2, 2, 0, 0, 0))
Expand Down Expand Up @@ -218,14 +222,26 @@ fn test_datetime_parse_from_str() {
NaiveDateTime::parse_from_str("1441497364.649", "%s%.3f"),
Ok(ymdhmsn(2015, 9, 5, 23, 56, 4, 649000000))
);
assert_eq!(
NaiveDateTime::parse_from_str("1441497364649", "%s%3f"),
Ok(ymdhmsn(2015, 9, 5, 23, 56, 4, 649000000))
);
assert_eq!(
NaiveDateTime::parse_from_str("1497854303.087654", "%s%.6f"),
Ok(ymdhmsn(2017, 6, 19, 6, 38, 23, 87654000))
);
assert_eq!(
NaiveDateTime::parse_from_str("1497854303087654", "%s%6f"),
Ok(ymdhmsn(2017, 6, 19, 6, 38, 23, 87654000))
);
assert_eq!(
NaiveDateTime::parse_from_str("1437742189.918273645", "%s%.9f"),
Ok(ymdhmsn(2015, 7, 24, 12, 49, 49, 918273645))
);
assert_eq!(
NaiveDateTime::parse_from_str("1437742189918273645", "%s%9f"),
Ok(ymdhmsn(2015, 7, 24, 12, 49, 49, 918273645))
);
}

#[test]
Expand Down

0 comments on commit 7a111f6

Please sign in to comment.