Skip to content

Commit

Permalink
Add PPUCD enumerated property parsing (#448)
Browse files Browse the repository at this point in the history
  • Loading branch information
echeran authored Mar 25, 2021
1 parent 7c82cb3 commit 30a3909
Show file tree
Hide file tree
Showing 19 changed files with 9,719 additions and 427 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion components/provider_ppucd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ skip_optional_dependencies = true
icu_locid = { version = "0.1", path = "../locid" }
icu_provider = { version = "0.1", path = "../provider" }
icu_locid_macros = { version = "0.1", path = "../locid/macros" }
tinystr = "0.4"
icu_uniset = { version = "0.1", path = "../uniset" }
tinystr = "0.4"
862 changes: 862 additions & 0 deletions components/provider_ppucd/src/enum_prop_mapping.rs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions components/provider_ppucd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

pub mod enum_prop_mapping;
mod error;
pub mod parse_ppucd;
pub mod support;
759 changes: 716 additions & 43 deletions components/provider_ppucd/src/parse_ppucd.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion components/provider_ppucd/src/support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fn test_ppucd_provider_parse() {
let ppucd_provider: PpucdDataProvider = PpucdDataProvider::new(&ppucd_property_file_str);
let data_req = DataRequest {
resource_path: ResourcePath {
key: key::WSPACE_V1,
key: key::WHITE_SPACE_V1,
options: ResourceOptions {
variant: None,
langid: None,
Expand Down
35 changes: 34 additions & 1 deletion components/provider_ppucd/tests/props_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,51 @@
#![allow(clippy::unreadable_literal, dead_code)]

use icu_provider_ppucd::support::*;
use icu_uniset::enum_props::*;
use icu_uniset::UnicodeSet;

#[test]
fn test_wspace_getter() {
let ppucd_property_files_root_path = "tests/testdata/ppucd-wspace-test.txt";
let ppucd_property_file_str = std::fs::read_to_string(ppucd_property_files_root_path).unwrap();
let ppucd_provider: PpucdDataProvider = PpucdDataProvider::new(&ppucd_property_file_str);
let wspace_uniset: UnicodeSet = icu_uniset::props::wspace(&ppucd_provider).unwrap();
let wspace_uniset: UnicodeSet =
icu_uniset::props::get_white_space_property(&ppucd_provider).unwrap();
let exp_uniset: UnicodeSet = UnicodeSet::from_inversion_list(vec![
9, 14, 32, 33, 133, 134, 160, 161, 5760, 5761, 8192, 8203, 8232, 8234, 8239, 8240, 8287,
8288, 12288, 12289,
])
.unwrap();
assert_eq!(wspace_uniset, exp_uniset);
}

#[test]
fn test_enum_props_getters() {
let ppucd_property_files_root_path = "tests/testdata/ppucd-enum-props-test.txt";
let ppucd_property_file_str = std::fs::read_to_string(ppucd_property_files_root_path).unwrap();
let ppucd_provider: PpucdDataProvider = PpucdDataProvider::new(&ppucd_property_file_str);

// lb=LF
let lb_lf_uniset: UnicodeSet =
icu_uniset::props::get_line_break_val_set(&ppucd_provider, LineBreak::LineFeed).unwrap();
let exp_lb_lf_uniset: UnicodeSet = UnicodeSet::from_inversion_list(vec![10, 11]).unwrap();
assert_eq!(lb_lf_uniset, exp_lb_lf_uniset);
}

#[test]
fn test_enum_props_getters_truncated_resc_key_subcategory() {
let ppucd_property_files_root_path = "tests/testdata/ppucd-inpc-topbotleft-test.txt";
let ppucd_property_file_str = std::fs::read_to_string(ppucd_property_files_root_path).unwrap();
let ppucd_provider: PpucdDataProvider = PpucdDataProvider::new(&ppucd_property_file_str);

// InPC=Top_And_Bottom_And_Left
let inpc_topbotleft_uniset: UnicodeSet =
icu_uniset::props::get_indic_positional_category_val_set(
&ppucd_provider,
IndicPositionalCategory::TopAndBottomAndLeft,
)
.unwrap();
let exp_inpc_topbotleft_uniset: UnicodeSet =
UnicodeSet::from_inversion_list(vec![4156, 4157, 71454, 71455]).unwrap();
assert_eq!(inpc_topbotleft_uniset, exp_inpc_topbotleft_uniset);
}
Loading

0 comments on commit 30a3909

Please sign in to comment.