Skip to content

Commit

Permalink
#532 Improve date format validation to include all supported cases | …
Browse files Browse the repository at this point in the history
…Formatting, test added
  • Loading branch information
Arkadiusz Bielewicz authored and meain committed Oct 14, 2021
1 parent 83a2586 commit 1363945
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
},
Expand Down
16 changes: 16 additions & 0 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

0 comments on commit 1363945

Please sign in to comment.