Skip to content

Commit

Permalink
more tests for HYPHEN-MINUS (U+2D) and MINUS SIGN (U+2212)
Browse files Browse the repository at this point in the history
Extra tests not strictly necessary for prior commit introducing
MINUS SIGN parsing.

Issue #835
  • Loading branch information
jtmoon79 committed Mar 28, 2023
1 parent 11fee1f commit 429e7a7
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/format/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,9 @@ fn test_parse() {
check!("", [lit!("a")]; TOO_SHORT);
check!(" ", [lit!("a")]; INVALID);
check!("a", [lit!("a")]; );
check!("+", [lit!("+")]; );
check!("-", [lit!("-")]; );
check!("−", [lit!("−")]; );
// a Literal may contain whitespace and match whitespace, but this should not be done
check!(" ", [lit!(" ")]; );
check!("aa", [lit!("a")]; TOO_LONG);
Expand All @@ -650,6 +653,8 @@ fn test_parse() {
check!("1", [lit!("1")]; );
check!("1234", [lit!("1234")]; );
check!("+1234", [lit!("+1234")]; );
check!("-1234", [lit!("-1234")]; );
check!("−1234", [lit!("−1234")]; );
check!("PST", [lit!("PST")]; );
check!("🤠", [lit!("🤠")]; );
check!("🤠a", [lit!("🤠"), lit!("a")]; );
Expand Down Expand Up @@ -716,6 +721,7 @@ fn test_parse() {
check!("-0042", [num!(Year)]; year: -42);
check!("+0042", [num!(Year)]; year: 42);
check!("-42195", [num!(Year)]; year: -42195);
check!("−42195", [num!(Year)]; INVALID);
check!("+42195", [num!(Year)]; year: 42195);
check!(" -42195", [num!(Year)]; INVALID);
check!(" +42195", [num!(Year)]; INVALID);
Expand All @@ -726,6 +732,7 @@ fn test_parse() {
check!(" - 42", [num!(Year)]; INVALID);
check!(" + 42", [num!(Year)]; INVALID);
check!(" -42195", [sp!(" "), num!(Year)]; year: -42195);
check!(" −42195", [sp!(" "), num!(Year)]; INVALID);
check!(" +42195", [sp!(" "), num!(Year)]; year: 42195);
check!(" - 42", [sp!(" "), num!(Year)]; INVALID);
check!(" + 42", [sp!(" "), num!(Year)]; INVALID);
Expand All @@ -736,6 +743,7 @@ fn test_parse() {
check!("345", [num!(Ordinal)]; ordinal: 345);
check!("+345", [num!(Ordinal)]; INVALID);
check!("-345", [num!(Ordinal)]; INVALID);
check!("−345", [num!(Ordinal)]; INVALID);
check!(" 345", [num!(Ordinal)]; INVALID);
check!("345 ", [num!(Ordinal)]; TOO_LONG);
check!(" 345", [sp!(" "), num!(Ordinal)]; ordinal: 345);
Expand Down Expand Up @@ -1396,7 +1404,9 @@ fn test_rfc2822() {
("20 Jan 2015 17:35:20 -0800", Ok("Tue, 20 Jan 2015 17:35:20 -0800")), // no day of week
("20 JAN 2015 17:35:20 -0800", Ok("Tue, 20 Jan 2015 17:35:20 -0800")), // upper case month
("Tue, 20 Jan 2015 17:35 -0800", Ok("Tue, 20 Jan 2015 17:35:00 -0800")), // no second
("11 Sep 2001 09:45:00 +0000", Ok("Tue, 11 Sep 2001 09:45:00 +0000")),
("11 Sep 2001 09:45:00 EST", Ok("Tue, 11 Sep 2001 09:45:00 -0500")),
("11 Sep 2001 09:45:00 GMT", Ok("Tue, 11 Sep 2001 09:45:00 +0000")),
("30 Feb 2015 17:35:20 -0800", Err(OUT_OF_RANGE)), // bad day of month
("Tue, 20 Jan 2015", Err(TOO_SHORT)), // omitted fields
("Tue, 20 Avr 2015 17:35:20 -0800", Err(INVALID)), // bad month name
Expand Down Expand Up @@ -1484,6 +1494,25 @@ fn parse_rfc850() {
for val in &testdates {
assert_eq!(Ok(val.0), Utc.datetime_from_str(val.1, RFC850_FMT));
}

let testdates_fail = [
"Saturday, 12-Nov-94 08:49:37",
"Saturday, 12-Nov-94 08:49:37 Z",
"Saturday, 12-Nov-94 08:49:37 GMTTTT",
"Saturday, 12-Nov-94 08:49:37 gmt",
"Saturday, 12-Nov-94 08:49:37 +08:00",
"Caturday, 12-Nov-94 08:49:37 GMT",
"Saturday, 99-Nov-94 08:49:37 GMT",
"Saturday, 12-Nov-2000 08:49:37 GMT",
"Saturday, 12-Mop-94 08:49:37 GMT",
"Saturday, 12-Nov-94 28:49:37 GMT",
"Saturday, 12-Nov-94 08:99:37 GMT",
"Saturday, 12-Nov-94 08:49:99 GMT",
];

for val in &testdates_fail {
assert!(Utc.datetime_from_str(val, RFC850_FMT).is_err());
}
}

#[cfg(test)]
Expand All @@ -1509,6 +1538,8 @@ fn test_rfc3339() {
("2015-01-20 17:35:20.001-08:00", Err(INVALID)), // missing separator 'T'
("2015/01/20T17:35:20.001-08:00", Err(INVALID)), // wrong separator char YMD
("2015-01-20T17-35-20.001-08:00", Err(INVALID)), // wrong separator char HMS
("-01-20T17:35:20-08:00", Err(INVALID)), // missing year
("99-01-20T17:35:20-08:00", Err(INVALID)), // bad year format
("99999-01-20T17:35:20-08:00", Err(INVALID)), // bad year value
("-2000-01-20T17:35:20-08:00", Err(INVALID)), // bad year value
("2015-02-30T17:35:20-08:00", Err(OUT_OF_RANGE)), // bad day of month value
Expand Down

0 comments on commit 429e7a7

Please sign in to comment.