Skip to content

Commit

Permalink
Fmt and moving code around
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc committed Jul 27, 2023
1 parent 0a59468 commit 05144e1
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 47 deletions.
2 changes: 1 addition & 1 deletion components/locid_transform/src/fallback/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
//! ```

use crate::provider::*;
use alloc::vec::Vec;
use icu_locid::extensions::unicode::{Key, Value};
use icu_locid::subtags::Variants;
use icu_provider::prelude::*;
use alloc::vec::Vec;

pub use icu_provider::{FallbackPriority, FallbackSupplement};

Expand Down
8 changes: 2 additions & 6 deletions provider/blob/src/blob_data_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,7 @@ mod test {
{
let mut exporter = BlobExporter::new_with_sink(Box::new(&mut blob));

exporter
.flush(HelloWorldV1Marker::KEY)
.unwrap();
exporter.flush(HelloWorldV1Marker::KEY).unwrap();

exporter.close().unwrap();
}
Expand All @@ -180,9 +178,7 @@ mod test {
{
let mut exporter = BlobExporter::new_with_sink(Box::new(&mut blob));

exporter
.flush(HelloSingletonV1Marker::KEY)
.unwrap();
exporter.flush(HelloSingletonV1Marker::KEY).unwrap();

exporter.close().unwrap();
}
Expand Down
4 changes: 3 additions & 1 deletion provider/core/src/datagen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ pub trait DataExporter: Sync {
_key: DataKey,
_fallback_mode: BuiltInFallbackMode,
) -> Result<(), DataError> {
Err(DataError::custom("Exporter does not implement built-in fallback"))
Err(DataError::custom(
"Exporter does not implement built-in fallback",
))
}

/// Function called after a non-singleton key has been fully enumerated.
Expand Down
100 changes: 61 additions & 39 deletions provider/datagen/tests/test-options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use elsa::sync::FrozenMap;
use icu_datagen::options::{FallbackMode, LocaleInclude, Options};
use icu_datagen::{DatagenProvider, SourceData};
use icu_decimal::provider::DecimalSymbolsV1Marker;
use icu_locid::langid;
use icu_locid::{langid, LanguageIdentifier};
use icu_provider::datagen::{DataExporter, ExportMarker};
use icu_provider::prelude::*;
use postcard::ser_flavors::{AllocVec, Flavor};
Expand Down Expand Up @@ -76,51 +76,26 @@ fn test_fallback_options() {

let mut options = Options::default();

options.locales = LocaleInclude::All;
options.fallback = FallbackMode::Hybrid;
DatagenProvider::try_new(options.clone(), source.clone())
.unwrap()
.export(decimal_symbols_key.clone(), &mut testing_exporter)
.unwrap();
let data_all_hybrid = testing_exporter.take_map_and_reset();
let explicit_locales: HashSet<LanguageIdentifier> = [
langid!("en-GB"),
langid!("sr-ME"),
langid!("ar-EG"),
langid!("es"),
]
.into_iter()
.collect();

options.fallback = FallbackMode::RuntimeManual;
DatagenProvider::try_new(options.clone(), source.clone())
.unwrap()
.export(decimal_symbols_key.clone(), &mut testing_exporter)
.unwrap();
let data_all_runtime = testing_exporter.take_map_and_reset();
//
// All+Hybrid
//

options.locales = LocaleInclude::Explicit(
[
langid!("en-GB"),
langid!("sr-ME"),
langid!("ar-EG"),
langid!("es"),
]
.into_iter()
.collect(),
);
options.locales = LocaleInclude::All;
options.fallback = FallbackMode::Hybrid;
DatagenProvider::try_new(options.clone(), source.clone())
.unwrap()
.export(decimal_symbols_key.clone(), &mut testing_exporter)
.unwrap();
let data_explicit_hybrid = testing_exporter.take_map_and_reset();

options.fallback = FallbackMode::RuntimeManual;
DatagenProvider::try_new(options.clone(), source.clone())
.unwrap()
.export(decimal_symbols_key.clone(), &mut testing_exporter)
.unwrap();
let data_explicit_runtime = testing_exporter.take_map_and_reset();

options.fallback = FallbackMode::Preresolved;
DatagenProvider::try_new(options, source)
.unwrap()
.export(decimal_symbols_key, &mut testing_exporter)
.unwrap();
let data_explicit_preresolved = testing_exporter.take_map_and_reset();
let data_all_hybrid = testing_exporter.take_map_and_reset();

// These are all of the supported locales for DecimalSymbolsV1 in tests/data.
let all_locales: Vec<&str> = vec![
Expand Down Expand Up @@ -153,6 +128,17 @@ fn test_fallback_options() {
// All+Hybrid should return exactly the supported locales set.
itertools::assert_equal(data_all_hybrid.keys(), all_locales.iter());

//
// All+Runtime
//

options.fallback = FallbackMode::RuntimeManual;
DatagenProvider::try_new(options.clone(), source.clone())
.unwrap()
.export(decimal_symbols_key.clone(), &mut testing_exporter)
.unwrap();
let data_all_runtime = testing_exporter.take_map_and_reset();

// These are all of the supported locales with deduplication applied.
let all_locales_dedup: Vec<&str> = vec![
"ar",
Expand Down Expand Up @@ -218,6 +204,18 @@ fn test_fallback_options() {
// All+Runtime should return the supported locales set with deduplication.
itertools::assert_equal(data_all_runtime.keys(), all_locales_dedup.iter());

//
// Explicit+Hybrid
//

options.locales = LocaleInclude::Explicit(explicit_locales.clone());
options.fallback = FallbackMode::Hybrid;
DatagenProvider::try_new(options.clone(), source.clone())
.unwrap()
.export(decimal_symbols_key.clone(), &mut testing_exporter)
.unwrap();
let data_explicit_hybrid = testing_exporter.take_map_and_reset();

// Explicit locales are "en-GB", "sr-ME", "ar-EG", "es"
let explicit_hybrid_locales: Vec<&str> = vec![
"ar", // ancestor of ar-EG
Expand All @@ -240,6 +238,18 @@ fn test_fallback_options() {
// Explicit+Hybrid should return the expanded explicit locales set above.
itertools::assert_equal(data_explicit_hybrid.keys(), explicit_hybrid_locales.iter());

//
// Explicit+Runtime
//

options.locales = LocaleInclude::Explicit(explicit_locales.clone());
options.fallback = FallbackMode::RuntimeManual;
DatagenProvider::try_new(options.clone(), source.clone())
.unwrap()
.export(decimal_symbols_key.clone(), &mut testing_exporter)
.unwrap();
let data_explicit_runtime = testing_exporter.take_map_and_reset();

// Explicit locales are "en-GB", "sr-ME", "ar-EG", "es"
let explicit_hybrid_locales_dedup: Vec<&str> = vec![
"ar",
Expand All @@ -261,6 +271,18 @@ fn test_fallback_options() {
explicit_hybrid_locales_dedup.iter(),
);

//
// Explicit+Preresolved
//

options.locales = LocaleInclude::Explicit(explicit_locales.clone());
options.fallback = FallbackMode::Preresolved;
DatagenProvider::try_new(options, source)
.unwrap()
.export(decimal_symbols_key, &mut testing_exporter)
.unwrap();
let data_explicit_preresolved = testing_exporter.take_map_and_reset();

// Explicit locales are "en-GB", "sr-ME", "ar-EG", "es"
let explicit_preresolved_locales: Vec<&str> = vec![
"ar-EG",
Expand Down

0 comments on commit 05144e1

Please sign in to comment.