Skip to content

Commit

Permalink
Decouple fixture components bag from library components bag; remove s…
Browse files Browse the repository at this point in the history
…erde
  • Loading branch information
sffc committed Nov 13, 2024
1 parent 6c08d7f commit d7d46b6
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 16 deletions.
43 changes: 30 additions & 13 deletions components/datetime/benches/fixtures/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use icu_datetime::options::DateTimeFormatterOptions;
use icu_datetime::{neo_skeleton, options::components};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
Expand All @@ -22,8 +22,8 @@ pub struct TestInput {

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct TestOptions {
pub length: Option<icu_datetime::options::length::Bag>,
pub components: Option<icu_datetime::options::components::Bag>,
pub length: Option<TestOptionsLength>,
pub components: Option<TestComponentsBag>,
pub semantic: Option<icu_datetime::fieldset::dynamic::CompositeFieldSet>,
pub preferences: Option<icu_datetime::options::preferences::Bag>,
}
Expand All @@ -47,15 +47,32 @@ pub enum TestLength {
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PatternsFixture(pub Vec<String>);
pub struct TestComponentsBag {
pub era: Option<components::Text>,
pub year: Option<components::Year>,
pub month: Option<components::Month>,
pub week: Option<components::Week>,
pub day: Option<components::Day>,
pub weekday: Option<components::Text>,

pub hour: Option<components::Numeric>,
pub minute: Option<components::Numeric>,
pub second: Option<components::Numeric>,
pub fractional_second: Option<neo_skeleton::FractionalSecondDigits>,

pub time_zone_name: Option<components::TimeZoneName>,

#[allow(dead_code)]
pub fn get_options(input: &TestOptions) -> Option<DateTimeFormatterOptions> {
if let Some(bag) = input.length {
return Some(bag.into());
}
if let Some(bag) = input.components {
return Some(bag.into());
}
None
pub hour_cycle: Option<TestHourCycle>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum TestHourCycle {
H11,
H12,
H23,
H24,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PatternsFixture(pub Vec<String>);
1 change: 0 additions & 1 deletion components/datetime/src/options/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ use serde::{Deserialize, Serialize};
/// <a href="https://github.com/unicode-org/icu4x/issues/1317">#1317</a>
/// </div>
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[non_exhaustive]
pub struct Bag {
/// Include the era, such as "AD" or "CE".
Expand Down
51 changes: 49 additions & 2 deletions components/datetime/tests/fixtures/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#![cfg(feature = "serde")]

use icu_datetime::{neo_skeleton, options::components};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

Expand All @@ -25,12 +26,58 @@ pub struct TestInput {

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct TestOptions {
pub length: Option<icu_datetime::options::length::Bag>,
pub components: Option<icu_datetime::options::components::Bag>,
pub length: Option<TestOptionsLength>,
pub components: Option<TestComponentsBag>,
pub semantic: Option<icu_datetime::fieldset::dynamic::CompositeFieldSet>,
pub preferences: Option<icu_datetime::options::preferences::Bag>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct TestOptionsLength {
pub date: Option<TestLength>,
pub time: Option<TestLength>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum TestLength {
#[serde(rename = "short")]
Short,
#[serde(rename = "medium")]
Medium,
#[serde(rename = "long")]
Long,
#[serde(rename = "full")]
Full,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct TestComponentsBag {
pub era: Option<components::Text>,
pub year: Option<components::Year>,
pub month: Option<components::Month>,
pub week: Option<components::Week>,
pub day: Option<components::Day>,
pub weekday: Option<components::Text>,

pub hour: Option<components::Numeric>,
pub minute: Option<components::Numeric>,
pub second: Option<components::Numeric>,
pub fractional_second: Option<neo_skeleton::FractionalSecondDigits>,

pub time_zone_name: Option<components::TimeZoneName>,

pub hour_cycle: Option<TestHourCycle>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum TestHourCycle {
H11,
H12,
H23,
H24,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct TestOutput {
// Key is locale, and value is expected test output.
Expand Down

0 comments on commit d7d46b6

Please sign in to comment.