Crate icu_testdata
source · [−]Expand description
icu_testdata
is a unit testing crate for ICU4X
.
The crate exposes a data provider with stable data useful for unit testing. The data is based on a CLDR tag and a short list of locales that, together, cover a range of scenarios.
There are four modes of operation, enabled by features:
static
(default) exposesget_postcard_provider
.fs
exposesget_json_provider
baked
exposesget_baked_provider
.metadata
exposes themetadata
module which contains information such as the CLDR Gitref and the list of included locales.
However, clients should not generally choose a specific provider, but rather use get_provider
.
This is currently an alias for get_postcard_provider
, as it is fast and has few dependencies.
Re-generating the data
Downloading fresh CLDR data
$ cargo run --bin --features=bin icu4x-testdata-download-sources
Regenerating JSON and postcard data
$ cargo run --bin --features=bin icu4x-testdata-datagen
Examples
use std::borrow::Cow;
use icu_provider::prelude::*;
use icu_locid::locale;
let data_provider = icu_testdata::get_provider();
let data: DataPayload<icu_plurals::provider::CardinalV1Marker> = data_provider
.load_resource(&DataRequest {
options: locale!("ru").into(),
metadata: Default::default(),
})
.unwrap()
.take_payload()
.unwrap();
let rule = "v = 0 and i % 10 = 2..4 and i % 100 != 12..14".parse()
.expect("Failed to parse plural rule");
assert_eq!(data.get().few, Some(rule));
Re-exports
pub use get_postcard_provider as get_provider;
Modules
Functions
Get a data, loading from the test data JSON directory.
Get a data provider, loading from the statically initialized postcard blob.
Get a small data provider that only contains the decimal/symbols@1
key for en
and bn
.