Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Components bag support with only skeleton matching #587

Merged
merged 9 commits into from
Apr 8, 2021

Conversation

gregtatum
Copy link
Member

This is a minimal implementation of the UTS 35 skeleton matching algorithm. It will find the best skeleton in the available formats, but it will not modify the final pattern to make it better suit the components::Bag. These modifications I have filed as the follow-ups: #584, #585, #586.

Resolves #481. (Note that this is a scoped down version of that PR, with the follow-ups listed above.)

@gregtatum gregtatum requested review from zbraniecki and sffc March 29, 2021 21:46
@gregtatum gregtatum requested a review from a team as a code owner March 29, 2021 21:46
@coveralls
Copy link

coveralls commented Mar 29, 2021

Pull Request Test Coverage Report for Build 0a17f5e58cc46a2a2c207e419acc181a3d1f8ff8-PR-587

  • 245 of 299 (81.94%) changed or added relevant lines in 7 files are covered.
  • 13 unchanged lines in 7 files lost coverage.
  • Overall coverage increased (+0.4%) to 73.077%

Changes Missing Coverage Covered Lines Changed/Added Lines %
components/datetime/src/error.rs 0 1 0.0%
components/datetime/src/provider/helpers.rs 11 12 91.67%
components/datetime/src/options/preferences.rs 0 2 0.0%
components/datetime/src/fields/mod.rs 4 11 36.36%
components/datetime/src/options/components.rs 84 92 91.3%
components/datetime/src/skeleton.rs 140 149 93.96%
components/datetime/src/fields/symbols.rs 6 32 18.75%
Files with Coverage Reduction New Missed Lines %
components/datetime/src/options/components.rs 1 75.65%
components/datetime/src/options/preferences.rs 1 0%
components/datetime/src/skeleton.rs 1 83.83%
components/provider_ppucd/src/parse_ppucd.rs 1 93.0%
components/plurals/src/data.rs 3 72.73%
components/plurals/src/lib.rs 3 85.0%
components/plurals/src/provider.rs 3 12.5%
Totals Coverage Status
Change from base Build 653c3ec23b76715caf9e50bc248828fac2049ee2: 0.4%
Covered Lines: 7182
Relevant Lines: 9828

💛 - Coveralls

Copy link
Member

@sffc sffc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Praise: Clear and easy to follow! I have only minor comments.

components/datetime/src/options/components.rs Outdated Show resolved Hide resolved
components/datetime/src/options/components.rs Outdated Show resolved Hide resolved
components/datetime/src/options/components.rs Outdated Show resolved Hide resolved
components/datetime/src/options/components.rs Outdated Show resolved Hide resolved
components/datetime/src/options/components.rs Outdated Show resolved Hide resolved

fields
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought (future): Perhaps this logic should live in the ecma402 crate. We can design a simpler components bag API for the actual ICU4X crate, and leave this mapping logic up to just the 402 compat layer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree.

components/datetime/src/options/preferences.rs Outdated Show resolved Hide resolved
components/datetime/src/provider/helpers.rs Outdated Show resolved Hide resolved
components/datetime/src/skeleton.rs Outdated Show resolved Hide resolved
components/datetime/src/skeleton.rs Outdated Show resolved Hide resolved
@jira-pull-request-webhook
Copy link

Notice: the branch changed across the force-push!

  • components/datetime/src/options/components.rs is different
  • components/datetime/src/options/preferences.rs is different
  • components/datetime/src/provider/helpers.rs is different
  • components/datetime/src/skeleton.rs is different
  • components/datetime/tests/datetime.rs is different
  • components/datetime/tests/fixtures/structs.rs is different

View Diff Across Force-Push

~ Your Friendly Jira-GitHub PR Checker Bot

@gregtatum
Copy link
Member Author

There's been a bunch of conflicting code landed in the last week, so I opted for a rebase to handle rather than merge as it was much simpler to verify the correctness in order to handle the conflicts.

This is still ready for re-review.

Copy link
Member

@sffc sffc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM except for one small issue

components/datetime/src/options/preferences.rs Outdated Show resolved Hide resolved
components/datetime/src/skeleton.rs Show resolved Hide resolved
@gregtatum gregtatum requested a review from sffc April 8, 2021 21:02
sffc
sffc previously approved these changes Apr 8, 2021
zbraniecki
zbraniecki previously approved these changes Apr 8, 2021
Copy link
Member

@zbraniecki zbraniecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!


// Shorten these for terser tests.
type FS = FieldSymbol;
type FL = FieldLength;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion(optional): I prefer Symbol, Length over FS, FL for readability.

second: None,
time_zone_name: None,
preferences: None,
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (if-minor): can you implement Default for it, so that one can write:

        let bag = Bag {
            year: Some(Numeric::Numeric),
            month: Some(Month::TwoDigit),
            day: Some(Numeric::Numeric),
            ..Default::default()
        };

Copy link
Member Author

@gregtatum gregtatum Apr 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, and was thinking I need to fix this. There's already an implementation of the Default trait, so I filled a follow-up since it'll touch multiple places across the code.

#623

/// A [`Skeleton`] is used to match against to find the best pattern.
///
/// This struct implements the [`Copy`] trait, as it's a collection of two references, which should
/// be fairly cheap to copy.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion(optional): The last sentence seems like overdocumentation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out the original reason why I was using that trait got factored out when I was working on that. Copy kind of scares me, which is why I documented it like that. I opted for removing both the trait and documentation.

@gregtatum gregtatum dismissed stale reviews from zbraniecki and sffc via b74aa87 April 8, 2021 21:35
@gregtatum gregtatum merged commit 6db4862 into unicode-org:main Apr 8, 2021
@zbraniecki zbraniecki mentioned this pull request Apr 14, 2021
16 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for components::Bag to DateTimeFormatOptions
4 participants