use proptest::prelude::*;
use super::month_names::MONTH_NAMES;
pub(crate) fn month_name_strategy() -> BoxedStrategy<String> {
prop::sample::select(&MONTH_NAMES)
.prop_flat_map(|month| {
prop::collection::vec(any::<bool>(), month.len()).prop_map(move |upper| {
month
.chars()
.zip(upper)
.map(|(ch, is_upper)| {
if is_upper {
ch.to_ascii_uppercase()
} else {
ch.to_ascii_lowercase()
}
})
.collect()
})
})
.boxed()
}
pub(crate) fn ordinal_suffix_strategy() -> BoxedStrategy<&'static str> {
prop_oneof![Just("st"), Just("nd"), Just("rd"), Just("th")].boxed()
}
pub(crate) fn ordinal_day_strategy() -> BoxedStrategy<String> { ordinal_day_with_range(1u8..=31) }
pub(crate) fn ordinal_day_with_range(
range: impl Strategy<Value = u8> + 'static,
) -> BoxedStrategy<String> {
(range, ordinal_suffix_strategy())
.prop_map(|(day, suffix)| format!("{day}{suffix}"))
.boxed()
}
pub(crate) fn numeric_day_strategy() -> BoxedStrategy<String> { numeric_day_with_range(1u8..=31) }
pub(crate) fn numeric_day_with_range(
range: impl Strategy<Value = u8> + 'static,
) -> BoxedStrategy<String> {
(range, any::<bool>())
.prop_map(|(day, append_comma)| {
if append_comma {
format!("{day},")
} else {
day.to_string()
}
})
.boxed()
}
pub(crate) fn year_strategy() -> BoxedStrategy<String> {
(1000u16..=2999).prop_map(|year| year.to_string()).boxed()
}