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

Creating unit tests using icu_testdata #2800

Closed
rizzen-yazston opened this issue Nov 2, 2022 · 4 comments
Closed

Creating unit tests using icu_testdata #2800

rizzen-yazston opened this issue Nov 2, 2022 · 4 comments
Labels
question Unresolved questions; type unclear

Comments

@rizzen-yazston
Copy link

For a unit test I am trying to create a data provider using the data of the icu_testdata crate, as it does contain Pattern_White_Space and Pattern_Syntax properties, and has a sample of Grapheme Segmenter data.

I do see 3 small examples, yet can't figure out how to expand the examples to have a single provider that supports: DataProvider + DataProvider + DataProvider.

I need to pass a single provider to a function that supports the 3 data types:

pub fn try_new<P>( provider: &P ) -> Result<Self, String> 
    where 
    P: DataProvider<PatternSyntaxV1Marker> + DataProvider<PatternWhiteSpaceV1Marker> +
    DataProvider<GraphemeClusterBreakDataV1Marker> + ?Sized,
    {
  /* --- snip details --- */
}

I believe a slightly more complex example that uses combination data type provider would help new users of the icu crates to create the unit tests using icu_testdata, and in general extend it to using icu_fs_provider for ICU data included in application.

Though I do see an issue for OS installed ICU data provider being proposed as an enhancement, which could reduce application installation size, and the applications are not concerned of the small changes taking place in the OS installed ICU data as OS updates takes place.

@rizzen-yazston
Copy link
Author

Is it possible to use BufferProvider (such as FsDataProvider, or icu_testdata::buffer()) as a provider for the following: icu_properties::sets (i.e. sets::load_pattern_white_space()), and icu_segmenter::GraphemeClusterBreakSegmenter::try_new_unstable()?

Or does one need to construct own methods to extract properties data using something similar to

provider.load(Default::default()).and_then(DataResponse::take_payload).map(CodePointSetData::from_data)?

, and similarly construct own method to obtain segmenter?

@sffc
Copy link
Member

sffc commented Nov 2, 2022

First of all, if you need segmenter data, which is still experimental (pending #2259), you need to explicitly enable the icu_testdata/icu_segmenter feature.

Once you enable the feature, icu_testdata::unstable() should implement all of the bounds you need.

If you want to use a BufferProvider, you should use the _with_buffer_provider constructors.

@rizzen-yazston
Copy link
Author

rizzen-yazston commented Nov 2, 2022

Thanks for advice.

In buf.rs: as_deserializing() is used in example above, yet when I use method in my own code it is producing error that method does not exit.

Perhaps part of the reason why I am struggling to get icu_testdata and FsDataProvider to work.

Seems icu_properties or icu_segmenter crates does not have methods with _with_buffer_provider. Thus how does one use icu_properties and icu_segmenter crates with FsDataProvider (points to local application copy of the CLDR data).

@robertbastian
Copy link
Member

You will need to activate the serde feature to use with_buffer_provider constructors (and as_deserializing).

Also note that the data format is not CLDR data, but a custom format compiled from CLDR (through icu_datagen).

@robertbastian robertbastian closed this as not planned Won't fix, can't repro, duplicate, stale Dec 21, 2022
@sffc sffc added question Unresolved questions; type unclear C-data-infra Component: provider, datagen, fallback, adapters and removed C-data-infra Component: provider, datagen, fallback, adapters labels Dec 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Unresolved questions; type unclear
Projects
None yet
Development

No branches or pull requests

3 participants