Experimenting with more structured ways to handle command-line input/output in Rust
//! 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/locale/**/selectors.ftl")]
pub enum Messages {
    Emails { unread_emails: u64 },
}

#[test]
fn selectors() {
    let locale = locale!("en-US");
    let plural_rules =
        PluralRules::try_new(&locale.clone().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(&[&locale], &plural_rules),
            correct_output,
            "Unexpected output for unread_emails = {test_value}"
        );
    }
}