Skip to content

Commit

Permalink
Implement FFI interface for PluralRanges
Browse files Browse the repository at this point in the history
  • Loading branch information
jedel1043 committed Oct 5, 2023
1 parent 42de871 commit a9b2eb4
Show file tree
Hide file tree
Showing 14 changed files with 385 additions and 3 deletions.
4 changes: 2 additions & 2 deletions components/plurals/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,8 @@ impl PluralRules {
}
}

/// A struct which provides the ability to retrieve an appropriate [`Plural Category`] for a number
/// range from the categories of its endpoints.
/// A struct which provides the ability to retrieve an appropriate [`Plural Category`] for a range
/// from the categories of its endpoints.
///
/// # Examples
///
Expand Down
36 changes: 36 additions & 0 deletions components/plurals/tests/ranges.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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, PluralRanges};

#[test]
fn test_plural_ranges() {
assert_eq!(
PluralRanges::try_new(&locale!("he").into())
.unwrap()
.category_for_range(PluralCategory::One, PluralCategory::Two),
PluralCategory::Other
);
}

#[test]
fn test_plural_ranges_optimized_data() {
assert_eq!(
PluralRanges::try_new(&locale!("en").into())
.unwrap()
.category_for_range(PluralCategory::One, PluralCategory::Other),
PluralCategory::Other
);
}

#[test]
fn test_plural_ranges_missing_data_fallback() {
assert_eq!(
PluralRanges::try_new(&locale!("nl").into())
.unwrap()
.category_for_range(PluralCategory::Two, PluralCategory::Many),
PluralCategory::Many
);
}
35 changes: 35 additions & 0 deletions ffi/diplomat/c/include/ICU4XPluralRanges.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions ffi/diplomat/cpp/docs/source/pluralrules_ffi.rst

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions ffi/diplomat/cpp/include/ICU4XPluralRanges.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 76 additions & 0 deletions ffi/diplomat/cpp/include/ICU4XPluralRanges.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions ffi/diplomat/js/docs/source/pluralrules_ffi.rst

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions ffi/diplomat/js/include/ICU4XPluralRanges.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions ffi/diplomat/js/include/ICU4XPluralRanges.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ffi/diplomat/js/include/index.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ffi/diplomat/js/include/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a9b2eb4

Please sign in to comment.