summaryrefslogtreecommitdiffstats
path: root/vendor/icu_locid/tests/fixtures
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/icu_locid/tests/fixtures')
-rw-r--r--vendor/icu_locid/tests/fixtures/canonicalize.json18
-rw-r--r--vendor/icu_locid/tests/fixtures/invalid-extensions.json112
-rw-r--r--vendor/icu_locid/tests/fixtures/invalid.json85
-rw-r--r--vendor/icu_locid/tests/fixtures/langid.json167
-rw-r--r--vendor/icu_locid/tests/fixtures/locale.json298
-rw-r--r--vendor/icu_locid/tests/fixtures/mod.rs260
6 files changed, 940 insertions, 0 deletions
diff --git a/vendor/icu_locid/tests/fixtures/canonicalize.json b/vendor/icu_locid/tests/fixtures/canonicalize.json
new file mode 100644
index 000000000..b20e64c4b
--- /dev/null
+++ b/vendor/icu_locid/tests/fixtures/canonicalize.json
@@ -0,0 +1,18 @@
+[
+ {
+ "input": "Pl",
+ "output": "pl"
+ },
+ {
+ "input": "eN-uS",
+ "output": "en-US"
+ },
+ {
+ "input": "ZH_hans_hK",
+ "output": "zh-Hans-HK"
+ },
+ {
+ "input": "en-scouse-fonipa",
+ "output": "en-fonipa-scouse"
+ }
+]
diff --git a/vendor/icu_locid/tests/fixtures/invalid-extensions.json b/vendor/icu_locid/tests/fixtures/invalid-extensions.json
new file mode 100644
index 000000000..a5f3a923d
--- /dev/null
+++ b/vendor/icu_locid/tests/fixtures/invalid-extensions.json
@@ -0,0 +1,112 @@
+[
+ {
+ "input": {
+ "type": "Locale",
+ "identifier": "pl-US-x-waytoolongkey"
+ },
+ "output": {
+ "error": "InvalidExtension",
+ "text": "Invalid subtag"
+ }
+ },
+ {
+ "input": {
+ "type": "Locale",
+ "identifier": "pl-US-x-@A_3"
+ },
+ "output": {
+ "error": "InvalidExtension",
+ "text": "Invalid subtag"
+ }
+ },
+ {
+ "input": {
+ "type": "Locale",
+ "identifier": "pl-US-t-h0"
+ },
+ "output": {
+ "error": "InvalidExtension",
+ "text": "Invalid subtag"
+ }
+ },
+ {
+ "input": {
+ "type": "Locale",
+ "identifier": "pl-US-t-h0-x-foo"
+ },
+ "output": {
+ "error": "InvalidExtension",
+ "text": "Invalid subtag"
+ }
+ },
+ {
+ "input": {
+ "type": "Locale",
+ "identifier": "pl-US-t-h0"
+ },
+ "output": {
+ "error": "InvalidExtension",
+ "text": "Invalid subtag"
+ }
+ },
+ {
+ "input": {
+ "type": "Locale",
+ "identifier": "und-t-m0"
+ },
+ "output": {
+ "error": "InvalidExtension",
+ "text": "Invalid subtag"
+ }
+ },
+ {
+ "input": {
+ "type": "Locale",
+ "identifier": "und-t-m0-n0-mixed"
+ },
+ "output": {
+ "error": "InvalidExtension",
+ "text": "Invalid subtag"
+ }
+ },
+ {
+ "input": {
+ "type": "Locale",
+ "identifier": "da-u"
+ },
+ "output": {
+ "error": "InvalidExtension",
+ "text": "Invalid subtag"
+ }
+ },
+ {
+ "input": {
+ "type": "Locale",
+ "identifier": "da-u--"
+ },
+ "output": {
+ "error": "InvalidExtension",
+ "text": "Invalid subtag"
+ }
+ },
+ {
+ "input": {
+ "type": "Locale",
+ "identifier": "da-u-t-latn"
+ },
+ "output": {
+ "error": "InvalidExtension",
+ "text": "Invalid subtag"
+ }
+ },
+ {
+ "input": {
+ "type": "Locale",
+ "identifier": "cmn-hans-cn-u-u"
+ },
+ "output": {
+ "error": "InvalidExtension",
+ "text": "Invalid subtag"
+ }
+ }
+]
diff --git a/vendor/icu_locid/tests/fixtures/invalid.json b/vendor/icu_locid/tests/fixtures/invalid.json
new file mode 100644
index 000000000..d44007596
--- /dev/null
+++ b/vendor/icu_locid/tests/fixtures/invalid.json
@@ -0,0 +1,85 @@
+[
+ {
+ "input": "a1a",
+ "output": {
+ "error": "InvalidLanguage",
+ "text": "The given language subtag is invalid"
+ }
+ },
+ {
+ "input": "Arab-US",
+ "output": {
+ "error": "InvalidLanguage",
+ "text": "The given language subtag is invalid"
+ }
+ },
+ {
+ "input": "",
+ "output": {
+ "error": "InvalidLanguage",
+ "text": "The given language subtag is invalid"
+ }
+ },
+ {
+ "input": "pl-DSDAFAFDF",
+ "output": {
+ "error": "InvalidSubtag",
+ "text": "Invalid subtag"
+ }
+ },
+ {
+ "input": "pl-Latn-$1231",
+ "output": {
+ "error": "InvalidSubtag",
+ "text": "Invalid subtag"
+ }
+ },
+ {
+ "input": "pl-Latn-US-$1231",
+ "output": {
+ "error": "InvalidSubtag",
+ "text": "Invalid subtag"
+ }
+ },
+ {
+ "input": "pl-Latn-12",
+ "output": {
+ "error": "InvalidSubtag",
+ "text": "Invalid subtag"
+ }
+ },
+ {
+ "input": "pl-Latn-a12",
+ "output": {
+ "error": "InvalidSubtag",
+ "text": "Invalid subtag"
+ }
+ },
+ {
+ "input": "pl-Latn-US-3_dd",
+ "output": {
+ "error": "InvalidSubtag",
+ "text": "Invalid subtag"
+ }
+ },
+ {
+ "input": {
+ "type": "Locale",
+ "identifier": "pl-Latn-US-variant-h0-hybrid"
+ },
+ "output": {
+ "error": "InvalidSubtag",
+ "text": "Invalid subtag"
+ }
+ },
+ {
+ "input": {
+ "type": "Locale",
+ "identifier": "en-variant-emodeng-emodeng"
+ },
+ "output": {
+ "error": "InvalidSubtag",
+ "text": "Invalid subtag"
+ }
+ }
+]
diff --git a/vendor/icu_locid/tests/fixtures/langid.json b/vendor/icu_locid/tests/fixtures/langid.json
new file mode 100644
index 000000000..31740d99a
--- /dev/null
+++ b/vendor/icu_locid/tests/fixtures/langid.json
@@ -0,0 +1,167 @@
+[
+ {
+ "input": "en",
+ "output": {
+ "type": "LanguageIdentifier",
+ "language": "en"
+ }
+ },
+ {
+ "input": "lij",
+ "output": {
+ "type": "LanguageIdentifier",
+ "language": "lij"
+ }
+ },
+ {
+ "input": "en-Latn",
+ "output": {
+ "type": "LanguageIdentifier",
+ "language": "en",
+ "script": "Latn"
+ }
+ },
+ {
+ "input": "lij-Arab",
+ "output": {
+ "type": "LanguageIdentifier",
+ "language": "lij",
+ "script": "Arab"
+ }
+ },
+ {
+ "input": "en-Latn-US",
+ "output": {
+ "type": "LanguageIdentifier",
+ "language": "en",
+ "script": "Latn",
+ "region": "US"
+ }
+ },
+ {
+ "input": "lij-Arab-FA",
+ "output": {
+ "type": "LanguageIdentifier",
+ "language": "lij",
+ "script": "Arab",
+ "region": "FA"
+ }
+ },
+ {
+ "input": "en-Latn-US-windows",
+ "output": {
+ "type": "LanguageIdentifier",
+ "language": "en",
+ "script": "Latn",
+ "region": "US",
+ "variants": ["windows"]
+ }
+ },
+ {
+ "input": "lij-Arab-FA-linux",
+ "output": {
+ "type": "LanguageIdentifier",
+ "language": "lij",
+ "script": "Arab",
+ "region": "FA",
+ "variants": ["linux"]
+ }
+ },
+ {
+ "input": "lij-Arab-FA-linux-nedis",
+ "output": {
+ "type": "LanguageIdentifier",
+ "language": "lij",
+ "script": "Arab",
+ "region": "FA",
+ "variants": ["linux", "nedis"]
+ }
+ },
+ {
+ "input": "EN-latn-us",
+ "output": {
+ "type": "LanguageIdentifier",
+ "language": "en",
+ "script": "Latn",
+ "region": "US"
+ }
+ },
+ {
+ "input": "sl-nedis",
+ "output": {
+ "type": "LanguageIdentifier",
+ "language": "sl",
+ "variants": ["nedis"]
+ }
+ },
+ {
+ "input": "de-CH-1996",
+ "output": {
+ "type": "LanguageIdentifier",
+ "language": "de",
+ "region": "CH",
+ "variants": ["1996"]
+ }
+ },
+ {
+ "input": "sr-Latn",
+ "output": {
+ "type": "LanguageIdentifier",
+ "language": "sr",
+ "script": "Latn"
+ }
+ },
+ {
+ "input": "es-419",
+ "output": {
+ "type": "LanguageIdentifier",
+ "language": "es",
+ "region": "419"
+ }
+ },
+ {
+ "input": "und-Latn-US",
+ "output": {
+ "type": "LanguageIdentifier",
+ "script": "Latn",
+ "region": "US"
+ }
+ },
+ {
+ "input": "und",
+ "output": {
+ "type": "LanguageIdentifier"
+ }
+ },
+ {
+ "input": "und-Latn",
+ "output": {
+ "type": "LanguageIdentifier",
+ "script": "Latn"
+ }
+ },
+ {
+ "input": "pl-macos-Windows-nedis-aRabic",
+ "output": {
+ "type": "LanguageIdentifier",
+ "language": "pl",
+ "variants": ["arabic", "macos", "nedis", "windows"]
+ }
+ },
+ {
+ "input": "und-Latn-macos",
+ "output": {
+ "type": "LanguageIdentifier",
+ "script": "Latn",
+ "variants": ["macos"]
+ }
+ },
+ {
+ "input": "und-Latn-312",
+ "output": {
+ "type": "LanguageIdentifier",
+ "script": "Latn",
+ "region": "312"
+ }
+ }
+]
diff --git a/vendor/icu_locid/tests/fixtures/locale.json b/vendor/icu_locid/tests/fixtures/locale.json
new file mode 100644
index 000000000..e87699351
--- /dev/null
+++ b/vendor/icu_locid/tests/fixtures/locale.json
@@ -0,0 +1,298 @@
+[
+ {
+ "input": {
+ "type": "Locale",
+ "identifier": "en-u-hc-h12"
+ },
+ "output": {
+ "type": "Locale",
+ "language": "en",
+ "extensions": {
+ "unicode": {
+ "keywords": {
+ "hc": "h12"
+ }
+ }
+ }
+ }
+ },
+ {
+ "input": {
+ "type": "Locale",
+ "identifier": "en-US-u-hc-h23"
+ },
+ "output": {
+ "type": "Locale",
+ "language": "en",
+ "region": "US",
+ "extensions": {
+ "unicode": {
+ "keywords": {
+ "hc": "h23"
+ }
+ }
+ }
+ }
+ },
+ {
+ "input": {
+ "type": "Locale",
+ "identifier": "en-US-u-foo"
+ },
+ "output": {
+ "type": "Locale",
+ "language": "en",
+ "region": "US",
+ "extensions": {
+ "unicode": {
+ "attributes": [
+ "foo"
+ ]
+ }
+ }
+ }
+ },
+ {
+ "input": {
+ "type": "Locale",
+ "identifier": "en-US-u-hc-h23-ca-islamic-civil-ss-true"
+ },
+ "output": {
+ "type": "Locale",
+ "language": "en",
+ "region": "US",
+ "extensions": {
+ "unicode": {
+ "keywords": {
+ "hc": "h23",
+ "ca": "islamic-civil",
+ "ss": "true"
+ }
+ }
+ }
+ }
+ },
+ {
+ "input": {
+ "type": "Locale",
+ "identifier": "en-US-t-pl-Latn-DE"
+ },
+ "output": {
+ "type": "Locale",
+ "language": "en",
+ "region": "US",
+ "extensions": {
+ "transform": {
+ "tlang": "pl-Latn-DE"
+ }
+ }
+ }
+ },
+ {
+ "input": {
+ "type": "Locale",
+ "identifier": "en-US-x-private-foobar"
+ },
+ "output": {
+ "type": "Locale",
+ "language": "en",
+ "region": "US",
+ "extensions": {
+ "private": ["private", "foobar"]
+ }
+ }
+ },
+ {
+ "input": {
+ "type": "Locale",
+ "identifier": "en-US-t-h0-hybrid-k0-platform-s0-true"
+ },
+ "output": {
+ "type": "Locale",
+ "language": "en",
+ "region": "US",
+ "extensions": {
+ "transform": {
+ "tfields": {
+ "h0": "hybrid",
+ "k0": "platform",
+ "s0": "true"
+ }
+ }
+ }
+ }
+ },
+ {
+ "input": {
+ "type": "Locale",
+ "identifier": "en-US-t-es-AR-x-foo"
+ },
+ "output": {
+ "type": "Locale",
+ "language": "en",
+ "region": "US",
+ "extensions": {
+ "transform": {
+ "tlang": "es-AR"
+ },
+ "private": ["foo"]
+ }
+ }
+ },
+ {
+ "input": {
+ "type": "Locale",
+ "identifier": "en-US-u-ca-buddhist-hc-h12-t-es-AR-h0-hybrid-x-private-foobar"
+ },
+ "output": {
+ "type": "Locale",
+ "language": "en",
+ "region": "US",
+ "extensions": {
+ "unicode": {
+ "keywords": {
+ "ca": "buddhist",
+ "hc": "h12"
+ }
+ },
+ "transform": {
+ "tlang": "es-AR",
+ "tfields": {
+ "h0": "hybrid"
+ }
+ },
+ "private": ["private", "foobar"]
+ }
+ }
+ },
+ {
+ "input": {
+ "type": "Locale",
+ "language": "es",
+ "region": "MX",
+ "extensions": {
+ "unicode": {
+ "keywords": {
+ "ca": "islamic",
+ "co": "search",
+ "nu": "roman"
+ }
+ }
+ }
+ },
+ "output": {
+ "type": "Locale",
+ "identifier": "es-MX-u-ca-islamic-co-search-nu-roman"
+ }
+ },
+ {
+ "input": {
+ "type": "Locale",
+ "identifier": "und-u-kn"
+ },
+ "output": {
+ "type": "Locale",
+ "identifier": "und-u-kn"
+ }
+ },
+ {
+ "input": {
+ "type": "Locale",
+ "identifier": "und-u-kn-ca-calendar"
+ },
+ "output": {
+ "type": "Locale",
+ "identifier": "und-u-ca-calendar-kn"
+ }
+ },
+ {
+ "input": {
+ "type": "Locale",
+ "identifier": "und-u-kn-nu-arab"
+ },
+ "output": {
+ "type": "Locale",
+ "identifier": "und-u-kn-nu-arab"
+ }
+ },
+ {
+ "input": {
+ "type": "Locale",
+ "identifier": "und-t-m0-true"
+ },
+ "output": {
+ "type": "Locale",
+ "identifier": "und-t-m0-true"
+ }
+ },
+ {
+ "input": {
+ "type": "Locale",
+ "identifier": "und-t-m0-true-n0-mixed"
+ },
+ "output": {
+ "type": "Locale",
+ "identifier": "und-t-m0-true-n0-mixed"
+ }
+ },
+ {
+ "input": {
+ "type": "Locale",
+ "identifier": "und-t-m0-true-c0-mixed"
+ },
+ "output": {
+ "type": "Locale",
+ "identifier": "und-t-c0-mixed-m0-true"
+ }
+ },
+ {
+ "input": {
+ "type": "Locale",
+ "identifier": "da-u-ca-gregory-ca-buddhist"
+ },
+ "output": {
+ "type": "Locale",
+ "identifier": "da-u-ca-gregory"
+ }
+ },
+ {
+ "input": {
+ "type": "Locale",
+ "identifier": "pt-u-attr2-attr1-ca-gregory"
+ },
+ "output": {
+ "type": "Locale",
+ "identifier": "pt-u-attr1-attr2-ca-gregory"
+ }
+ },
+ {
+ "input": {
+ "type": "Locale",
+ "identifier": "pt-u-attr1-attr2-attr1-ca-gregory"
+ },
+ "output": {
+ "type": "Locale",
+ "identifier": "pt-u-attr1-attr2-ca-gregory"
+ }
+ },
+ {
+ "input": {
+ "type": "Locale",
+ "identifier": "en-a-not-assigned"
+ },
+ "output": {
+ "type": "Locale",
+ "identifier": "en-a-not-assigned"
+ }
+ },
+ {
+ "input": {
+ "type": "Locale",
+ "identifier": "en-w-bar-u-foo-a-bar-x-u-foo"
+ },
+ "output": {
+ "type": "Locale",
+ "identifier": "en-a-bar-u-foo-w-bar-x-u-foo"
+ }
+ }
+]
diff --git a/vendor/icu_locid/tests/fixtures/mod.rs b/vendor/icu_locid/tests/fixtures/mod.rs
new file mode 100644
index 000000000..b688632ba
--- /dev/null
+++ b/vendor/icu_locid/tests/fixtures/mod.rs
@@ -0,0 +1,260 @@
+// 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 ).
+
+use std::collections::HashMap;
+use std::convert::{TryFrom, TryInto};
+
+use icu_locid::extensions::private;
+use icu_locid::extensions::transform;
+use icu_locid::extensions::unicode;
+use icu_locid::extensions::Extensions;
+use icu_locid::{subtags, LanguageIdentifier, Locale, ParserError};
+use serde::Deserialize;
+
+#[derive(Debug, Deserialize, Clone)]
+pub struct LocaleIdentifier {
+ #[serde(rename = "type")]
+ pub field_type: String,
+ pub identifier: String,
+}
+
+#[derive(Debug, Deserialize, Clone)]
+pub struct LocaleExtensionUnicode {
+ #[serde(default)]
+ keywords: HashMap<String, Option<String>>,
+ #[serde(default)]
+ attributes: Vec<String>,
+}
+
+#[derive(Debug, Deserialize, Clone)]
+pub struct LocaleExtensionTransform {
+ tlang: Option<String>,
+ #[serde(default)]
+ tfields: HashMap<String, Option<String>>,
+}
+
+#[derive(Debug, Deserialize, Clone)]
+pub struct LocaleExtensions {
+ unicode: Option<LocaleExtensionUnicode>,
+ transform: Option<LocaleExtensionTransform>,
+ #[serde(default)]
+ private: Vec<String>,
+ _other: Option<String>,
+}
+
+impl TryFrom<LocaleExtensions> for Extensions {
+ type Error = ParserError;
+
+ fn try_from(input: LocaleExtensions) -> Result<Self, Self::Error> {
+ let mut ext = Extensions::default();
+ if let Some(unicode) = input.unicode {
+ ext.unicode.keywords = unicode
+ .keywords
+ .iter()
+ .map(|(k, v)| {
+ (
+ unicode::Key::try_from_bytes(k.as_bytes()).expect("Parsing key failed."),
+ v.as_ref().map_or(
+ unicode::Value::try_from_bytes(b"").expect("Failed to parse Value"),
+ |v| {
+ unicode::Value::try_from_bytes(v.as_bytes())
+ .expect("Parsing type failed.")
+ },
+ ),
+ )
+ })
+ .collect();
+ let v: Vec<unicode::Attribute> = unicode
+ .attributes
+ .iter()
+ .map(|v| {
+ unicode::Attribute::try_from_bytes(v.as_bytes())
+ .expect("Parsing attribute failed.")
+ })
+ .collect();
+ ext.unicode.attributes = unicode::Attributes::from_vec_unchecked(v);
+ }
+ if let Some(transform) = input.transform {
+ ext.transform.fields = transform
+ .tfields
+ .iter()
+ .map(|(k, v)| {
+ (
+ transform::Key::try_from_bytes(k.as_bytes()).expect("Parsing key failed."),
+ v.as_ref()
+ .map(|v| {
+ transform::Value::try_from_bytes(v.as_bytes())
+ .expect("Parsing value failed.")
+ })
+ .expect("Value cannot be empty."),
+ )
+ })
+ .collect();
+
+ if let Some(tlang) = transform.tlang {
+ ext.transform.lang = Some(tlang.parse().expect("Failed to parse tlang."));
+ }
+ }
+ let v: Vec<private::Subtag> = input
+ .private
+ .iter()
+ .map(|v| private::Subtag::try_from_bytes(v.as_bytes()).expect("Failed to add field."))
+ .collect();
+ ext.private = private::Private::from_vec_unchecked(v);
+ Ok(ext)
+ }
+}
+
+#[derive(Debug, Deserialize, Clone)]
+pub struct LocaleSubtags {
+ #[serde(rename = "type")]
+ pub field_type: String,
+ pub language: Option<String>,
+ pub script: Option<String>,
+ pub region: Option<String>,
+ #[serde(default)]
+ pub variants: Vec<String>,
+ pub extensions: Option<LocaleExtensions>,
+}
+
+#[derive(Debug, Deserialize, Clone)]
+pub struct LocaleError {
+ pub error: String,
+ pub text: String,
+}
+
+#[derive(Debug, Deserialize, Clone)]
+#[serde(untagged)]
+#[allow(clippy::large_enum_variant)] // test code
+pub enum LocaleInfo {
+ String(String),
+ Error(LocaleError),
+ Identifier(LocaleIdentifier),
+ Object(LocaleSubtags),
+}
+
+impl TryFrom<LocaleInfo> for LanguageIdentifier {
+ type Error = ParserError;
+
+ fn try_from(input: LocaleInfo) -> Result<Self, Self::Error> {
+ match input {
+ LocaleInfo::String(s) => s.parse(),
+ LocaleInfo::Error(e) => Err(e.into()),
+ LocaleInfo::Identifier(ident) => ident.try_into(),
+ LocaleInfo::Object(o) => o.try_into(),
+ }
+ }
+}
+
+impl TryFrom<LocaleInfo> for Locale {
+ type Error = ParserError;
+
+ fn try_from(input: LocaleInfo) -> Result<Self, Self::Error> {
+ match input {
+ LocaleInfo::String(s) => s.parse(),
+ LocaleInfo::Error(e) => Err(e.into()),
+ LocaleInfo::Identifier(ident) => ident.try_into(),
+ LocaleInfo::Object(o) => o.try_into(),
+ }
+ }
+}
+
+impl TryFrom<LocaleIdentifier> for LanguageIdentifier {
+ type Error = ParserError;
+
+ fn try_from(input: LocaleIdentifier) -> Result<Self, Self::Error> {
+ LanguageIdentifier::try_from_locale_bytes(input.identifier.as_bytes())
+ }
+}
+
+impl TryFrom<LocaleIdentifier> for Locale {
+ type Error = ParserError;
+
+ fn try_from(input: LocaleIdentifier) -> Result<Self, Self::Error> {
+ Locale::try_from_bytes(input.identifier.as_bytes())
+ }
+}
+
+impl TryFrom<LocaleSubtags> for LanguageIdentifier {
+ type Error = ParserError;
+
+ fn try_from(subtags: LocaleSubtags) -> Result<Self, Self::Error> {
+ let language = if let Some(lang) = subtags.language {
+ lang.parse().expect("Failed to parse language subtag")
+ } else {
+ subtags::Language::default()
+ };
+ let script = subtags
+ .script
+ .map(|s| s.parse().expect("Failed to parse script subtag."));
+ let region = subtags
+ .region
+ .map(|s| s.parse().expect("Failed to parse region subtag."));
+ let variants = subtags
+ .variants
+ .iter()
+ .map(|v| v.parse().expect("Failed to parse variant subtag."))
+ .collect::<Vec<_>>();
+ Ok(LanguageIdentifier {
+ language,
+ script,
+ region,
+ variants: subtags::Variants::from_vec_unchecked(variants),
+ })
+ }
+}
+
+impl TryFrom<LocaleSubtags> for Locale {
+ type Error = ParserError;
+
+ fn try_from(subtags: LocaleSubtags) -> Result<Self, Self::Error> {
+ let language = if let Some(lang) = subtags.language {
+ lang.parse().expect("Failed to parse language subtag")
+ } else {
+ subtags::Language::default()
+ };
+ let script = subtags
+ .script
+ .map(|s| s.parse().expect("Failed to parse script subtag."));
+ let region = subtags
+ .region
+ .map(|s| s.parse().expect("Failed to parse region subtag."));
+ let variants = subtags
+ .variants
+ .iter()
+ .map(|v| v.parse().expect("Failed to parse variant subtag."))
+ .collect::<Vec<_>>();
+ let extensions = if let Some(e) = subtags.extensions {
+ e.try_into().expect("Failed to parse extensions.")
+ } else {
+ Extensions::default()
+ };
+ Ok(Locale {
+ id: LanguageIdentifier {
+ language,
+ script,
+ region,
+ variants: subtags::Variants::from_vec_unchecked(variants),
+ },
+ extensions,
+ })
+ }
+}
+
+impl From<LocaleError> for ParserError {
+ fn from(e: LocaleError) -> Self {
+ match e.error.as_str() {
+ "InvalidLanguage" => ParserError::InvalidLanguage,
+ "InvalidSubtag" => ParserError::InvalidSubtag,
+ "InvalidExtension" => ParserError::InvalidExtension,
+ _ => unreachable!("Unknown error name"),
+ }
+ }
+}
+
+#[derive(Debug, Deserialize)]
+pub struct LocaleTest {
+ pub input: LocaleInfo,
+ pub output: LocaleInfo,
+}