#![allow(clippy::unwrap_used, reason = "test code with known-valid times")]
use chrono::NaiveTime;
use super::{TimeError, parse_time};
#[test]
fn an_hour_or_minute_without_its_leading_zero_is_read() {
let expected = Ok(NaiveTime::from_hms_opt(9, 5, 0).unwrap());
for text in ["9:5", "9:05", "09:5"] {
assert_eq!(parse_time(text), expected, "for `{text}`");
}
}
#[test]
fn a_time_with_ascii_spaces_around_it_is_read() {
let expected = Ok(NaiveTime::from_hms_opt(9, 5, 0).unwrap());
for text in [" 09:05", "09:05 ", " 9:5 "] {
assert_eq!(parse_time(text), expected, "for `{text}`");
}
}
#[test]
fn a_time_with_other_whitespace_is_not_read() {
for text in ["09: 05", "09 :05", "\u{a0}09:05", "\t09:05"] {
assert_eq!(parse_time(text), Err(TimeError::Syntax), "for `{text}`");
}
}
#[test]
fn a_time_in_any_other_form_is_not_read() {
let texts = [
"+9:05", "-9:05", "009:05", "09:005", "09:05:00", "0905", "9h05", ":05", "09:", "",
];
for text in texts {
assert_eq!(parse_time(text), Err(TimeError::Syntax), "for `{text}`");
}
}
#[test]
fn a_time_a_day_does_not_have_is_not_read() {
for text in ["24:00", "09:60", "99:99"] {
assert_eq!(
parse_time(text),
Err(TimeError::NotATimeOfDay),
"for `{text}`"
);
}
}