Skip to content

Commit

Permalink
Merge branch 'main' into canload
Browse files Browse the repository at this point in the history
  • Loading branch information
robertbastian committed Jul 2, 2024
2 parents 98e1bba + 92f106d commit 0527aab
Show file tree
Hide file tree
Showing 36 changed files with 239 additions and 185 deletions.
4 changes: 2 additions & 2 deletions components/calendar/src/islamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2149,7 +2149,7 @@ mod test {
}
}

#[ignore]
#[ignore] // slow
#[test]
fn test_days_in_provided_year_observational() {
let calendar = IslamicObservational::new();
Expand Down Expand Up @@ -2179,7 +2179,7 @@ mod test {
);
}

#[ignore]
#[ignore] // slow
#[test]
fn test_days_in_provided_year_ummalqura() {
let calendar = IslamicUmmAlQura::new();
Expand Down
36 changes: 2 additions & 34 deletions components/collator/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,16 +622,12 @@ fn test_ja_chooon_kigoo() {
}
}

// TODO: This test should eventually test fallback
// TODO: Test Swedish and Chinese also, since they have unusual
// variant defaults. (But are currently not part of the test data.)
#[ignore]
#[test]
fn test_region_fallback() {
// There's no explicit fi-FI data.
let locale: Locale = "fi-u-co-standard".parse().unwrap();

// let locale = locale!("fi-FI").into();
let locale = locale!("fi-FI");

let collator = Collator::try_new(&locale.into(), CollatorOptions::new()).unwrap();
assert_eq!(collator.compare("ä", "z"), Ordering::Greater);
Expand Down Expand Up @@ -694,8 +690,8 @@ fn test_vi() {
}
}

#[ignore]
#[test]
// See DatagenProvider test_zh_non_baked for gb2312 and big5han tests
fn test_zh() {
// Note: ㄅ is Bopomofo.

Expand Down Expand Up @@ -735,20 +731,6 @@ fn test_zh() {
assert_eq!(collator.compare("佰", "ㄅ"), Ordering::Less);
assert_eq!(collator.compare("不", "把"), Ordering::Greater);
}
{
let locale: Locale = "zh-u-co-gb2312".parse().unwrap();
let collator = Collator::try_new(&locale.into(), CollatorOptions::new()).unwrap();
assert_eq!(collator.compare("艾", "a"), Ordering::Greater);
assert_eq!(collator.compare("佰", "a"), Ordering::Greater);
assert_eq!(collator.compare("ㄅ", "a"), Ordering::Greater);
assert_eq!(collator.compare("ㄅ", "ж"), Ordering::Greater);
assert_eq!(collator.compare("艾", "佰"), Ordering::Less);
// In GB2312 proper, Bopomofo comes before Han, but the
// collation leaves Bopomofo unreordered, so it comes after.
assert_eq!(collator.compare("艾", "ㄅ"), Ordering::Less);
assert_eq!(collator.compare("佰", "ㄅ"), Ordering::Less);
assert_eq!(collator.compare("不", "把"), Ordering::Greater);
}
{
let locale: Locale = "zh-u-co-stroke".parse().unwrap();
let collator = Collator::try_new(&locale.into(), CollatorOptions::new()).unwrap();
Expand Down Expand Up @@ -785,18 +767,6 @@ fn test_zh() {
assert_eq!(collator.compare("佰", "ㄅ"), Ordering::Less);
assert_eq!(collator.compare("不", "把"), Ordering::Less);
}
{
let locale: Locale = "zh-u-co-big5han".parse().unwrap();
let collator = Collator::try_new(&locale.into(), CollatorOptions::new()).unwrap();
assert_eq!(collator.compare("艾", "a"), Ordering::Greater);
assert_eq!(collator.compare("佰", "a"), Ordering::Greater);
assert_eq!(collator.compare("ㄅ", "a"), Ordering::Greater);
assert_eq!(collator.compare("ㄅ", "ж"), Ordering::Less);
assert_eq!(collator.compare("艾", "佰"), Ordering::Less);
assert_eq!(collator.compare("艾", "ㄅ"), Ordering::Less);
assert_eq!(collator.compare("佰", "ㄅ"), Ordering::Less);
assert_eq!(collator.compare("不", "把"), Ordering::Less);
}
// TODO: Test script and region aliases
}

Expand Down Expand Up @@ -1044,7 +1014,6 @@ fn test_tr_primary() {
}
}

#[ignore]
#[test]
fn test_lt_tertiary() {
let left = [
Expand Down Expand Up @@ -1079,7 +1048,6 @@ fn test_lt_tertiary() {
}
}

#[ignore]
#[test]
fn test_lt_primary() {
let left = ["ž"];
Expand Down
4 changes: 2 additions & 2 deletions components/datetime/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ macro_rules! size_test {
};
}
#[test]
#[cfg_attr(not(icu4x_run_size_tests), ignore)]
#[cfg_attr(not(icu4x_run_size_tests), ignore)] // Doesn't work on arbitrary Rust versions
fn $id() {
let size = core::mem::size_of::<$ty>();
let success = match option_env!("CI_TOOLCHAIN") {
Expand Down Expand Up @@ -67,7 +67,7 @@ macro_rules! size_test {
};
}
#[test]
#[cfg_attr(not(icu4x_run_size_tests), ignore)]
#[cfg_attr(not(icu4x_run_size_tests), ignore)] // Doesn't work on arbitrary Rust versions
fn $id() {
let size = core::mem::size_of::<$ty>();
let expected = $size;
Expand Down
20 changes: 10 additions & 10 deletions components/datetime/src/neo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ macro_rules! gen_any_buffer_constructors_with_external_loader {
&provider.as_downcasting(),
&ExternalLoaderAny(provider),
locale,
$($arg),+
$($arg.into()),+
)
}
#[doc = icu_provider::gen_any_buffer_unstable_docs!(BUFFER, Self::$compiled_fn)]
Expand All @@ -74,7 +74,7 @@ macro_rules! gen_any_buffer_constructors_with_external_loader {
&provider.as_deserializing(),
&ExternalLoaderBuffer(provider),
locale,
$($arg),+
$($arg.into()),+
)
}
};
Expand Down Expand Up @@ -394,7 +394,7 @@ impl<C: CldrCalendar, R: TypedDateTimeMarkers<C> + IsRuntimeComponents> TypedNeo
&crate::provider::Baked,
&ExternalLoaderCompiledData,
locale,
components,
components.into(),
length,
)
}
Expand Down Expand Up @@ -440,7 +440,7 @@ impl<C: CldrCalendar, R: TypedDateTimeMarkers<C> + IsRuntimeComponents> TypedNeo
provider,
&ExternalLoaderUnstable(provider),
locale,
components,
components.into(),
length,
)
}
Expand All @@ -451,7 +451,7 @@ impl<C: CldrCalendar, R: TypedDateTimeMarkers<C>> TypedNeoFormatter<C, R> {
provider: &P,
loader: &L,
locale: &DataLocale,
components: impl Into<NeoComponents>,
components: NeoComponents,
length: NeoSkeletonLength,
) -> Result<Self, LoadError>
where
Expand All @@ -478,7 +478,7 @@ impl<C: CldrCalendar, R: TypedDateTimeMarkers<C>> TypedNeoFormatter<C, R> {
&R::DateTimePatternV1Marker::bind(provider),
locale,
length,
components.into(),
components,
)
.map_err(LoadError::Data)?;
let mut names = RawDateTimeNames::new_without_fixed_decimal_formatter();
Expand Down Expand Up @@ -980,7 +980,7 @@ impl<R: DateTimeMarkers + IsRuntimeComponents> NeoFormatter<R> {
&crate::provider::Baked,
&ExternalLoaderCompiledData,
locale,
components,
components.into(),
length,
)
}
Expand Down Expand Up @@ -1081,7 +1081,7 @@ impl<R: DateTimeMarkers + IsRuntimeComponents> NeoFormatter<R> {
provider,
&ExternalLoaderUnstable(provider),
locale,
components,
components.into(),
length,
)
}
Expand All @@ -1092,7 +1092,7 @@ impl<R: DateTimeMarkers> NeoFormatter<R> {
provider: &P,
loader: &L,
locale: &DataLocale,
components: impl Into<NeoComponents>,
components: NeoComponents,
length: NeoSkeletonLength,
) -> Result<Self, LoadError>
where
Expand Down Expand Up @@ -1169,7 +1169,7 @@ impl<R: DateTimeMarkers> NeoFormatter<R> {
&R::DateTimePatternV1Marker::bind(provider),
locale,
length,
components.into(),
components,
)
.map_err(LoadError::Data)?;
let mut names = RawDateTimeNames::new_without_fixed_decimal_formatter();
Expand Down
10 changes: 9 additions & 1 deletion components/experimental/src/dimension/provider/pattern_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl AsULE for PatternKey {
PatternKey::Decimal(value) => {
let sign = if value < 0 { 0b0010_0000 } else { 0 };
debug_assert!(value > -32 && value < 32);
(0b01 << 6) | sign | (value as u8 & 0b0001_1111)
(0b01 << 6) | sign | (value.unsigned_abs() & 0b0001_1111)
}
PatternKey::Power { power, count } => {
let power_bits = {
Expand Down Expand Up @@ -230,6 +230,14 @@ fn test_pattern_key_ule() {
count: CompoundCount::Two,
}
);

let decimal_neg_1 = PatternKey::Decimal(-1);
let decimal_neg_1_ule = decimal_neg_1.to_unaligned();
assert_eq!(decimal_neg_1_ule.0, 0b0110_0001);

let decimal_neg_1 = PatternKey::from_unaligned(decimal_neg_1_ule);
assert_eq!(decimal_neg_1, PatternKey::Decimal(-1));

// Test invalid bytes
let unvalidated_bytes = [0b1100_0000];
assert_eq!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ mod tests {
}

#[test]
#[ignore] // not clear from the spec whether this test is correct
fn test_multi_3_initial_should_still_only_be_2() -> Result<(), PersonNamesFormatterError> {
let mut person_data = LiteMap::new();
person_data.insert(
Expand All @@ -127,7 +126,9 @@ mod tests {
};
let result =
super::derive_missing_initials(&person_name, &requested_field, "{0}.", "{0} {1}");
assert_eq!(result, "M. J.");

// TODO(#3077): broken, this should be equal
assert_ne!(result, "M. J.");
Ok(())
}
}
22 changes: 11 additions & 11 deletions components/icu/examples/tui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use icu::timezone::CustomTimeZone;
use icu_collections::codepointinvlist::CodePointInversionListBuilder;
use std::env;

fn print<T: AsRef<str>>(_input: T) {
#[cfg(debug_assertions)]
println!("{}", _input.as_ref());
#[cfg(not(debug_assertions))]
macro_rules! println {
($($arg:tt)*) => {};
}

#[no_mangle]
Expand All @@ -40,9 +40,9 @@ fn main(_argc: isize, _argv: *const *const u8) -> isize {
})
.unwrap_or(5);

print(format!("\nTextual User Interface Example ({locale})"));
print("===================================");
print(format!("User: {user_name}"));
println!("\nTextual User Interface Example ({locale})");
println!("===================================");
println!("User: {user_name}");

{
let dtf = TypedZonedDateTimeFormatter::<Gregorian>::try_new(
Expand All @@ -56,7 +56,7 @@ fn main(_argc: isize, _argv: *const *const u8) -> isize {

let formatted_dt = dtf.format(&today_date, &today_tz);

print(format!("Today is: {formatted_dt}"));
println!("Today is: {formatted_dt}");
}

{
Expand All @@ -68,9 +68,9 @@ fn main(_argc: isize, _argv: *const *const u8) -> isize {
let only_latin1 = user_name.chars().all(|ch| latin1_set.contains(ch));

if only_latin1 {
print("User name latin1 only: true");
println!("User name latin1 only: true");
} else {
print("User name latin1 only: false");
println!("User name latin1 only: false");
}
}

Expand All @@ -79,8 +79,8 @@ fn main(_argc: isize, _argv: *const *const u8) -> isize {
.expect("Failed to create PluralRules.");

match pr.category_for(email_count) {
PluralCategory::One => print("Note: You have one unread email."),
_ => print(format!("Note: You have {email_count} unread emails.")),
PluralCategory::One => println!("Note: You have one unread email."),
_ => println!("Note: You have {email_count} unread emails."),
}
}

Expand Down
10 changes: 4 additions & 6 deletions components/icu/src/datagen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ icu_registry::registry!(cb);
///
/// ```no_run
/// # use icu_provider::DataMarker;
/// # use std::path::Path;
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// assert_eq!(
/// icu::markers_for_bin("target/release/my-app")?,
/// icu::markers_for_bin(Path::new("target/release/my-app"))?,
/// std::collections::HashSet::from_iter([
/// icu::list::provider::AndListV2Marker::INFO,
/// icu::list::provider::OrListV2Marker::INFO,
Expand All @@ -82,11 +83,8 @@ icu_registry::registry!(cb);
/// # Ok(())
/// # }
/// ```
pub fn markers_for_bin<P: AsRef<Path>>(path: P) -> Result<HashSet<DataMarkerInfo>, DataError> {
let file = std::fs::read(path.as_ref())?;
let file = file.as_slice();

markers_for_bin_inner(file)
pub fn markers_for_bin(path: &Path) -> Result<HashSet<DataMarkerInfo>, DataError> {
markers_for_bin_inner(&std::fs::read(path)?)
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion components/segmenter/tests/css_word_break.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ fn wordbreak_keepall() {
}

#[test]
#[cfg_attr(not(feature = "lstm"), ignore)]
#[cfg(feature = "lstm")]
fn wordbreak_keepall_lstm() {
// from css/css-text/word-break/word-break-keep-all-003.html
let s = "และและ";
Expand Down
4 changes: 3 additions & 1 deletion ffi/capi/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ pub mod ffi {
Ok(Box::new(convert_buffer_provider(
icu_provider_fs::FsDataProvider::try_new(
// In the future we can start using OsString APIs to support non-utf8 paths
core::str::from_utf8(path).map_err(|_| ICU4XDataError::Io)?,
core::str::from_utf8(path)
.map_err(|_| ICU4XDataError::Io)?
.into(),
)?,
)))
}
Expand Down
Loading

0 comments on commit 0527aab

Please sign in to comment.