test(primitive): cover comments and ignored signs between items

This commit is contained in:
Anas Awadalla authored and Sylvestre Ledru committed 2026-10-03 13:17:40 -04:00
1 parent 59336d8db1
commit c6bfe2d15a
2 files changed
+47

No files matched your search

+24
View File
@@ -779,6 +779,30 @@ mod tests {
}
}
#[test]
fn comments_and_ignored_signs() {
let base = "2000-06-15 12:34:56"
.parse::<DateTime>()
.unwrap()
.to_zoned(TimeZone::UTC)
.unwrap();
for (input, expected) in [
("1997-01-01 (foo) 10:00", "1997-01-01 10:00:00+00:00"),
("1997-01-01 (a (b)) 10:00", "1997-01-01 10:00:00+00:00"),
("(foo) 1997-01-01", "1997-01-01 00:00:00+00:00"),
("+ (c) 1997-01-01", "1997-01-01 00:00:00+00:00"),
("- (c) 1997-01-01", "1997-01-01 00:00:00+00:00"),
("1997-01-01 (x) + 1 day", "1997-01-02 00:00:00+00:00"),
] {
let result = parse_at_date(base.clone(), input).unwrap();
assert_eq!(result.to_string(), expected, "{input}");
}
// Like GNU, a hyphen followed by a digit is a sign, not ignored.
assert!(parse_at_date(base.clone(), "- 1997-01-01").is_err());
}
#[test]
fn pure() {
let now = Zoned::now().with_time_zone(TimeZone::UTC);
+23
View File
@@ -230,4 +230,27 @@ mod tests {
);
}
}
#[test]
fn space_skips_comments_and_ignored_signs() {
for (input, rest) in [
("", ""),
("abc", "abc"),
(" \t abc", "abc"),
("(foo) abc", "abc"),
(" (a (b)) abc", "abc"),
("- abc", "abc"),
("+ (c) abc", "abc"),
("- (c) 12", "12"),
// A sign followed by a digit is not ignored.
("- 12", "- 12"),
(" +12", "+12"),
// An unbalanced comment is not skipped.
("(foo abc", "(foo abc"),
] {
let mut s = input;
space::<ContextError>(&mut s).unwrap();
assert_eq!(s, rest, "{input:?}");
}
}
}