Mostly testing different methods of string interpolation, nothing very fancy.
KF65O6ODA2UE2GYYTXFINCJW54CN62LB65NQLZNI5UM2W76ABEJAC
6ABVDTXZOHVUDZDKDQS256F74LFIMM5DO3OZWHKRXZBUTPII4WAQC
XEEXWJLGVIPIGURSDU4ETZMGAIFTFDPECM4QWFOSRHU7GMGVOUVQC
VNSHGQYNPGKGGPYNVP4Z2RWD7JCSDJVYAADD6UXWBYL6ZRXKLE4AC
O77KA6C4UJGZXVGPEA7WCRQH6XYQJPWETSPDXI3VOKOSRQND7JEQC
JZXXFWQKOYAFQLQZDRALXG4KGEDR7JKO3AZ5Q5X7IQTS7BCJP3QAC
UKFEFT6LSI4K7X6UHQFZYD52DILKXMZMYSO2UYS2FCHNPXIF4BEQC
BFL2Y7GN6NBXXNAUSD4M6T6CIVQ2OLERPE2CAFSLRF377WFFTVCQC
SHNZZSZGIBTTD4IV5SMW5BIN5DORUWQVTVTNB5RMRD5CTFNOMJ6AC
//! End-to-end tests for the examples at https://projectfluent.org/fluent/guide/placeables.html
use fluent_embed::{localize, Localize};
use icu_locid::langid;
use pretty_assertions::assert_eq;
use rstest::rstest;
use rstest_reuse::{apply, template};
#[localize("tests/locale/**/placeables.ftl")]
pub enum Message {
OneNumber {
number: u64,
},
OneString {
first: String,
},
TwoStrings {
first: String,
second: String,
},
Many {
first: String,
second: String,
third: u64,
},
}
#[template]
#[rstest]
fn first_second_strings(
#[values("a regular string", "", r#"""#)] first: String,
#[values("a regular string", "", r#"""#)] second: String,
) {
}
#[rstest]
#[case::basic("a regular string")]
#[case::empty("")]
#[case::double_quote(r#"""#)]
fn one_string(#[case] first: String) {
let expected_message = format!(r#"Here is a string: "{first}"."#);
let data = Message::OneString { first };
let mut buffer = Vec::new();
data.message_for_locale(&mut buffer, &langid!("en-US"))
.unwrap();
assert_eq!(String::from_utf8(buffer), Ok(expected_message));
}
#[apply(first_second_strings)]
fn two_strings(first: String, second: String) {
let expected_message = format!(r#"Here is a string: "{first}". And another: "{second}"."#);
let data = Message::TwoStrings { first, second };
let mut buffer = Vec::new();
data.message_for_locale(&mut buffer, &langid!("en-US"))
.unwrap();
assert_eq!(String::from_utf8(buffer), Ok(expected_message));
}
#[apply(first_second_strings)]
#[case::zero(0, "0")]
#[case::one(1, "1")]
#[case::two(2, "2")]
#[case::max(u64::MAX, "18,446,744,073,709,551,615")]
fn many_interpolations(first: String, second: String, #[case] third: u64, #[case] plural: &str) {
let expected_message = format!(
r#"Here is a string: "{first}". And another: "{second}". I once counted {plural} strings in total!"#
);
let data = Message::Many {
first,
second,
third,
};
let mut buffer = Vec::new();
data.message_for_locale(&mut buffer, &langid!("en-US"))
.unwrap();
assert_eq!(String::from_utf8(buffer), Ok(expected_message));
}
#[rstest]
#[case::zero(0, "0")]
#[case::one(1, "1")]
#[case::two(2, "2")]
#[case::max(u64::MAX, "18,446,744,073,709,551,615")]
fn one_number(#[case] number: u64, #[case] plural: &str) {
let expected_message = format!("Here is a number: {plural}.");
let data = Message::OneNumber { number };
let mut buffer = Vec::new();
data.message_for_locale(&mut buffer, &langid!("en-US"))
.unwrap();
assert_eq!(String::from_utf8(buffer), Ok(expected_message));
}
# $first (String)
one-string = Here is a string: "{ $first }".
# $number (Number)
one-number = Here is a number: { $number }.
# $first (String)
# $second (String)
two-strings = Here is a string: "{ $first }". And another: "{ $second }".
# $first (String)
# $second (String)
# $third (Number)
many = Here is a string: "{ $first }". And another: "{ $second }". I once counted { $third } strings in total!
rstest_reuse = "0.7.0"
]
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core",