Adds more tests and places shared logic behind common module
MABGENI7CW5F5D3BFUJ7BS2H7XPYG4F3UMWGDPFFSMCCZKUUDLDQC 7M4UI3TWQIAA333GQ577HDWDWZPSZKWCYG556L6SBRLB6SZDQYPAC XEEXWJLGVIPIGURSDU4ETZMGAIFTFDPECM4QWFOSRHU7GMGVOUVQC AAERM7PBDVDFDEEXZ7UJ5WWQF7SPEJQQYXRBZ63ETB5YAVIECHMAC S2444K42FJFLTQMMU6PAVA4YRQGDNCMIFBQ5VO2LCD4GJ7LUCRYQC 6ABVDTXZOHVUDZDKDQS256F74LFIMM5DO3OZWHKRXZBUTPII4WAQC KZLFC7OWYNK3G5YNHRANUK3VUVCM6W6J34N7UABYA24XMZWAVVHQC 3NMKD6I57ONAGHEN4PZIAV2KPYESVR4JL3DTWSHXKCMVJBEQ4GIQC C6W7N6N57UCNHEV55HEZ3G7WN2ZOBGMFBB5M5ZPDB2HNNHHTOPBQC 7FYXVNAB6JAP3CJKE4MY57UWYSUPEXFVER6K264BSKYHVU6V4SGQC VNSHGQYNPGKGGPYNVP4Z2RWD7JCSDJVYAADD6UXWBYL6ZRXKLE4AC let mut buffer = Vec::new();data.message_for_locale(&mut buffer, &locale).unwrap();assert_eq!(String::from_utf8(buffer), Ok(expected_message));}
compare_message(data, expected_message, locale);}
//! End-to-end test for recursive localization support in the `fluent_embed_derive` macromod common;use common::compare_message;use fluent_embed::localize;use icu_locale::langid;#[localize("tests/locale/**/basic.ftl")]pub struct Title {name: String,}#[localize("tests/locale/**/basic.ftl")]pub struct Praise {name: Title,}#[localize("tests/locale/**/basic.ftl")]pub struct Greeting {name: Praise,}#[test]fn once() {let name = Title {name: String::from("Ferris"),};compare_message(Praise { name },"the Excellent Ferris the crab",langid!("en-US"),)}#[test]fn twice() {let name = Praise {name: Title {name: String::from("Ferris"),},};compare_message(Greeting { name },"Hello, the Excellent Ferris the crab!",langid!("en-US"),)}
message = Hello, world!
title = { $name } the crabpraise = the Excellent { $name }greeting = Hello, { $name }!
//! End-to-end test for lifetime support in the `fluent_embed_derive` macromod common;use common::compare_message;use fluent_embed::localize;use icu_locale::langid;#[localize("tests/locale/**/basic.ftl")]pub struct Greeting<'a> {name: &'a str,}#[test]fn local_str() {let name = "hi";compare_message(Greeting { name },format!("Hello, {name}!"),langid!("en-US"),)}#[test]fn static_str() {const NAME: &'static str = "hi";compare_message(Greeting { name: NAME },format!("Hello, {NAME}!"),langid!("en-US"),)}
//! End-to-end test for generics support in the `fluent_embed_derive` macromod common;use common::compare_message;use fluent_embed::localize;use icu_locale::langid;#[localize("tests/locale/**/basic.ftl")]pub struct Greeting<T> {name: T,}#[test]fn string() {let name = "Ferris";compare_message(Greeting { name }, "Hello, Ferris!", langid!("en-US"))}#[test]fn number() {let name = 2;compare_message(Greeting { name }, format!("Hello, 2!"), langid!("en-US"))}
//! End-to-end test for unit struct support (empty messages) in the `fluent_embed_derive` macromod common;use common::compare_message;use fluent_embed::localize;use icu_locale::langid;#[localize("tests/locale/**/empty.ftl")]pub struct Message;#[localize("tests/locale/**/empty.ftl")]pub enum Empty {Message,}#[test]fn unit_struct() {compare_message(Message, "Hello, world!", langid!("en-US"))}#[test]fn unit_variant() {compare_message(Empty::Message, "Hello, world!", langid!("en-US"))}
use fluent_embed::Localize;use icu_locale::LanguageIdentifier;pub fn compare_message<L: Localize<Vec<u8>>, S: AsRef<str>>(message: L,expected: S,locale: LanguageIdentifier,) {let mut buffer = Vec::new();message.message_for_locale(&mut buffer, &locale).unwrap();let result = String::from_utf8(buffer).unwrap();pretty_assertions::assert_eq!(result, expected.as_ref());}