Crate icu_testdata[−][src]
Expand description
icu_testdata
is a unit testing package for ICU4X
.
The package exposes a DataProvider
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.
The list of locales and the current CLDR tag can be found in Cargo.toml.
The output data can be found in the data subdirectory. There, you will find:
json
for the ICU4X JSON test datacldr
for the source CLDR JSON
Pointing to custom test data
If you wish to run ICU4X tests with custom test data, you may do so by setting the “ICU4X_TESTDATA_DIR” environment variable:
$ ICU4X_TESTDATA_DIR=/path/to/custom/testdata cargo test
Re-generating the data
From the top level directory of the icu4x
metapackage, run:
$ cargo make testdata
The following commands are also available:
cargo make testdata-download
downloads fresh CLDR JSON without overwriting ICU4X JSONcargo make testdata-build-json
re-generates the ICU4X JSONcargo make bincode-gen-testdata
generates Bincode testdata
Examples
use std::borrow::Cow; use icu_provider::prelude::*; use icu_locid_macros::langid; let data_provider = icu_testdata::get_provider(); let data: DataPayload<icu_plurals::provider::PluralRuleStringsV1Marker> = data_provider .load_payload(&DataRequest { resource_path: ResourcePath { key: icu_plurals::provider::key::CARDINAL_V1, options: ResourceOptions { langid: Some(langid!("ru")), variant: None, }, }, }) .unwrap() .take_payload() .unwrap(); assert_eq!(data.get().few, Some(Cow::Borrowed("v = 0 and i % 10 = 2..4 and i % 100 != 12..14")));
Modules
Functions
Get a DataProvider
, loading from the test data JSON directory.
Panics if unable to load the data.
Get a DataProvider
, loading from the statically initialized bincode blob.
Panics if unable to load the data.