use crate::traits::{Direction, MorphType, NormType, SegType, TraitKey, TransType};
use hashbrown::HashMap;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum TraitValue {
Boolean(bool),
Direction(Direction),
SegType(SegType),
MorphType(MorphType),
StringArray(Vec<String>),
String(String),
NormType(NormType),
TransType(TransType),
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct CapabilityManifest {
pub resolved_locale: String,
pub traits: HashMap<TraitKey, TraitValue>,
pub metadata: HashMap<String, String>,
}
impl CapabilityManifest {
pub fn new(resolved_locale: String) -> Self {
Self { resolved_locale, traits: HashMap::new(), metadata: HashMap::new() }
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_manifest_golden_serialization() {
let mut manifest = CapabilityManifest::new("ar-EG".to_string());
manifest.traits.insert(TraitKey::PrimaryDirection, TraitValue::Direction(Direction::RTL));
manifest.traits.insert(TraitKey::HasBidiElements, TraitValue::Boolean(true));
manifest
.traits
.insert(TraitKey::MorphologyType, TraitValue::MorphType(MorphType::TEMPLATIC));
manifest.traits.insert(TraitKey::NormalizationType, TraitValue::NormType(NormType::NFC));
manifest
.traits
.insert(TraitKey::TransliterationType, TraitValue::TransType(TransType::ICU_TRANSFORM));
manifest.metadata.insert("icu_strip_vowels".to_string(), "true".to_string());
manifest.metadata.insert("registry_version".to_string(), "1.0.0".to_string());
let json_output = serde_json::to_string(&manifest).expect("Failed to serialize manifest");
assert!(json_output.contains(r#""resolved_locale":"ar-EG""#));
assert!(json_output.contains(r#""PRIMARY_DIRECTION":"RTL""#));
assert!(json_output.contains(r#""HAS_BIDI_ELEMENTS":true"#));
assert!(json_output.contains(r#""MORPHOLOGY_TYPE":"TEMPLATIC""#));
assert!(json_output.contains(r#""NORMALIZATION_TYPE":"NFC""#));
assert!(json_output.contains(r#""TRANSLITERATION_TYPE":"ICU_TRANSFORM""#));
assert!(json_output.contains(r#""icu_strip_vowels":"true""#));
assert!(json_output.contains(r#""registry_version":"1.0.0""#));
}
}