use super::parse;
#[test]
fn jiff_answers_the_sub_day_units() {
for (text, seconds) in [
("PT1H30M30S", 5_430),
("1h 30m 30s", 5_430),
("1h30m30s", 5_430),
("10m", 600),
("-PT2S", -2),
("0s", 0),
] {
assert_eq!(
parse(text)
.unwrap_or_else(|e| panic!("{text}: {e}"))
.as_secs(),
seconds,
"{text}"
);
}
}
#[test]
fn the_table_answers_the_calendar_units() {
for (text, seconds) in [
("1d", 86_400),
("2w", 1_209_600),
("1month", 2_630_016),
("1M", 2_630_016),
("1y", 31_557_600),
] {
assert_eq!(
parse(text)
.unwrap_or_else(|e| panic!("{text}: {e}"))
.as_secs(),
seconds,
"{text}"
);
}
}
#[test]
fn the_month_and_the_minute_differ_by_case() {
assert_eq!(parse("1M").expect("a month").as_secs(), 2_630_016);
assert_eq!(parse("1m").expect("a minute").as_secs(), 60);
}
#[test]
fn the_table_reads_a_compound_in_any_order() {
assert_eq!(parse("1s 1h").expect("a compound").as_secs(), 3_601);
assert_eq!(parse("1d 1hrs").expect("a compound").as_secs(), 90_000);
}
#[test]
fn a_unitless_number_is_refused_and_zero_is_not() {
assert!(parse("5400").is_err());
assert!(parse("").is_err());
assert_eq!(parse("0").expect("bare zero").as_secs(), 0);
}
#[test]
fn a_value_past_the_carrier_refuses_rather_than_wrapping() {
assert!(parse("292471208677y").is_err());
}