From ac23dca426a6132300b9b21ce412c2845e0fdc50 Mon Sep 17 00:00:00 2001 From: Anish Bhobe Date: Thu, 16 Mar 2023 15:53:43 +0100 Subject: [PATCH] tests/date: Added tests for date ISO8601 formats. Regex matching for correctness check. Tests for format with `minute`, `hour` and `date` added. --- tests/by-util/test_date.rs | 57 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/tests/by-util/test_date.rs b/tests/by-util/test_date.rs index a1064a8faa..bedbc959dc 100644 --- a/tests/by-util/test_date.rs +++ b/tests/by-util/test_date.rs @@ -45,15 +45,68 @@ fn test_date_rfc_3339() { #[test] fn test_date_rfc_8601() { + let re = Regex::new(r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2},\d{9}[+-]\d{2}:\d{2}\n$").unwrap(); for param in ["--iso-8601", "--i"] { - new_ucmd!().arg(format!("{param}=ns")).succeeds(); + new_ucmd!() + .arg(format!("{param}=ns")) + .succeeds() + .stdout_matches(&re); } } #[test] fn test_date_rfc_8601_second() { + let re = Regex::new(r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{2}:\d{2}\n$").unwrap(); for param in ["--iso-8601", "--i"] { - new_ucmd!().arg(format!("{param}=second")).succeeds(); + new_ucmd!() + .arg(format!("{param}=second")) + .succeeds() + .stdout_matches(&re); + new_ucmd!() + .arg(format!("{param}=seconds")) + .succeeds() + .stdout_matches(&re); + } +} + +#[test] +fn test_date_rfc_8601_minute() { + let re = Regex::new(r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}[+-]\d{2}:\d{2}\n$").unwrap(); + for param in ["--iso-8601", "--i"] { + new_ucmd!() + .arg(format!("{param}=minute")) + .succeeds() + .stdout_matches(&re); + new_ucmd!() + .arg(format!("{param}=minutes")) + .succeeds() + .stdout_matches(&re); + } +} + +#[test] +fn test_date_rfc_8601_hour() { + let re = Regex::new(r"^\d{4}-\d{2}-\d{2}T\d{2}[+-]\d{2}:\d{2}\n$").unwrap(); + for param in ["--iso-8601", "--i"] { + new_ucmd!() + .arg(format!("{param}=hour")) + .succeeds() + .stdout_matches(&re); + new_ucmd!() + .arg(format!("{param}=hours")) + .succeeds() + .stdout_matches(&re); + } +} + +#[test] +fn test_date_rfc_8601_date() { + let re = Regex::new(r"^\d{4}-\d{2}-\d{2}\n$").unwrap(); + for param in ["--iso-8601", "--i"] { + new_ucmd!() + .arg(format!("{param}=date")) + .succeeds() + .stdout_matches(&re); } }