Skip to content

Commit

Permalink
get rid of baked testdata
Browse files Browse the repository at this point in the history
  • Loading branch information
robertbastian committed Oct 19, 2024
1 parent db3f275 commit e603a52
Show file tree
Hide file tree
Showing 19 changed files with 2,397 additions and 388 deletions.
2 changes: 1 addition & 1 deletion components/experimental/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ default = ["compiled_data"]
compiled_data = ["dep:icu_experimental_data", "icu_decimal/compiled_data", "icu_list/compiled_data", "icu_plurals/compiled_data", "icu_properties/compiled_data", "icu_normalizer/compiled_data"]
datagen = ["serde", "std", "dep:databake", "zerovec/databake", "zerotrie/databake", "tinystr/databake", "icu_collections/databake", "std", "log", "icu_pattern/databake", "icu_plurals/datagen", "icu_pattern/alloc"]
ryu = ["fixed_decimal/ryu"]
serde = ["dep:serde", "zerovec/serde", "potential_utf/serde", "tinystr/serde", "icu_collections/serde", "icu_decimal/serde", "icu_list/serde", "icu_pattern/serde", "icu_plurals/serde", "icu_provider/serde", "zerotrie/serde"]
serde = ["dep:serde", "zerovec/serde", "potential_utf/serde", "tinystr/serde", "icu_collections/serde", "icu_decimal/serde", "icu_list/serde", "icu_pattern/serde", "icu_plurals/serde", "icu_provider/serde", "zerotrie/serde", "icu_normalizer/serde"]
std = ["fixed_decimal/std", "icu_decimal/std", "icu_pattern/std", "icu_plurals/std", "icu_provider/std", "icu_locale_core/std"]

bench = []
Expand Down
6 changes: 1 addition & 5 deletions components/experimental/benches/transliterate/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ use icu_locale_core::Locale;

use icu_experimental::transliterate::Transliterator;

#[allow(clippy::single_component_path_imports)]
use icu_experimental;
include!("../../tests/transliterate/data/provider.rs");

struct BenchDataContent {
pub num: usize,
pub name: String,
Expand All @@ -36,7 +32,7 @@ fn bench_data_from_sources(locale_str: &str, source: &str) -> Vec<BenchDataConte
.map(|(idx, input)| BenchDataContent {
num: idx + 1,
name: locale_str.to_string(),
translit: Transliterator::try_new_unstable(locale.clone(), &TestingProvider).unwrap(),
translit: Transliterator::try_new(&locale).unwrap(),
input,
})
.collect()
Expand Down
12 changes: 6 additions & 6 deletions components/experimental/src/transliterate/compile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ mod tests {
}];
let expected_id_group2 = vec![ds::SimpleId {
filter: parse_set_cp(r"[\ ]"),
id: Cow::Borrowed("x-any-remove"),
id: Cow::Borrowed("any-remove"),
}];
let expected_id_group3 = vec![
ds::SimpleId {
Expand All @@ -704,7 +704,7 @@ mod tests {
},
ds::SimpleId {
filter: parse::FilterSet::all(),
id: Cow::Borrowed("x-any-nfc"),
id: Cow::Borrowed("any-nfc"),
},
];

Expand Down Expand Up @@ -782,8 +782,8 @@ mod tests {
assert_eq!(
forward.payload.get().deps().collect::<HashSet<_>>(),
HashSet::from_iter([
Cow::Borrowed("x-any-nfc"),
Cow::Borrowed("x-any-remove"),
Cow::Borrowed("any-nfc"),
Cow::Borrowed("any-remove"),
Cow::Borrowed("x-interindic-devanagari"),
Cow::Borrowed("x-latin-interindic"),
])
Expand All @@ -795,7 +795,7 @@ mod tests {
let expected_id_group1 = vec![
ds::SimpleId {
filter: parse::FilterSet::all(),
id: Cow::Borrowed("x-any-nfd"),
id: Cow::Borrowed("any-nfd"),
},
ds::SimpleId {
filter: parse::FilterSet::all(),
Expand Down Expand Up @@ -888,7 +888,7 @@ mod tests {
reverse.payload.get().deps().collect::<HashSet<_>>(),
HashSet::from_iter([
Cow::Borrowed("und-t-d0-addrndsp-m0-fifty-s0-anyrev"),
Cow::Borrowed("x-any-nfd"),
Cow::Borrowed("any-nfd"),
Cow::Borrowed("x-any-revfncall"),
Cow::Borrowed("x-devanagari-interindic"),
Cow::Borrowed("x-interindic-latin"),
Expand Down
118 changes: 78 additions & 40 deletions components/experimental/src/transliterate/transliterator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ impl Transliterator {
/// Construct a [`Transliterator`] from the given [`Locale`].
///
/// # Examples
/// ```ignore
/// ```
/// use icu::experimental::transliterate::Transliterator;
/// // BCP-47-T ID for Bengali to Arabic transliteration
/// let locale = "und-Arab-t-und-beng".parse().unwrap();
Expand Down Expand Up @@ -304,7 +304,7 @@ impl Transliterator {
///
/// # Example
/// Overriding `"de-t-de-d0-ascii"`'s dependency on `"und-t-und-Latn-d0-ascii"`:
/// ```ignore
/// ```
/// use icu::experimental::transliterate::{Transliterator, CustomTransliterator};
/// use icu::locale::Locale;
/// use core::ops::Range;
Expand Down Expand Up @@ -347,7 +347,6 @@ impl Transliterator {
where
F: Fn(&Locale) -> Option<Result<Box<dyn CustomTransliterator>, DataError>>,
{
use icu_provider::any::AsDowncastingAnyProvider;
Self::try_new_with_override_unstable(
&provider.as_downcasting(),
&provider.as_downcasting(),
Expand All @@ -365,7 +364,6 @@ impl Transliterator {
where
F: Fn(&Locale) -> Option<Result<Box<dyn CustomTransliterator>, DataError>>,
{
use icu_provider::buf::AsDeserializingBufferProvider;
Self::try_new_with_override_unstable(
&provider.as_deserializing(),
&provider.as_deserializing(),
Expand Down Expand Up @@ -1377,11 +1375,8 @@ impl<'a> VarTable<'a> {

#[cfg(test)]
mod tests {
#![allow(unused_imports)]
use super::*;

use crate as icu_experimental;
include!("../../../tests/transliterate/data/provider.rs");
use crate::transliterate::RuleCollection;

#[test]
fn test_empty_matches() {
Expand All @@ -1393,10 +1388,19 @@ mod tests {
("b1", "bmatch1"),
];

let mut collection = RuleCollection::default();
collection.register_source(
&"und-x-test".parse().unwrap(),
include_str!("../../../tests/transliterate/data/transforms/EmptyMatches.txt").into(),
[],
false,
true,
);

let t = Transliterator::try_new_unstable(
&TestingProvider,
&collection.as_provider(),
&icu_normalizer::provider::Baked,
&"und-t-und-s0-test-d0-test-m0-emtymach".parse().unwrap(),
&"und-x-test".parse().unwrap(),
)
.unwrap();

Expand All @@ -1407,10 +1411,26 @@ mod tests {

#[test]
fn test_recursive_suite() {
let mut collection = RuleCollection::default();
collection.register_source(
&"und-x-root".parse().unwrap(),
include_str!("../../../tests/transliterate/data/transforms/RecursiveRoot.txt").into(),
[],
false,
true,
);
collection.register_source(
&"und-x-rec".parse().unwrap(),
include_str!("../../../tests/transliterate/data/transforms/RecursiveA.txt").into(),
["Test-Test/RecursiveSuiteA"],
false,
true,
);

let t = Transliterator::try_new_unstable(
&TestingProvider,
&collection.as_provider(),
&icu_normalizer::provider::Baked,
&"und-t-und-s0-test-d0-test-m0-rectestr".parse().unwrap(),
&"und-x-root".parse().unwrap(),
)
.unwrap();

Expand All @@ -1421,10 +1441,18 @@ mod tests {

#[test]
fn test_cursor_placeholders_filters() {
let mut collection = RuleCollection::default();
collection.register_source(
&"und-x-test".parse().unwrap(),
include_str!("../../../tests/transliterate/data/transforms/CursorFilters.txt").into(),
[],
false,
true,
);
let t = Transliterator::try_new_unstable(
&TestingProvider,
&collection.as_provider(),
&icu_normalizer::provider::Baked,
&"und-t-und-s0-test-d0-test-m0-cursfilt".parse().unwrap(),
&"und-x-test".parse().unwrap(),
)
.unwrap();

Expand All @@ -1435,10 +1463,18 @@ mod tests {

#[test]
fn test_functionality() {
let mut collection = RuleCollection::default();
collection.register_source(
&"und-x-test".parse().unwrap(),
include_str!("../../../tests/transliterate/data/transforms/Functionality.txt").into(),
[],
false,
true,
);
let t = Transliterator::try_new_unstable(
&TestingProvider,
&collection.as_provider(),
&icu_normalizer::provider::Baked,
&"und-t-und-s0-test-d0-test-m0-niels".parse().unwrap(),
&"und-x-test".parse().unwrap(),
)
.unwrap();

Expand All @@ -1449,12 +1485,7 @@ mod tests {

#[test]
fn test_de_ascii() {
let t = Transliterator::try_new_unstable(
&TestingProvider,
&icu_normalizer::provider::Baked,
&"de-t-de-d0-ascii".parse().unwrap(),
)
.unwrap();
let t = Transliterator::try_new(&"de-t-de-d0-ascii".parse().unwrap()).unwrap();
let input =
"Über ältere Lügner lästern ist sehr a\u{0308}rgerlich. Ja, SEHR ÄRGERLICH! - ꜵ";
let output =
Expand All @@ -1474,17 +1505,13 @@ mod tests {
}

let want_locale = "und-t-und-latn-d0-ascii".parse().unwrap();
let t = Transliterator::try_new_with_override_unstable(
&TestingProvider,
&icu_normalizer::provider::Baked,
&"de-t-de-d0-ascii".parse().unwrap(),
|locale| {
let t =
Transliterator::try_new_with_override(&"de-t-de-d0-ascii".parse().unwrap(), |locale| {
locale
.eq(&want_locale)
.then_some(Ok(Box::new(MaoamTranslit)))
},
)
.unwrap();
})
.unwrap();

let input = "Ich liebe ꜵ über alles";
let output = "Ich liebe maoam ueber alles";
Expand All @@ -1493,23 +1520,26 @@ mod tests {

#[test]
fn test_nfc_nfd() {
let t = Transliterator::try_new_unstable(
&TestingProvider,
&icu_normalizer::provider::Baked,
&"und-t-und-latn-d0-ascii".parse().unwrap(),
)
.unwrap();
let t = Transliterator::try_new(&"und-t-und-latn-d0-ascii".parse().unwrap()).unwrap();
let input = "äa\u{0308}";
let output = "aa";
assert_eq!(t.transliterate(input.to_string()), output);
}

#[test]
fn test_hex_rust() {
let mut collection = RuleCollection::default();
collection.register_source(
&"und-x-test".parse().unwrap(),
"::Hex/Rust".into(),
[],
false,
true,
);
let t = Transliterator::try_new_unstable(
&TestingProvider,
&collection.as_provider(),
&icu_normalizer::provider::Baked,
&"und-t-und-s0-test-d0-test-m0-hexrust".parse().unwrap(),
&"und-x-test".parse().unwrap(),
)
.unwrap();
let input = "\0äa\u{10FFFF}❤!";
Expand All @@ -1519,10 +1549,18 @@ mod tests {

#[test]
fn test_hex_unicode() {
let mut collection = RuleCollection::default();
collection.register_source(
&"und-x-test".parse().unwrap(),
"::Hex/Unicode".into(),
[],
false,
true,
);
let t = Transliterator::try_new_unstable(
&TestingProvider,
&collection.as_provider(),
&icu_normalizer::provider::Baked,
&"und-t-und-s0-test-d0-test-m0-hexuni".parse().unwrap(),
&"und-x-test".parse().unwrap(),
)
.unwrap();
let input = "\0äa\u{10FFFF}❤!";
Expand Down
11 changes: 1 addition & 10 deletions components/experimental/tests/transliterate/cldr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@

use icu_experimental::transliterate::Transliterator;

#[allow(clippy::single_component_path_imports)]
use icu_experimental;
include!("data/provider.rs");

#[test]
fn test_all_cldr() {
for (locale, data) in [
Expand Down Expand Up @@ -40,12 +36,7 @@ fn test_all_cldr() {
include_str!("data/fixtures/und-t-und-latn-d0-ascii.txt"),
),
] {
let t = Transliterator::try_new_unstable(
&TestingProvider,
&icu_normalizer::provider::Baked,
&locale.parse().unwrap(),
)
.unwrap();
let t = Transliterator::try_new(&locale.parse().unwrap()).unwrap();
let test_cases = data
.lines()
.filter(|x| !x.starts_with('#'))
Expand Down

This file was deleted.

48 changes: 0 additions & 48 deletions components/experimental/tests/transliterate/data/baked/mod.rs

This file was deleted.

Loading

0 comments on commit e603a52

Please sign in to comment.