mirror of
https://github.com/lsd-rs/lsd
synced 2024-12-13 13:42:34 +00:00
#532 Improve date format validation to include all supported cases | Formatting, test added
This commit is contained in:
parent
83a25867d0
commit
1363945fd8
2 changed files with 19 additions and 3 deletions
|
@ -308,17 +308,17 @@ pub fn validate_time_format(formatter: &str) -> Result<(), String> {
|
|||
Some('f') => (),
|
||||
Some(c) => return Err(format!("invalid format specifier: %{}{}", n, c)),
|
||||
None => return Err("missing format specifier".to_owned()),
|
||||
}
|
||||
},
|
||||
Some('.') => match chars.next() {
|
||||
Some('f') => (),
|
||||
Some(n @ '3') | Some(n @ '6') | Some(n @ '9') => match chars.next() {
|
||||
Some('f') => (),
|
||||
Some(c) => return Err(format!("invalid format specifier: %.{}{}", n, c)),
|
||||
None => return Err("missing format specifier".to_owned()),
|
||||
}
|
||||
},
|
||||
Some(c) => return Err(format!("invalid format specifier: %.{}", c)),
|
||||
None => return Err("missing format specifier".to_owned()),
|
||||
}
|
||||
},
|
||||
Some(c) => return Err(format!("invalid format specifier: %{}", c)),
|
||||
None => return Err("missing format specifier".to_owned()),
|
||||
},
|
||||
|
|
|
@ -592,3 +592,19 @@ fn test_custom_config_file_parsing() {
|
|||
.assert()
|
||||
.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));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue