Should formalize a lot of expected behaviour, but will need to do some infrastructure work to make test case paramaterization more bearable. This solution will not be scalable once support is added for multiple locales.
XEEXWJLGVIPIGURSDU4ETZMGAIFTFDPECM4QWFOSRHU7GMGVOUVQC
//! A basic end-to-end test for the example at https://projectfluent.org/fluent/guide/selectors.html
use cli_macros::localize;
use icu_locid::locale;
use icu_plurals::{PluralRuleType, PluralRules};
#[localize("tests/selectors.ftl")]
pub enum Messages {
Emails { unread_emails: u64 },
}
#[test]
fn selectors() {
let plural_rules =
PluralRules::try_new(&locale!("en").into(), PluralRuleType::Cardinal).unwrap();
let test_values = [0, 1, 2, u64::MAX];
for test_value in test_values {
let correct_output = if test_value == 1 {
String::from("You have one unread email.")
} else {
format!("You have {test_value} unread emails.")
};
let message = Messages::Emails {
unread_emails: test_value,
};
assert_eq!(
message.localize(&plural_rules),
correct_output,
"Unexpected output for unread_emails = {test_value}"
);
}
}
emails =
{ $unreadEmails ->
[one] You have one unread email.
*[other] You have { $unreadEmails } unread emails.
}