use alloc::string::ToString;
use crate::tz::Tzif;
pub(crate) const TZIF_TEST_FILES: &[TzifTestFile] = &[
TzifTestFile {
name: "America/New_York",
data: include_bytes!("testdata/america-new-york.tzif"),
},
TzifTestFile {
name: "America/Sitka",
data: include_bytes!("testdata/america-sitka.tzif"),
},
TzifTestFile {
name: "America/St_Johns",
data: include_bytes!("testdata/america-st-johns.tzif"),
},
TzifTestFile {
name: "right/America/New_York",
data: include_bytes!("testdata/right-america-new-york.tzif"),
},
TzifTestFile {
name: "Antarctica/Troll",
data: include_bytes!("testdata/antarctica-troll.tzif"),
},
TzifTestFile {
name: "Australia/Tasmania",
data: include_bytes!("testdata/australia-tasmania.tzif"),
},
TzifTestFile {
name: "Europe/Dublin",
data: include_bytes!("testdata/europe-dublin.tzif"),
},
TzifTestFile {
name: "Pacific/Honolulu",
data: include_bytes!("testdata/pacific-honolulu.tzif"),
},
TzifTestFile {
name: "Australia/Sydney/RHEL8",
data: include_bytes!("testdata/australia-sydney-rhel8.tzif"),
},
TzifTestFile { name: "UTC", data: include_bytes!("testdata/utc.tzif") },
];
#[derive(Clone, Copy)]
pub(crate) struct TzifTestFile {
pub(crate) name: &'static str,
pub(crate) data: &'static [u8],
}
impl TzifTestFile {
pub(crate) fn get(name: &str) -> TzifTestFile {
for &tzif_file in TZIF_TEST_FILES {
if tzif_file.name == name {
return tzif_file;
}
}
panic!("could not find TZif test file for {name:?}")
}
pub(crate) fn parse(self) -> Tzif {
let name = Some(self.name.to_string());
Tzif::parse(name, self.data).unwrap_or_else(|err| {
panic!("failed to parse TZif test file for {:?}: {err}", self.name)
})
}
pub(crate) fn parse_v1(self) -> Tzif {
let name = Some(self.name.to_string());
let mut data = self.data.to_vec();
data[4] = 0;
Tzif::parse(name, &data).unwrap_or_else(|err| {
panic!(
"failed to parse V1 TZif test file for {:?}: {err}",
self.name
)
})
}
}