summaryrefslogtreecommitdiffstats
path: root/third_party/rust/icu_locid_transform/tests/locale_canonicalizer.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /third_party/rust/icu_locid_transform/tests/locale_canonicalizer.rs
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/icu_locid_transform/tests/locale_canonicalizer.rs')
-rw-r--r--third_party/rust/icu_locid_transform/tests/locale_canonicalizer.rs82
1 files changed, 82 insertions, 0 deletions
diff --git a/third_party/rust/icu_locid_transform/tests/locale_canonicalizer.rs b/third_party/rust/icu_locid_transform/tests/locale_canonicalizer.rs
new file mode 100644
index 0000000000..06e360f53c
--- /dev/null
+++ b/third_party/rust/icu_locid_transform/tests/locale_canonicalizer.rs
@@ -0,0 +1,82 @@
+// This file is part of ICU4X. For terms of use, please see the file
+// called LICENSE at the top level of the ICU4X source tree
+// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
+
+mod fixtures;
+mod helpers;
+
+use icu_locid::Locale;
+use icu_locid_transform::{LocaleCanonicalizer, LocaleExpander, TransformResult};
+use writeable::assert_writeable_eq;
+
+#[test]
+fn test_maximize() {
+ let lc = LocaleExpander::new_extended();
+
+ let path = "./tests/fixtures/maximize.json";
+ let testcases: Vec<fixtures::CanonicalizationTest> =
+ helpers::read_fixture(path).expect("Failed to read a fixture");
+
+ for case in testcases {
+ if let Some(true) = case.disabled {
+ continue;
+ }
+ let mut locale: Locale = case.input.parse().unwrap();
+ let unmodified = locale.clone();
+ let result = lc.maximize(&mut locale);
+ assert_writeable_eq!(locale, case.output);
+ if result == TransformResult::Modified {
+ assert_ne!(locale, unmodified);
+ } else {
+ assert_eq!(locale, unmodified);
+ }
+ }
+}
+
+#[test]
+fn test_minimize() {
+ let lc = LocaleExpander::new_extended();
+
+ let path = "./tests/fixtures/minimize.json";
+ let testcases: Vec<fixtures::CanonicalizationTest> =
+ helpers::read_fixture(path).expect("Failed to read a fixture");
+
+ for case in testcases {
+ if let Some(true) = case.disabled {
+ continue;
+ }
+ let mut locale: Locale = case.input.parse().unwrap();
+ let unmodified = locale.clone();
+ let result = lc.minimize(&mut locale);
+ assert_writeable_eq!(locale, case.output);
+ if result == TransformResult::Modified {
+ assert_ne!(locale, unmodified);
+ } else {
+ assert_eq!(locale, unmodified);
+ }
+ }
+}
+
+#[test]
+fn test_canonicalize() {
+ let lc = LocaleCanonicalizer::new();
+
+ let path = "./tests/fixtures/canonicalize.json";
+ let testcases: Vec<fixtures::CanonicalizationTest> =
+ helpers::read_fixture(path).expect("Failed to read a fixture");
+
+ for case in testcases {
+ if let Some(true) = case.disabled {
+ continue;
+ }
+ let mut locale: Locale = case.input.parse().expect("Unable to parse input");
+ let unmodified = locale.clone();
+ let result = lc.canonicalize(&mut locale);
+ assert_writeable_eq!(locale, case.output);
+ if result == TransformResult::Modified {
+ assert_ne!(locale, unmodified);
+ } else {
+ assert_eq!(locale, unmodified);
+ }
+ }
+}