Refactor selectors test to not rely on funciton calls

finchie
Aug 29, 2024, 6:13 AM
S2444K42FJFLTQMMU6PAVA4YRQGDNCMIFBQ5VO2LCD4GJ7LUCRYQC

Dependencies

  • [2] C6W7N6N5 Implement `Localize` for `FixedDecimal` and primitive number types
  • [3] CESJ4CTO Move macro-specific code into `macro_impl` module
  • [4] 7FYXVNAB Ignore comments in Fluent source code
  • [5] VNSHGQYN Support using glob paths in `localize` macro
  • [6] AAERM7PB Add selector tests for the `fr` locale
  • [7] 6ABVDTXZ Improve `fluent_embed_derive` test suite
  • [8] XEEXWJLG Add simple end-to-end test for selectors
  • [9] 3NMKD6I5 Refactor `Localize` trait to use `std::io::Write`

Change contents

  • replacement in fluent_embed_derive/tests/selectors.rs at line 4
    [3.40][3.40:75]()
    use icu_locid::LanguageIdentifier;
    [3.40]
    [3.0]
    use icu_locid::{langid, LanguageIdentifier};
  • edit in fluent_embed_derive/tests/selectors.rs at line 11
    [3.431][3.431:433](),[3.614][3.614:615](),[3.615][3.115:130](),[3.130][2.0:56](),[2.56][3.181:312](),[3.181][3.181:312](),[3.312][2.57:231](),[2.231][3.562:627](),[3.562][3.562:627](),[3.627][2.232:418](),[2.418][3.887:958](),[3.887][3.887:958](),[3.958][2.419:1419](),[2.1419][3.958:974](),[3.958][3.958:974]()
    }
    impl Message {
    fn expected_plural(&self, locale: &str) -> String {
    match self {
    Self::Emails { unread_emails } => match locale {
    "en-US" => match unread_emails {
    0..=999 => unread_emails.to_string(),
    &u64::MAX => "18,446,744,073,709,551,615".to_string(),
    _ => unreachable!(),
    },
    "fr" => match unread_emails {
    0..=999 => unread_emails.to_string(),
    &u64::MAX => "18 446 744 073 709 551 615".to_string(),
    _ => unreachable!(),
    },
    _ => unreachable!(),
    },
    }
    }
    fn expected_message(&self, locale: &str) -> String {
    match self {
    Self::Emails { unread_emails } => {
    let expected_plural = self.expected_plural(locale);
    match locale {
    "en-US" => match unread_emails {
    // Only 1 is singular
    1 => "You have 1 unread email.".to_string(),
    // Everything else is plural
    0 | 2.. => format!("You have {expected_plural} unread emails."),
    },
    "fr" => match unread_emails {
    // Both 0 & 1 are singular
    0 | 1 => format!("Vous avez {expected_plural} e-mail non lu."),
    // Everything else is plural
    2.. => format!("Vous avez {expected_plural} e-mails non lus."),
    },
    _ => unreachable!(),
    }
    }
    }
    }
  • edit in fluent_embed_derive/tests/selectors.rs at line 15
    [3.65]
    [3.1067]
    #[case::zero_en(langid!("en-US"), 0, "You have 0 unread emails.")]
    #[case::one_en(langid!("en-US"), 1, "You have 1 unread email.")]
    #[case::two_en(langid!("en-US"), 2, "You have 2 unread emails.")]
    #[case::max_en(
    langid!("en-US"),
    u64::MAX,
    "You have 18,446,744,073,709,551,615 unread emails."
    )]
    #[case::zero_fr(langid!("fr"), 0, "Vous avez 0 e-mail non lu.")]
    #[case::one_fr(langid!("fr"), 1, "Vous avez 1 e-mail non lu.")]
    #[case::two_fr(langid!("fr"), 2, "Vous avez 2 e-mails non lus.")]
    #[case::max_fr(langid!("fr"), u64::MAX, "Vous avez 18 446 744 073 709 551 615 e-mails non lus.")]
  • replacement in fluent_embed_derive/tests/selectors.rs at line 28
    [3.1090][3.1090:1186]()
    #[values(0, 1, 2, u64::MAX)] unread_emails: u64,
    #[values("en-US", "fr")] locale: &str,
    [3.1090]
    [3.1186]
    #[case] locale: LanguageIdentifier,
    #[case] unread_emails: u64,
    #[case] expected_message: String,
  • edit in fluent_embed_derive/tests/selectors.rs at line 33
    [3.181][3.1249:1450](),[3.1249][3.1249:1450]()
    let language_id = LanguageIdentifier::try_from_bytes(locale.as_bytes()).unwrap();
    // Make sure the generated string is what we expect
    let expected_message = data.expected_message(locale);
  • replacement in fluent_embed_derive/tests/selectors.rs at line 34
    [3.33][2.1420:1485]()
    data.message_for_locale(&mut buffer, &language_id).unwrap();
    [3.33]
    [3.89]
    data.message_for_locale(&mut buffer, &locale).unwrap();