forked from unicode-org/icu4x
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement PluralRulesWithRanges component (unicode-org#4116)
- Loading branch information
Showing
15 changed files
with
986 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// This file is part of ICU4X. For terms of use, please see the file | ||
// called LICENSE at the top level of the ICU4X source tree | ||
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). | ||
|
||
use icu_locid::locale; | ||
use icu_plurals::{PluralCategory, PluralOperands, PluralRuleType, PluralRulesWithRanges}; | ||
|
||
#[test] | ||
fn test_plural_ranges_raw() { | ||
assert_eq!( | ||
PluralRulesWithRanges::try_new_cardinal(&locale!("he").into()) | ||
.unwrap() | ||
.resolve_range(PluralCategory::One, PluralCategory::Two), | ||
PluralCategory::Other | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_plural_ranges_optimized_data() { | ||
assert_eq!( | ||
PluralRulesWithRanges::try_new_ordinal(&locale!("en").into()) | ||
.unwrap() | ||
.resolve_range(PluralCategory::One, PluralCategory::Other), | ||
PluralCategory::Other | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_plural_ranges_missing_data_fallback() { | ||
assert_eq!( | ||
PluralRulesWithRanges::try_new_cardinal(&locale!("nl").into()) | ||
.unwrap() | ||
.resolve_range(PluralCategory::Two, PluralCategory::Many), | ||
PluralCategory::Many | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_plural_ranges_full() { | ||
let ranges = | ||
PluralRulesWithRanges::try_new(&locale!("sl").into(), PluralRuleType::Cardinal).unwrap(); | ||
let start: PluralOperands = "0.5".parse().unwrap(); // PluralCategory::Other | ||
let end: PluralOperands = PluralOperands::try_from(1).unwrap(); // PluralCategory::One | ||
|
||
assert_eq!(ranges.category_for_range(start, end), PluralCategory::Few) | ||
} |
Oops, something went wrong.