From 7a111f689171ebea9edf84cf7a928dceb9037451 Mon Sep 17 00:00:00 2001 From: "chenyee.cy.huang" Date: Sat, 11 Jan 2025 21:23:04 +0800 Subject: [PATCH] add more testcases --- src/format/parse.rs | 4 ++++ src/naive/datetime/tests.rs | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/format/parse.rs b/src/format/parse.rs index be088fa75e..b882b16b14 100644 --- a/src/format/parse.rs +++ b/src/format/parse.rs @@ -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)); @@ -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)); diff --git a/src/naive/datetime/tests.rs b/src/naive/datetime/tests.rs index 161245813d..d48bb22158 100644 --- a/src/naive/datetime/tests.rs +++ b/src/naive/datetime/tests.rs @@ -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)) @@ -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]