| 1 |
// This file is part of ICU4X. For terms of use, please see the file |
| 2 |
// called LICENSE at the top level of the ICU4X source tree |
| 3 |
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). |
| 4 |
|
| 5 |
use icu_locale_core::locale; |
| 6 |
use icu_plurals::{PluralCategory, PluralOperands, PluralRulesWithRanges}; |
| 7 |
|
| 8 |
#[test] |
| 9 |
fn test_plural_ranges_raw() { |
| 10 |
assert_eq!( |
| 11 |
PluralRulesWithRanges::try_new_cardinal(locale!("he").into()) |
| 12 |
.unwrap() |
| 13 |
.resolve_range(PluralCategory::One, PluralCategory::Two), |
| 14 |
PluralCategory::Other |
| 15 |
); |
| 16 |
} |
| 17 |
|
| 18 |
#[test] |
| 19 |
fn test_plural_ranges_optimized_data() { |
| 20 |
assert_eq!( |
| 21 |
PluralRulesWithRanges::try_new_ordinal(locale!("en").into()) |
| 22 |
.unwrap() |
| 23 |
.resolve_range(PluralCategory::One, PluralCategory::Other), |
| 24 |
PluralCategory::Other |
| 25 |
); |
| 26 |
} |
| 27 |
|
| 28 |
#[test] |
| 29 |
fn test_plural_ranges_missing_data_fallback() { |
| 30 |
assert_eq!( |
| 31 |
PluralRulesWithRanges::try_new_cardinal(locale!("nl").into()) |
| 32 |
.unwrap() |
| 33 |
.resolve_range(PluralCategory::Two, PluralCategory::Many), |
| 34 |
PluralCategory::Many |
| 35 |
); |
| 36 |
} |
| 37 |
|
| 38 |
#[test] |
| 39 |
fn test_plural_ranges_full() { |
| 40 |
let ranges = PluralRulesWithRanges::try_new(locale!("sl").into(), Default::default()).unwrap(); |
| 41 |
let start: PluralOperands = "0.5".parse().unwrap(); // PluralCategory::Other |
| 42 |
let end: PluralOperands = PluralOperands::from(1); // PluralCategory::One |
| 43 |
|
| 44 |
assert_eq!(ranges.category_for_range(start, end), PluralCategory::Few) |
| 45 |
} |