#[cfg(not(miri))]
use crate::tz::tzif::TzifOwned;
pub(crate) static ANDROID_CONCATENATED_TZIF: &'static [u8] =
include_bytes!("testdata/android/tzdata");
pub(crate) static 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: "America/Sao_Paulo",
data: include_bytes!("testdata/america-sao-paulo.tzif"),
},
TzifTestFile {
name: "America/Boa_Vista",
data: include_bytes!("testdata/america-boa-vista.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:?}")
}
#[cfg(not(miri))]
pub(crate) fn parse(self) -> TzifOwned {
use alloc::string::ToString;
let name = Some(self.name.to_string());
TzifOwned::parse(name, self.data).unwrap_or_else(|err| {
panic!("failed to parse TZif test file for {:?}: {err}", self.name)
})
}
#[cfg(not(miri))]
pub(crate) fn parse_v1(self) -> TzifOwned {
use alloc::string::ToString;
let name = Some(self.name.to_string());
let mut data = self.data.to_vec();
data[4] = 0;
TzifOwned::parse(name, &data).unwrap_or_else(|err| {
panic!(
"failed to parse V1 TZif test file for {:?}: {err}",
self.name
)
})
}
}