Skip to content

Commit

Permalink
Use the right mask for case level (#2892)
Browse files Browse the repository at this point in the history
* Use the right mask for case level

Fixes #2884
  • Loading branch information
hsivonen authored Dec 16, 2022
1 parent 356bfa8 commit 856b3dc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
8 changes: 4 additions & 4 deletions components/collator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions components/collator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion components/collator/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions components/collator/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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_eq!(
collator_with_case.compare("aA", "Aa"),
core::cmp::Ordering::Less
);
}

// TODO: Test languages that map to the root.
// The languages that map to root without script reordering are:
// ca (at least for now)
Expand Down

0 comments on commit 856b3dc

Please sign in to comment.