mirror of
https://github.com/chronotope/chrono.git
synced 2025-10-02 15:26:12 +00:00
Fixed incorrect whitespace parsing; added more tests
This commit is contained in:
parent
b2430c2b77
commit
5eacc0a698
@ -832,6 +832,11 @@ fn test_rfc2822() {
|
||||
Ok("Tue, 20 Jan 2015 17:35:20 -0800"),
|
||||
), // complex trailing comment
|
||||
(r"Tue, 20 Jan 2015 17:35:20 -0800 (UTC\)", Err(TOO_LONG)), // incorrect comment, not enough closing parentheses
|
||||
(
|
||||
"Tue, 20 Jan 2015 17:35:20 -0800 (UTC)\t \r\n(Anothercomment)",
|
||||
Ok("Tue, 20 Jan 2015 17:35:20 -0800"),
|
||||
), // multiple comments
|
||||
("Tue, 20 Jan 2015 17:35:20 -0800 (UTC) ", Err(TOO_LONG)), // trailing whitespace after comment
|
||||
("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
|
||||
|
@ -355,10 +355,11 @@ pub(super) fn timezone_name_skip(s: &str) -> ParseResult<(&str, ())> {
|
||||
pub(super) fn comment_2822(s: &str) -> ParseResult<(&str, ())> {
|
||||
use CommentState::*;
|
||||
|
||||
let s = s.trim_start();
|
||||
|
||||
let mut state = Start;
|
||||
for (i, c) in s.bytes().enumerate() {
|
||||
state = match (state, c) {
|
||||
(Start, b' ') => Start,
|
||||
(Start, b'(') => Next(1),
|
||||
(Next(1), b')') => return Ok((&s[i + 1..], ())),
|
||||
(Next(depth), b'\\') => Escape(depth),
|
||||
@ -383,9 +384,12 @@ enum CommentState {
|
||||
fn test_rfc2822_comments() {
|
||||
let testdata = [
|
||||
("", Err(TOO_SHORT)),
|
||||
(" ", Err(TOO_SHORT)),
|
||||
("x", Err(INVALID)),
|
||||
("(", Err(TOO_SHORT)),
|
||||
("()", Ok("")),
|
||||
(" \r\n\t()", Ok("")),
|
||||
("() ", Ok(" ")),
|
||||
("()z", Ok("z")),
|
||||
("(x)", Ok("")),
|
||||
("(())", Ok("")),
|
||||
@ -402,6 +406,10 @@ fn test_rfc2822_comments() {
|
||||
|
||||
for (test_in, expected) in testdata {
|
||||
let actual = comment_2822(test_in).map(|(s, _)| s);
|
||||
assert_eq!(expected, actual);
|
||||
assert_eq!(
|
||||
expected, actual,
|
||||
"{:?} expected to produce {:?}, but produced {:?}.",
|
||||
test_in, expected, actual
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user