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

Fix LocaleExpander::try_new_with_any_provider #3769

Merged
merged 1 commit into from
Aug 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions components/locid_transform/src/expander.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ impl LocaleExpander {

let (likely_subtags_l, likely_subtags_sr, likely_subtags_ext) =
match (payload_l, payload_sr, payload_ext) {
(Ok(l), Ok(sr), Err(_)) => (l, sr, None),
(Ok(l), Ok(sr), Ok(ext)) => (l, sr, Some(ext)),
_ => {
let result: DataPayload<LikelySubtagsV1Marker> =
Expand Down Expand Up @@ -658,6 +659,7 @@ mod tests {
keys: vec![
LikelySubtagsForLanguageV1Marker::KEY,
LikelySubtagsForScriptRegionV1Marker::KEY,
LikelySubtagsExtendedV1Marker::KEY,
],
};
let lc = LocaleExpander::try_new_with_any_provider(&provider)
Expand Down Expand Up @@ -706,4 +708,20 @@ mod tests {
panic!("should not create: no data present")
};
}

#[test]
fn test_new_small_keys() {
// Include the new small keys but not the extended key
let provider = RejectByKeyProvider {
keys: vec![
LikelySubtagsExtendedV1Marker::KEY,
LikelySubtagsV1Marker::KEY,
],
};
let lc = LocaleExpander::try_new_with_any_provider(&provider)
.expect("should create with mixed keys");
let mut locale = locale!("zh-CN");
assert_eq!(lc.maximize(&mut locale), TransformResult::Modified);
assert_eq!(locale, locale!("zh-Hans-CN"));
}
}
Loading