#532 Improve date format validation to include all supported cases | Formatting, test added

This commit is contained in:
Arkadiusz Bielewicz 2021-10-13 11:35:58 +02:00 committed by Abin Simon
parent 83a25867d0
commit 1363945fd8
2 changed files with 19 additions and 3 deletions

View file

@ -308,17 +308,17 @@ pub fn validate_time_format(formatter: &str) -> Result<(), String> {
Some('f') => (), Some('f') => (),
Some(c) => return Err(format!("invalid format specifier: %{}{}", n, c)), Some(c) => return Err(format!("invalid format specifier: %{}{}", n, c)),
None => return Err("missing format specifier".to_owned()), None => return Err("missing format specifier".to_owned()),
} },
Some('.') => match chars.next() { Some('.') => match chars.next() {
Some('f') => (), Some('f') => (),
Some(n @ '3') | Some(n @ '6') | Some(n @ '9') => match chars.next() { Some(n @ '3') | Some(n @ '6') | Some(n @ '9') => match chars.next() {
Some('f') => (), Some('f') => (),
Some(c) => return Err(format!("invalid format specifier: %.{}{}", n, c)), Some(c) => return Err(format!("invalid format specifier: %.{}{}", n, c)),
None => return Err("missing format specifier".to_owned()), None => return Err("missing format specifier".to_owned()),
} },
Some(c) => return Err(format!("invalid format specifier: %.{}", c)), Some(c) => return Err(format!("invalid format specifier: %.{}", c)),
None => return Err("missing format specifier".to_owned()), None => return Err("missing format specifier".to_owned()),
} },
Some(c) => return Err(format!("invalid format specifier: %{}", c)), Some(c) => return Err(format!("invalid format specifier: %{}", c)),
None => return Err("missing format specifier".to_owned()), None => return Err("missing format specifier".to_owned()),
}, },

View file

@ -592,3 +592,19 @@ fn test_custom_config_file_parsing() {
.assert() .assert()
.stdout(predicate::str::is_match("folder\n└── file").unwrap()); .stdout(predicate::str::is_match("folder\n└── file").unwrap());
} }
#[test]
fn test_date_custom_format_supports_nanos_with_length() {
let dir = tempdir();
dir.child("one").touch().unwrap();
dir.child("two").touch().unwrap();
cmd()
.arg("-l")
.arg("--date")
.arg("+testDateFormat%.3f")
.arg("--ignore-config")
.arg(dir.path())
.assert()
.stdout(predicate::str::is_match("testDateFormat\\.[0-9]{3}").unwrap().count(2));
}