Skip to content

Commit

Permalink
Use icu_testdata
Browse files Browse the repository at this point in the history
  • Loading branch information
zbraniecki committed Oct 9, 2020
1 parent 45aae6a commit 3572b08
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 33 deletions.
2 changes: 1 addition & 1 deletion components/datetime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ icu-data-provider = { path = "../data-provider" }
[dev-dependencies]
criterion = "0.3"
icu-data-provider = { path = "../data-provider", features = ["invariant"] }
icu-fs-data-provider = { path = "../fs-data-provider" }
icu-testdata = { path = "../../resources/testdata" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

Expand Down
4 changes: 1 addition & 3 deletions components/datetime/benches/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ use std::fmt::Write;

use icu_datetime::DateTimeFormat;
use icu_datetime::MockDateTime;
use icu_fs_data_provider::FsDataProvider;

fn datetime_benches(c: &mut Criterion) {
let fxs = fixtures::get_fixture("styles").unwrap();

let provider = FsDataProvider::try_new("../../resources/testdata/data/json")
.expect("Loading file from testdata directory");
let provider = icu_testdata::get_provider();

{
let mut group = c.benchmark_group("datetime");
Expand Down
4 changes: 1 addition & 3 deletions components/datetime/examples/work_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// from a work log into human readable dates and times.
use icu_datetime::date::MockDateTime;
use icu_datetime::{options::style, DateTimeFormat};
use icu_fs_data_provider::FsDataProvider;
use icu_locale::LanguageIdentifier;

const DATES_ISO: &[&str] = &[
Expand Down Expand Up @@ -30,8 +29,7 @@ fn print(_input: &str, _value: Option<usize>) {
fn main() {
let langid: LanguageIdentifier = "en".parse().expect("Failed to parse Language Identifier.");

let provider = FsDataProvider::try_new("../../resources/testdata/data/json")
.expect("Loading file from testdata directory");
let provider = icu_testdata::get_provider();

let dates = DATES_ISO
.iter()
Expand Down
4 changes: 1 addition & 3 deletions components/datetime/tests/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ mod fixtures;

use icu_datetime::DateTimeFormat;
use icu_datetime::MockDateTime;
use icu_fs_data_provider::FsDataProvider;
use std::fmt::Write;

#[test]
fn test_fixtures() {
let provider = FsDataProvider::try_new("../../resources/testdata/data/json")
.expect("Loading file from testdata directory");
let provider = icu_testdata::get_provider();

for fx in fixtures::get_fixture("styles").unwrap().0 {
let langid = fx.input.locale.parse().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion components/pluralrules/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = {version = "1.0" }
icu-locale = { path = "../locale", features = ["serde"] }
icu-data-provider = { path = "../data-provider", features = ["invariant"] }
icu-fs-data-provider = { path = "../fs-data-provider" }
icu-testdata = { path = "../../resources/testdata" }

[features]
default = []
Expand Down
2 changes: 1 addition & 1 deletion components/pluralrules/benches/fixtures/plurals.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"langs": ["be", "bn", "en", "fa", "fr", "und", "zh"]
"langs": ["ar", "be", "bn", "en", "es", "fr", "ja", "sr", "th", "tr"]
}
4 changes: 1 addition & 3 deletions components/pluralrules/benches/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ mod helpers;
use criterion::{black_box, criterion_group, criterion_main, Criterion};

use icu_data_provider::{icu_data_key, structs, DataEntry, DataProvider, DataRequest};
use icu_fs_data_provider::FsDataProvider;
use std::borrow::Cow;

fn parser(c: &mut Criterion) {
use icu_pluralrules::rules::parse_condition;

let plurals_data = helpers::get_plurals_data();

let provider = FsDataProvider::try_new("../../resources/testdata/data/json")
.expect("Loading file from testdata directory");
let provider = icu_testdata::get_provider();

let mut rules = vec![];

Expand Down
4 changes: 1 addition & 3 deletions components/pluralrules/benches/pluralrules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ mod helpers;

use criterion::{criterion_group, criterion_main, Criterion};

use icu_fs_data_provider::FsDataProvider;
use icu_pluralrules::{PluralRuleType, PluralRules};

fn pluralrules(c: &mut Criterion) {
let plurals_data = helpers::get_plurals_data();
let numbers_data = helpers::get_numbers_data();

let provider = FsDataProvider::try_new("../../resources/testdata/data/json")
.expect("Loading file from testdata directory");
let provider = icu_testdata::get_provider();

c.bench_function("pluralrules/overview", |b| {
b.iter(|| {
Expand Down
7 changes: 3 additions & 4 deletions components/pluralrules/examples/elevator_floors.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// An example application which uses icu_pluralrules to construct a correct
// sentence for English based on the numerical value in Ordinal category.
use icu_fs_data_provider::FsDataProvider;
use icu_locale::LanguageIdentifier;
use icu_pluralrules::{PluralCategory, PluralRuleType, PluralRules};

Expand All @@ -17,12 +16,12 @@ fn print(_input: &str, _value: Option<usize>) {

fn main() {
let langid: LanguageIdentifier = "en".parse().expect("Failed to parse Language Identifier.");
let dtp = FsDataProvider::try_new("../../resources/testdata/data/json")
.expect("Loading file from testdata directory");

let provider = icu_testdata::get_provider();

{
print("\n====== Elevator Floor (en) example ============", None);
let pr = PluralRules::try_new(langid, &dtp, PluralRuleType::Ordinal)
let pr = PluralRules::try_new(langid, &provider, PluralRuleType::Ordinal)
.expect("Failed to create a PluralRules instance.");

for value in VALUES {
Expand Down
6 changes: 2 additions & 4 deletions components/pluralrules/examples/unread_emails.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// An example application which uses icu_pluralrules to construct a correct
// sentence for English based on the numerical value in Cardinal category.
use icu_fs_data_provider::FsDataProvider;
use icu_locale::LanguageIdentifier;
use icu_pluralrules::{PluralCategory, PluralRuleType, PluralRules};

Expand All @@ -17,12 +16,11 @@ fn print(_input: &str, _value: Option<usize>) {

fn main() {
let langid: LanguageIdentifier = "en".parse().expect("Failed to parse Language Identifier.");
let dtp = FsDataProvider::try_new("../../resources/testdata/data/json")
.expect("Loading file from testdata directory");
let provider = icu_testdata::get_provider();

{
print("\n====== Unread Emails (en) example ============", None);
let pr = PluralRules::try_new(langid, &dtp, PluralRuleType::Cardinal)
let pr = PluralRules::try_new(langid, &provider, PluralRuleType::Cardinal)
.expect("Failed to create a PluralRules instance.");

for value in VALUES {
Expand Down
11 changes: 4 additions & 7 deletions components/pluralrules/tests/plurals.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
use icu_fs_data_provider::FsDataProvider;
use icu_locale::LanguageIdentifier;
use icu_pluralrules::{PluralCategory, PluralRuleType, PluralRules};

#[test]
fn test_plural_rules() {
let dp = FsDataProvider::try_new("../../resources/testdata/data/json")
.expect("Loading file from testdata directory");
let provider = icu_testdata::get_provider();

let lang: LanguageIdentifier = "en".parse().unwrap();

let pr = PluralRules::try_new(lang, &dp, PluralRuleType::Cardinal).unwrap();
let pr = PluralRules::try_new(lang, &provider, PluralRuleType::Cardinal).unwrap();

assert_eq!(pr.select(5_usize), PluralCategory::Other);
}

#[test]
fn test_plural_rules_missing() {
let dp = FsDataProvider::try_new("../../resources/testdata/data/json")
.expect("Loading file from testdata directory");
let provider = icu_testdata::get_provider();

let lang: LanguageIdentifier = "xx".parse().unwrap();

let pr = PluralRules::try_new(lang, &dp, PluralRuleType::Cardinal);
let pr = PluralRules::try_new(lang, &provider, PluralRuleType::Cardinal);

assert!(pr.is_err());
}
Expand Down

0 comments on commit 3572b08

Please sign in to comment.