Refactor `fluent_embed_derive` tests
Dependencies
- [2]
7M4UI3TWUpdate dependencies to latest versions - [3]
4MRF5E76Generate simple locale matching code in `localize()` - [4]
OWXLFLRMMerge `cli_macros` shim into `fluent_embed` - [5]
CESJ4CTOMove macro-specific code into `macro_impl` module - [6]
P6FW2GGORemove unnecessary parameters in generated `localize()` function - [7]
6ABVDTXZImprove `fluent_embed_derive` test suite - [8]
KZLFC7OWRename `fluent_embed_runtime` to `fluent_embed` - [9]
AAERM7PBAdd selector tests for the `fr` locale - [10]
7FYXVNABIgnore comments in Fluent source code - [11]
3WEPY3OXAdd `locale` parameter to derived `localize()` function - [12]
S2444K42Refactor selectors test to not rely on funciton calls - [13]
C6W7N6N5Implement `Localize` for `FixedDecimal` and primitive number types - [14]
XEEXWJLGAdd simple end-to-end test for selectors - [15]
3NMKD6I5Refactor `Localize` trait to use `std::io::Write` - [*]
VNSHGQYNSupport using glob paths in `localize` macro
Change contents
- replacement in fluent_embed_derive/tests/selectors.rs at line 3
use fluent_embed::{localize, Localize};mod common;use common::compare_message;use fluent_embed::localize; - edit in fluent_embed_derive/tests/selectors.rs at line 8
use pretty_assertions::assert_eq; - edit in fluent_embed_derive/tests/selectors.rs at line 17[3.1450]→[3.0:33](∅→∅),[3.33]→[3.773:834](∅→∅),[3.834]→[3.89:154](∅→∅),[3.1485]→[3.89:154](∅→∅),[3.89]→[3.89:154](∅→∅),[3.154]→[3.1111:1113](∅→∅),[3.410]→[3.1111:1113](∅→∅),[3.1523]→[3.1111:1113](∅→∅),[3.1111]→[3.1111:1113](∅→∅)
let mut buffer = Vec::new();data.message_for_locale(&mut buffer, &locale).unwrap();assert_eq!(String::from_utf8(buffer), Ok(expected_message));} - edit in fluent_embed_derive/tests/selectors.rs at line 35[3.181]
compare_message(data, expected_message, locale);} - file addition: recursive.rs[3.101]
//! 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"),)} - file addition: empty.ftl[17.990]
message = Hello, world! - file addition: basic.ftl[17.990]
title = { $name } the crabpraise = the Excellent { $name }greeting = Hello, { $name }! - file addition: lifetimes.rs[3.101]
//! 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"),)} - file addition: generics.rs[3.101]
//! 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"))} - file addition: empty_fields.rs[3.101]
//! 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"))} - file addition: common[3.101]
- file addition: mod.rs[0.3020]
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());}