From c2efefc77b2af793520eefd431e50de257c56cc1 Mon Sep 17 00:00:00 2001 From: Henri Sivonen Date: Thu, 15 Dec 2022 15:58:46 +0200 Subject: [PATCH 1/2] Use the right mask for case level Fixes #2884 --- components/collator/src/lib.rs | 8 ++++---- components/collator/src/options.rs | 2 +- components/collator/tests/tests.rs | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/components/collator/src/lib.rs b/components/collator/src/lib.rs index adcfef15a88..523f4f3cf10 100644 --- a/components/collator/src/lib.rs +++ b/components/collator/src/lib.rs @@ -226,8 +226,8 @@ //! &Default::default(), //! options).unwrap(); //! -//! assert_eq!(primary_and_case.compare("ⓓⓔⓐⓛ", "DEAL"), Ordering::Equal); -//! assert_eq!(primary_and_case.compare("dejavu", "dejAvu"), Ordering::Equal); +//! assert_eq!(primary_and_case.compare("ⓓⓔⓐⓛ", "DEAL"), Ordering::Less); +//! assert_eq!(primary_and_case.compare("dejavu", "dejAvu"), Ordering::Less); //! assert_eq!(primary_and_case.compare("dejavu", "déjavu"), Ordering::Equal); //! //! // Secondary with case level on @@ -239,8 +239,8 @@ //! &Default::default(), //! options).unwrap(); //! -//! assert_eq!(secondary_and_case.compare("ⓓⓔⓐⓛ", "DEAL"), Ordering::Equal); -//! assert_eq!(secondary_and_case.compare("dejavu", "dejAvu"), Ordering::Equal); +//! assert_eq!(secondary_and_case.compare("ⓓⓔⓐⓛ", "DEAL"), Ordering::Less); +//! assert_eq!(secondary_and_case.compare("dejavu", "dejAvu"), Ordering::Less); //! assert_eq!(secondary_and_case.compare("dejavu", "déjavu"), Ordering::Less); // secondary difference //! //! // Tertiary diff --git a/components/collator/src/options.rs b/components/collator/src/options.rs index fae093715e5..7d948b88938 100644 --- a/components/collator/src/options.rs +++ b/components/collator/src/options.rs @@ -510,7 +510,7 @@ impl CollatorOptionsBitField { if let Some(case_level) = case_level { self.0 |= CollatorOptionsBitField::EXPLICIT_CASE_LEVEL_MASK; if case_level { - self.0 |= CollatorOptionsBitField::ALTERNATE_HANDLING_MASK; + self.0 |= CollatorOptionsBitField::CASE_LEVEL_MASK; } } else { self.0 &= !CollatorOptionsBitField::EXPLICIT_CASE_LEVEL_MASK; diff --git a/components/collator/tests/tests.rs b/components/collator/tests/tests.rs index d96cf86d87a..2cb7c77b8f8 100644 --- a/components/collator/tests/tests.rs +++ b/components/collator/tests/tests.rs @@ -1404,6 +1404,20 @@ fn test_conformance_non_ignorable() { } } +#[test] +fn test_case_level() { + let mut options = CollatorOptions::new(); + options.strength = Some(Strength::Primary); + options.case_level = Some(CaseLevel::On); + let collator_with_case = + Collator::try_new_unstable(&icu_testdata::unstable(), &Default::default(), options) + .unwrap(); + assert_ne!( + collator_with_case.compare("aA", "Aa"), + core::cmp::Ordering::Equal + ); +} + // TODO: Test languages that map to the root. // The languages that map to root without script reordering are: // ca (at least for now) From 5a8e4abb189b6bdc29b8aca677e9b1268aba8586 Mon Sep 17 00:00:00 2001 From: Henri Sivonen Date: Fri, 16 Dec 2022 11:02:31 +0200 Subject: [PATCH 2/2] Regenerate README and use assert_eq instead of assert_ne --- components/collator/README.md | 8 ++++---- components/collator/tests/tests.rs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/components/collator/README.md b/components/collator/README.md index 459c4ec9a04..f44fb3a03ca 100644 --- a/components/collator/README.md +++ b/components/collator/README.md @@ -204,8 +204,8 @@ let primary_and_case = &Default::default(), options).unwrap(); -assert_eq!(primary_and_case.compare("ⓓⓔⓐⓛ", "DEAL"), Ordering::Equal); -assert_eq!(primary_and_case.compare("dejavu", "dejAvu"), Ordering::Equal); +assert_eq!(primary_and_case.compare("ⓓⓔⓐⓛ", "DEAL"), Ordering::Less); +assert_eq!(primary_and_case.compare("dejavu", "dejAvu"), Ordering::Less); assert_eq!(primary_and_case.compare("dejavu", "déjavu"), Ordering::Equal); // Secondary with case level on @@ -217,8 +217,8 @@ let secondary_and_case = &Default::default(), options).unwrap(); -assert_eq!(secondary_and_case.compare("ⓓⓔⓐⓛ", "DEAL"), Ordering::Equal); -assert_eq!(secondary_and_case.compare("dejavu", "dejAvu"), Ordering::Equal); +assert_eq!(secondary_and_case.compare("ⓓⓔⓐⓛ", "DEAL"), Ordering::Less); +assert_eq!(secondary_and_case.compare("dejavu", "dejAvu"), Ordering::Less); assert_eq!(secondary_and_case.compare("dejavu", "déjavu"), Ordering::Less); // secondary difference // Tertiary diff --git a/components/collator/tests/tests.rs b/components/collator/tests/tests.rs index 2cb7c77b8f8..15fc10296b5 100644 --- a/components/collator/tests/tests.rs +++ b/components/collator/tests/tests.rs @@ -1412,9 +1412,9 @@ fn test_case_level() { let collator_with_case = Collator::try_new_unstable(&icu_testdata::unstable(), &Default::default(), options) .unwrap(); - assert_ne!( + assert_eq!( collator_with_case.compare("aA", "Aa"), - core::cmp::Ordering::Equal + core::cmp::Ordering::Less ); }