Skip to content

Commit

Permalink
Review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc committed Jan 5, 2021
1 parent 43cd00c commit ef00581
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 98 deletions.
12 changes: 11 additions & 1 deletion components/provider/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,25 @@ include = [
# Serialize None values when exporting. Required for Bincode.
serialize_none = []

# Include the HelloWorldProvider, useful for unit testing.
hello_world = ["icu_locid_macros"]

[dependencies]
icu_locid = { version = "0.1", path = "../locid" }
tinystr = "0.4"
erased-serde = "0.3"
smallstr = { version = "0.2", features = ["serde"] }
downcast-rs = "1.2"
serde = { version = "1.0", features = ["derive"] }
icu_locid_macros = { version = "0.1", path = "../locid/macros" }

# For feature "hello_world"
icu_locid_macros = { version = "0.1", path = "../locid/macros", optional = true }

[dev-dependencies]
serde_json = "1.0"
static_assertions = "1.1"
icu_locid_macros = { version = "0.1", path = "../locid/macros" }

[[test]]
name = "iteration"
required-features = ["hello_world"]
47 changes: 26 additions & 21 deletions components/provider/src/inv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,29 +65,34 @@ impl IterableDataProvider<'_> for InvariantDataProvider {
}
}

#[test]
fn test_invariant() {
use crate::structs;
let provider = InvariantDataProvider;
#[cfg(test)]
mod tests {
use super::*;

let data1: Cow<structs::icu4x::HelloWorldV1> = provider
.load_payload(&DataRequest::from(structs::icu4x::key::HELLO_WORLD_V1))
.unwrap()
.take_payload()
.unwrap();
#[test]
fn test_invariant() {
use crate::structs;
let provider = InvariantDataProvider;

let data2: Cow<structs::icu4x::HelloWorldV1> = (&provider as &dyn ErasedDataProvider)
.load_payload(&DataRequest::from(structs::icu4x::key::HELLO_WORLD_V1))
.unwrap()
.take_payload()
.unwrap();
let data1: Cow<structs::icu4x::HelloWorldV1> = provider
.load_payload(&DataRequest::from(structs::icu4x::key::HELLO_WORLD_V1))
.unwrap()
.take_payload()
.unwrap();

assert_eq!(
&*data1,
&structs::icu4x::HelloWorldV1 {
message: Cow::Borrowed("(und) Hello World")
}
);
let data2: Cow<structs::icu4x::HelloWorldV1> = (&provider as &dyn ErasedDataProvider)
.load_payload(&DataRequest::from(structs::icu4x::key::HELLO_WORLD_V1))
.unwrap()
.take_payload()
.unwrap();

assert_eq!(data1, data2);
assert_eq!(
&*data1,
&structs::icu4x::HelloWorldV1 {
message: Cow::Borrowed("(und) Hello World")
}
);

assert_eq!(data1, data2);
}
}
1 change: 1 addition & 0 deletions components/provider/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ pub mod data_provider;
pub mod resource;
#[macro_use]
pub mod erased;
#[cfg(feature = "hello_world")]
pub mod hello_world;
pub mod inv;
pub mod iter;
Expand Down
156 changes: 80 additions & 76 deletions components/provider/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,88 +305,92 @@ pub struct ResourcePath {
pub options: ResourceOptions,
}

#[test]
fn test_entry_to_string() {
#[cfg(test)]
mod tests {
use super::*;
use tinystr::tinystr4;
struct TestCase {
pub resc_key: ResourceKey,
pub expected: &'static str,
}
let cases = [
TestCase {
resc_key: resource_key!(plurals, "cardinal", 1),
expected: "plurals/cardinal@1",
},
TestCase {
resc_key: ResourceKey {
category: ResourceCategory::PrivateUse(tinystr4!("priv")),
sub_category: tinystr16!("cardinal"),
version: 1,

#[test]
fn test_entry_to_string() {
struct TestCase {
pub resc_key: ResourceKey,
pub expected: &'static str,
}
let cases = [
TestCase {
resc_key: resource_key!(plurals, "cardinal", 1),
expected: "plurals/cardinal@1",
},
TestCase {
resc_key: ResourceKey {
category: ResourceCategory::PrivateUse(tinystr4!("priv")),
sub_category: tinystr16!("cardinal"),
version: 1,
},
expected: "x-priv/cardinal@1",
},
TestCase {
resc_key: resource_key!(plurals, "maxlengthsubcatg", 1),
expected: "plurals/maxlengthsubcatg@1",
},
TestCase {
resc_key: resource_key!(plurals, "cardinal", 2147483647),
expected: "plurals/cardinal@2147483647",
},
expected: "x-priv/cardinal@1",
},
TestCase {
resc_key: resource_key!(plurals, "maxlengthsubcatg", 1),
expected: "plurals/maxlengthsubcatg@1",
},
TestCase {
resc_key: resource_key!(plurals, "cardinal", 2147483647),
expected: "plurals/cardinal@2147483647",
},
];
for cas in cases.iter() {
assert_eq!(cas.expected, cas.resc_key.to_string());
assert_eq!(
cas.expected,
cas.resc_key
.get_components()
.iter()
.collect::<Vec<&str>>()
.join("/")
);
];
for cas in cases.iter() {
assert_eq!(cas.expected, cas.resc_key.to_string());
assert_eq!(
cas.expected,
cas.resc_key
.get_components()
.iter()
.collect::<Vec<&str>>()
.join("/")
);
}
}
}

#[test]
fn test_key_to_string() {
use icu_locid_macros::langid;

struct TestCase {
pub resc_options: ResourceOptions,
pub expected: &'static str,
}
let cases = [
TestCase {
resc_options: ResourceOptions {
variant: None,
langid: Some(LanguageIdentifier::default()),
#[test]
fn test_key_to_string() {
use icu_locid_macros::langid;
struct TestCase {
pub resc_options: ResourceOptions,
pub expected: &'static str,
}
let cases = [
TestCase {
resc_options: ResourceOptions {
variant: None,
langid: Some(LanguageIdentifier::default()),
},
expected: "und",
},
expected: "und",
},
TestCase {
resc_options: ResourceOptions {
variant: Some(Cow::Borrowed("GBP")),
langid: Some(LanguageIdentifier::default()),
TestCase {
resc_options: ResourceOptions {
variant: Some(Cow::Borrowed("GBP")),
langid: Some(LanguageIdentifier::default()),
},
expected: "GBP/und",
},
expected: "GBP/und",
},
TestCase {
resc_options: ResourceOptions {
variant: Some(Cow::Borrowed("GBP")),
langid: Some(langid!("en-ZA")),
TestCase {
resc_options: ResourceOptions {
variant: Some(Cow::Borrowed("GBP")),
langid: Some(langid!("en-ZA")),
},
expected: "GBP/en-ZA",
},
expected: "GBP/en-ZA",
},
];
for cas in cases.iter() {
assert_eq!(cas.expected, cas.resc_options.to_string());
assert_eq!(
cas.expected,
cas.resc_options
.get_components()
.iter()
.collect::<Vec<&str>>()
.join("/")
);
];
for cas in cases.iter() {
assert_eq!(cas.expected, cas.resc_options.to_string());
assert_eq!(
cas.expected,
cas.resc_options
.get_components()
.iter()
.collect::<Vec<&str>>()
.join("/")
);
}
}
}
1 change: 1 addition & 0 deletions components/provider_fs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ simple_logger = { version = "1.11", optional = true }

[dev-dependencies]
icu_locid_macros = { version = "0.1", path = "../locid/macros" }
icu_provider = { version = "0.1", path = "../provider", features = ["hello_world"] }
criterion = "0.3.3"

[features]
Expand Down
1 change: 1 addition & 0 deletions components/provider_fs/benches/provider_fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};

use icu_locid_macros::langid;
#[cfg(feature = "bench")]
use icu_provider::erased::*;
use icu_provider::prelude::*;
use icu_provider::structs;
Expand Down

0 comments on commit ef00581

Please sign in to comment.