Add simple end-to-end test for selectors

finchie
Feb 18, 2024, 8:26 AM
XEEXWJLGVIPIGURSDU4ETZMGAIFTFDPECM4QWFOSRHU7GMGVOUVQC

Dependencies

  • [2] 5FIVUZYF Unify `fluent_embed` macro API as `localize()`
  • [3] SHNZZSZG Create `cli_macros` shim crate
  • [4] OCR4YRQ2 Parse group from fluent file specified by macro attribute
  • [5] QSK7JRBA Add simple `attribute_path` function
  • [*] XGNME3WR Move `Group::derive_enum` to new `crate::parse_macro` module

Change contents

  • replacement in fluent_embed/src/parse_macro.rs at line 58
    [2.469][2.469:550]()
    let resource_path = PathBuf::from(manifest_root).join(path_literal.value());
    [2.469]
    [2.550]
    let resource_path = PathBuf::from(&manifest_root).join(path_literal.value());
  • file addition: tests (d--r------)
    [3.22]
  • file addition: selectors.rs (----------)
    [0.101]
    //! 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}"
    );
    }
    }
  • file addition: selectors.ftl (----------)
    [0.101]
    emails =
    { $unreadEmails ->
    [one] You have one unread email.
    *[other] You have { $unreadEmails } unread emails.
    }