use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Qualifier {
pub namespace: String,
pub name: String,
pub value: String,
}
impl Qualifier {
pub fn new(
namespace: impl Into<String>,
name: impl Into<String>,
value: impl Into<String>,
) -> Self {
Self {
namespace: namespace.into(),
name: name.into(),
value: value.into(),
}
}
pub fn path(&self) -> String {
format!("{}:{}", self.namespace, self.name)
}
}
impl fmt::Display for Qualifier {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}:{}={}", self.namespace, self.name, self.value)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_qualifier_new() {
let qual = Qualifier::new("http://ns.adobe.com/xap/1.0/", "lang", "en-US");
assert_eq!(qual.namespace, "http://ns.adobe.com/xap/1.0/");
assert_eq!(qual.name, "lang");
assert_eq!(qual.value, "en-US");
}
#[test]
fn test_qualifier_path() {
let qual = Qualifier::new("http://ns.adobe.com/xap/1.0/", "lang", "en-US");
assert_eq!(qual.path(), "http://ns.adobe.com/xap/1.0/:lang");
}
}