mirror of
https://github.com/uutils/parse_datetime.git
synced 2026-10-16 03:25:04 -07:00
test(primitive): cover comments and ignored signs between items
This commit is contained in:
1 parent
59336d8db1
commit
c6bfe2d15a
2 files changed
+47
No files matched your search
@@ -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);
|
||||
|
||||
@@ -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:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user