Skip to content

Commit 953f792

Browse files
committed
date: add tests for --resolution flag
1 parent 5acfdca commit 953f792

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tests/by-util/test_date.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,3 +745,36 @@ fn test_date_empty_tz_time() {
745745
.succeeds()
746746
.stdout_only("Thu Jan 1 00:00:00 UTC 1970\n");
747747
}
748+
749+
#[test]
750+
fn test_date_resolution() {
751+
// Test that --resolution flag returns a floating point number by default
752+
new_ucmd!()
753+
.arg("--resolution")
754+
.succeeds()
755+
.stdout_str_check(|s| s.trim().parse::<f64>().is_ok());
756+
757+
// Test that --resolution flag can be passed twice to match gnu
758+
new_ucmd!()
759+
.arg("--resolution")
760+
.arg("--resolution")
761+
.succeeds()
762+
.stdout_str_check(|s| s.trim().parse::<f64>().is_ok());
763+
764+
// Test that can --resolution output can be formatted as a date
765+
new_ucmd!()
766+
.arg("--resolution")
767+
.arg("-Iseconds")
768+
.succeeds()
769+
.stdout_only("1970-01-01T00:00:00+00:00\n");
770+
}
771+
772+
#[test]
773+
fn test_date_resolution_no_combine() {
774+
// Test that date fails when --resolution flag is passed with date flag
775+
new_ucmd!()
776+
.arg("--resolution")
777+
.arg("-d")
778+
.arg("2025-01-01")
779+
.fails();
780+
}

0 commit comments

Comments
 (0)