Skip to content

Commit

Permalink
Make TZ fixture more readable (unicode-org#5756)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertbastian authored Oct 31, 2024
1 parent 0222629 commit fb9f30a
Show file tree
Hide file tree
Showing 3 changed files with 240 additions and 1,303 deletions.
108 changes: 43 additions & 65 deletions components/datetime/tests/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ use icu_datetime::{
};
use icu_locale_core::{
extensions::unicode::{key, value, Value},
locale, LanguageIdentifier, Locale,
locale, Locale,
};
use icu_provider::prelude::*;
use icu_timezone::{CustomZonedDateTime, TimeZoneIdMapper, TimeZoneInfo, UtcOffset};
use patterns::{
dayperiods::{DayPeriodExpectation, DayPeriodTests},
time_zones::{TimeZoneExpectation, TimeZoneFormatterConfig, TimeZoneTests},
time_zones::TimeZoneTests,
};
use writeable::{assert_try_writeable_eq, assert_writeable_eq};

Expand Down Expand Up @@ -434,41 +434,30 @@ fn test_time_zone_format_configs() {
.unwrap()
.0
{
let data_locale: DataLocale = test.locale.parse::<LanguageIdentifier>().unwrap().into();
let data_locale: DataLocale = test.locale.parse::<Locale>().unwrap().into();
let zoned_datetime = mock::parse_zoned_gregorian_from_str(&test.datetime);
for TimeZoneExpectation {
patterns: _,
configs,
expected,
} in &test.expectations
{
for &config_input in configs {
if matches!(config_input, TimeZoneFormatterConfig::Iso8601(_, _, _)) {
// TODO: ISO-8601 not yet supported via Semantic Skeleton
continue;
}
let skeleton = config_input.to_semantic_skeleton();
for expect in expected {
let tzf =
FixedCalendarDateTimeFormatter::<Gregorian, _>::try_new_with_skeleton(
&data_locale,
skeleton,
)
.unwrap();
assert_writeable_eq!(
writeable::adapters::LossyWrap(tzf.format(&zoned_datetime.zone)),
*expect,
"\n\
for (pattern_input, expect) in &test.expectations {
let Some(skeleton) = patterns::time_zones::pattern_to_semantic_skeleton(pattern_input)
else {
continue;
};
let tzf = FixedCalendarDateTimeFormatter::<Gregorian, _>::try_new_with_skeleton(
&data_locale,
skeleton,
)
.unwrap();
assert_writeable_eq!(
writeable::adapters::LossyWrap(tzf.format(&zoned_datetime.zone)),
*expect,
"\n\
locale: `{}`,\n\
datetime: `{}`,\n\
config: `{:?}`,\n
",
data_locale,
test.datetime,
config_input,
);
}
}
data_locale,
test.datetime,
pattern_input,
);
}
}
}
Expand Down Expand Up @@ -508,44 +497,33 @@ fn test_time_zone_patterns() {
.unwrap()
.0
{
let locale: Locale = test.locale.parse().unwrap();
let data_locale: DataLocale = test.locale.parse::<Locale>().unwrap().into();
let zoned_datetime = mock::parse_zoned_gregorian_from_str(&test.datetime);

for TimeZoneExpectation {
patterns,
configs: _,
expected,
} in &test.expectations
{
for pattern_input in patterns {
if pattern_input == "VVV" {
// TODO(#5658): 'VVV' format not yet supported
continue;
}
let parsed_pattern = DateTimePattern::try_from_pattern_str(pattern_input).unwrap();
for expect in expected.iter() {
let mut pattern_formatter =
TypedDateTimeNames::<Gregorian, NeoTimeZoneSkeleton>::try_new(
&(&locale).into(),
)
.unwrap();
let formatted_datetime = pattern_formatter
.include_for_pattern(&parsed_pattern)
.unwrap()
.format(&zoned_datetime);
assert_writeable_eq!(
writeable::adapters::LossyWrap(formatted_datetime),
*expect,
"\n\
for (pattern_input, expect) in &test.expectations {
if pattern_input == "VVV" {
// TODO(#5658): 'VVV' format not yet supported
continue;
}
let parsed_pattern = DateTimePattern::try_from_pattern_str(pattern_input).unwrap();
let mut pattern_formatter =
TypedDateTimeNames::<Gregorian, NeoTimeZoneSkeleton>::try_new(&data_locale)
.unwrap();
let formatted_datetime = pattern_formatter
.include_for_pattern(&parsed_pattern)
.unwrap()
.format(&zoned_datetime);
assert_writeable_eq!(
writeable::adapters::LossyWrap(formatted_datetime),
*expect,
"\n\
locale: `{}`,\n\
datetime: `{}`,\n\
pattern: `{}`",
locale,
test.datetime,
pattern_input,
);
}
}
data_locale,
test.datetime,
pattern_input,
);
}
}
}
Expand Down
Loading

0 comments on commit fb9f30a

Please sign in to comment.