Skip to content

Commit c11e3fa

Browse files
committed
Improve test coverage
1 parent 52e9e56 commit c11e3fa

File tree

4 files changed

+18
-23
lines changed

4 files changed

+18
-23
lines changed

src/negotiate/likely_subtags.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub fn add(langid: &LanguageIdentifier) -> Option<LanguageIdentifier> {
1010
"fr" => "fr-Latn-FR",
1111
"sr" => "sr-Cyrl-SR",
1212
"sr-RU" => "sr-Latn-SR",
13-
"az-IR" => "az-Aram-IR",
13+
"az-IR" => "az-Arab-IR",
1414
"zh-GB" => "zh-Hant-GB",
1515
"zh-US" => "zh-Hant-US",
1616
_ => {

src/negotiate/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@
121121
122122
use std::collections::HashMap;
123123
use unic_langid::LanguageIdentifier;
124-
125124
mod likely_subtags;
126125

127126
#[derive(PartialEq, Debug, Clone, Copy)]
@@ -151,7 +150,7 @@ pub fn filter_matches<
151150
let req_langids: Vec<LanguageIdentifier> =
152151
requested.into_iter().map(|a| a.clone().into()).collect();
153152

154-
for mut req in req_langids {
153+
for req in req_langids {
155154
if req.get_language() == "und" {
156155
continue;
157156
}
@@ -207,7 +206,7 @@ pub fn filter_matches<
207206
match_found = false;
208207

209208
// 3) Try to match against a maximized version of the requested locale
210-
if let Some(req) = likely_subtags::add(&req) {
209+
let mut req = if let Some(req) = likely_subtags::add(&req) {
211210
av_map.retain(|key, value| {
212211
if strategy != NegotiationStrategy::Filtering && match_found {
213212
return true;
@@ -230,7 +229,10 @@ pub fn filter_matches<
230229
}
231230

232231
match_found = false;
233-
}
232+
req
233+
} else {
234+
req
235+
};
234236

235237
// 4) Try to match against a variant as a range
236238
req.set_variants(&[]).unwrap();
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[
22
{
33
"input": [["und"], ["de", "pl-PL", "it", "fr-Latn-CA", "ru"]],
4-
"output": ["de", "pl-PL", "it", "fr-Latn-CA", "ru"]
4+
"output": []
55
}
66
]

tests/lib.rs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::fs;
33
use std::fs::File;
44
use std::path::Path;
55

6-
use fluent_locale::convert_vec_str_to_langids;
6+
use fluent_locale::convert_vec_str_to_langids_lossy;
77
use fluent_locale::negotiate_languages;
88
use fluent_locale::parse_accepted_languages;
99
use fluent_locale::NegotiationStrategy;
@@ -39,6 +39,7 @@ fn read_negotiate_testsets<P: AsRef<Path>>(path: P) -> Result<Vec<NegotiateTestS
3939
}
4040

4141
fn test_negotiate_fixtures(path: &str) {
42+
println!("Testing path: {}", path);
4243
let tests = read_negotiate_testsets(path).unwrap();
4344

4445
for test in tests {
@@ -53,12 +54,9 @@ fn test_negotiate_fixtures(path: &str) {
5354
};
5455
match test.input {
5556
NegotiateTestInput::NoDefault(requested, available) => {
56-
let requested =
57-
convert_vec_str_to_langids(requested).expect("Failed to read langid list");
58-
let available =
59-
convert_vec_str_to_langids(available).expect("Failed to read langid list");
60-
let output =
61-
convert_vec_str_to_langids(test.output).expect("Failed to read langid list");
57+
let requested = convert_vec_str_to_langids_lossy(requested);
58+
let available = convert_vec_str_to_langids_lossy(available);
59+
let output = convert_vec_str_to_langids_lossy(test.output);
6260
let output2: Vec<&LanguageIdentifier> = output.iter().map(|t| t.as_ref()).collect();
6361
assert_eq!(
6462
negotiate_languages(&requested, &available, None, strategy),
@@ -68,12 +66,9 @@ fn test_negotiate_fixtures(path: &str) {
6866
);
6967
}
7068
NegotiateTestInput::Default(requested, available, default) => {
71-
let requested =
72-
convert_vec_str_to_langids(requested).expect("Failed to read langid list");
73-
let available =
74-
convert_vec_str_to_langids(available).expect("Failed to read langid list");
75-
let output =
76-
convert_vec_str_to_langids(test.output).expect("Failed to read langid list");
69+
let requested = convert_vec_str_to_langids_lossy(requested);
70+
let available = convert_vec_str_to_langids_lossy(available);
71+
let output = convert_vec_str_to_langids_lossy(test.output);
7772
let output2: Vec<&LanguageIdentifier> = output.iter().map(|t| t.as_ref()).collect();
7873
assert_eq!(
7974
negotiate_languages(
@@ -97,9 +92,7 @@ fn negotiate_filtering() {
9792

9893
for path in paths {
9994
let p = path.unwrap().path().to_str().unwrap().to_owned();
100-
if p.contains("available") {
101-
test_negotiate_fixtures(p.as_str());
102-
}
95+
test_negotiate_fixtures(p.as_str());
10396
}
10497
}
10598

@@ -130,7 +123,7 @@ fn accepted_languages() {
130123

131124
for test in tests {
132125
let locales = parse_accepted_languages(test.input.as_str());
133-
let output = convert_vec_str_to_langids(test.output).expect("Failed to read langid list");
126+
let output = convert_vec_str_to_langids_lossy(test.output);
134127
assert_eq!(output, locales);
135128
}
136129
}

0 commit comments

Comments
 (0)