Add tests for placeables

finchie
Aug 29, 2024, 6:42 AM
KF65O6ODA2UE2GYYTXFINCJW54CN62LB65NQLZNI5UM2W76ABEJAC

Dependencies

  • [2] 6ABVDTXZ Improve `fluent_embed_derive` test suite
  • [*] XEEXWJLG Add simple end-to-end test for selectors
  • [*] VNSHGQYN Support using glob paths in `localize` macro
  • [*] O77KA6C4 Create `fluent_embed` crate
  • [*] UKFEFT6L Create basic `Output` proc-macro
  • [*] JZXXFWQK Add tests for `locale_select` backends on unix
  • [*] BFL2Y7GN Add relative timestamps using `jiff` and `icu_relativetime`
  • [*] SHNZZSZG Create `cli_macros` shim crate

Change contents

  • file addition: placeables.rs (----------)
    [4.101]
    //! 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));
    }
  • file addition: placeables.ftl (----------)
    [5.990]
    # $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!
  • edit in fluent_embed_derive/Cargo.toml at line 31
    [2.457]
    rstest_reuse = "0.7.0"
  • edit in Cargo.lock at line 70
    [8.189]
    [8.189]
    [[package]]
    name = "byteorder"
    version = "1.5.0"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
  • edit in Cargo.lock at line 224
    [2.877]
    [9.5348]
    "rstest_reuse",
  • edit in Cargo.lock at line 323
    [2.3340]
    [2.3340]
    ]
    [[package]]
    name = "getrandom"
    version = "0.2.15"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
    dependencies = [
    "cfg-if",
    "libc",
    "wasi",
  • edit in Cargo.lock at line 841
    [5.3013]
    [2.4375]
    ]
    [[package]]
    name = "ppv-lite86"
    version = "0.2.20"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04"
    dependencies = [
    "zerocopy",
  • edit in Cargo.lock at line 911
    [7.4944]
    [5.3029]
    ]
    [[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",
  • edit in Cargo.lock at line 935
    [5.3044]
    [5.3044]
    name = "rand_core"
    version = "0.6.4"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
    dependencies = [
    "getrandom",
    ]
    [[package]]
  • edit in Cargo.lock at line 1006
    [2.5670]
    [2.5670]
    ]
    [[package]]
    name = "rstest_reuse"
    version = "0.7.0"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "b3a8fb4672e840a587a66fc577a5491375df51ddb88f2a2c2a792598c326fe14"
    dependencies = [
    "quote",
    "rand",
    "syn 2.0.71",
  • edit in Cargo.lock at line 1301
    [5.4437]
    [5.4437]
    name = "wasi"
    version = "0.11.0+wasi-snapshot-preview1"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
    [[package]]
  • edit in Cargo.lock at line 1542
    [10.5963]
    [10.5963]
    ]
    [[package]]
    name = "zerocopy"
    version = "0.7.35"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0"
    dependencies = [
    "byteorder",
    "zerocopy-derive",
  • edit in Cargo.lock at line 1555
    [10.5978]
    [10.5978]
    name = "zerocopy-derive"
    version = "0.7.35"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e"
    dependencies = [
    "proc-macro2",
    "quote",
    "syn 2.0.71",
    ]
    [[package]]