| 1 |
// This file is part of ICU4X. For terms of use, please see the file |
| 2 |
// called LICENSE at the top level of the ICU4X source tree |
| 3 |
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). |
| 4 |
|
| 5 |
mod fixtures; |
| 6 |
|
| 7 |
use icu_locid::Locale; |
| 8 |
use icu_locid_transform::{LocaleCanonicalizer, LocaleExpander, TransformResult}; |
| 9 |
use writeable::assert_writeable_eq; |
| 10 |
|
| 11 |
#[test] |
| 12 |
fn test_maximize() { |
| 13 |
let lc = LocaleExpander::new_extended(); |
| 14 |
|
| 15 |
let testcases: Vec<fixtures::CanonicalizationTest> = |
| 16 |
serde_json::from_str(include_str!("fixtures/maximize.json")) |
| 17 |
.expect("Failed to read a fixture"); |
| 18 |
|
| 19 |
for case in testcases { |
| 20 |
if let Some(true) = case.disabled { |
| 21 |
continue; |
| 22 |
} |
| 23 |
let mut locale: Locale = case.input.parse().unwrap(); |
| 24 |
let unmodified = locale.clone(); |
| 25 |
let result = lc.maximize(&mut locale); |
| 26 |
assert_writeable_eq!(locale, case.output, "{:?}", case); |
| 27 |
if result == TransformResult::Modified { |
| 28 |
assert_ne!(locale, unmodified, "{:?}", case); |
| 29 |
} else { |
| 30 |
assert_eq!(locale, unmodified, "{:?}", case); |
| 31 |
} |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
#[test] |
| 36 |
fn test_minimize() { |
| 37 |
let lc = LocaleExpander::new_extended(); |
| 38 |
|
| 39 |
let testcases: Vec<fixtures::CanonicalizationTest> = |
| 40 |
serde_json::from_str(include_str!("fixtures/minimize.json")) |
| 41 |
.expect("Failed to read a fixture"); |
| 42 |
|
| 43 |
for case in testcases { |
| 44 |
if let Some(true) = case.disabled { |
| 45 |
continue; |
| 46 |
} |
| 47 |
let mut locale: Locale = case.input.parse().unwrap(); |
| 48 |
let unmodified = locale.clone(); |
| 49 |
let result = lc.minimize(&mut locale); |
| 50 |
assert_writeable_eq!(locale, case.output, "{:?}", case); |
| 51 |
if result == TransformResult::Modified { |
| 52 |
assert_ne!(locale, unmodified, "{:?}", case); |
| 53 |
} else { |
| 54 |
assert_eq!(locale, unmodified, "{:?}", case); |
| 55 |
} |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
#[test] |
| 60 |
fn test_canonicalize() { |
| 61 |
let lc = LocaleCanonicalizer::new(); |
| 62 |
|
| 63 |
let testcases: Vec<fixtures::CanonicalizationTest> = |
| 64 |
serde_json::from_str(include_str!("fixtures/canonicalize.json")) |
| 65 |
.expect("Failed to read a fixture"); |
| 66 |
|
| 67 |
for case in testcases { |
| 68 |
if let Some(true) = case.disabled { |
| 69 |
continue; |
| 70 |
} |
| 71 |
let mut locale: Locale = case.input.parse().expect("Unable to parse input"); |
| 72 |
let unmodified = locale.clone(); |
| 73 |
let result = lc.canonicalize(&mut locale); |
| 74 |
assert_writeable_eq!(locale, case.output, "{:?}", case); |
| 75 |
if result == TransformResult::Modified { |
| 76 |
assert_ne!(locale, unmodified, "{:?}", case); |
| 77 |
} else { |
| 78 |
assert_eq!(locale, unmodified, "{:?}", case); |
| 79 |
} |
| 80 |
} |
| 81 |
} |