#![allow(clippy::unwrap_used, clippy::expect_used)]
use timeglyph::interpret;
fn unix_assumptions(value: i64) -> Vec<String> {
interpret::interpret_int(value)
.into_iter()
.find(|c| c.format_id == "unix")
.unwrap_or_else(|| panic!("no unix candidate for {value}"))
.assumptions
}
#[test]
fn value_approaching_signed_32bit_max_carries_boundary_note() {
let joined = unix_assumptions(2_100_000_000).join(" ").to_lowercase();
assert!(
joined.contains("consistent with")
&& joined.contains("32-bit")
&& (joined.contains("limit")
|| joined.contains("maximum")
|| joined.contains("boundary")),
"a value near 2^31 must carry a 'consistent with … 32-bit … limit' note; got: {joined:?}"
);
assert!(
!joined.contains("will roll over") && !joined.contains("has rolled over"),
"must not assert a verdict: {joined:?}"
);
}
#[test]
fn value_past_signed_but_within_unsigned_32bit_is_flagged() {
let joined = unix_assumptions(3_000_000_000).join(" ").to_lowercase();
assert!(
joined.contains("32-bit")
&& (joined.contains("exceeds") || joined.contains("unsigned") || joined.contains("past")),
"a value in (2^31, 2^32) must be flagged relative to the signed 32-bit range; got: {joined:?}"
);
}
#[test]
fn ordinary_in_range_value_has_no_boundary_note() {
let joined = unix_assumptions(1_577_836_800).join(" ").to_lowercase();
assert!(
!joined.contains("32-bit"),
"an ordinary value must carry no 32-bit boundary note; got: {joined:?}"
);
}
#[test]
fn eight_byte_formats_never_carry_the_32bit_note() {
let ms = interpret::interpret_int(1_577_836_800_000)
.into_iter()
.find(|c| c.format_id == "unix_ms")
.expect("unix_ms candidate");
let joined = ms.assumptions.join(" ").to_lowercase();
assert!(
!joined.contains("32-bit"),
"an 8-byte format must never carry a 32-bit boundary note; got: {joined:?}"
);
}