easyofd_core/extensions/
property.rs1#[derive(Debug, Clone)]
7pub struct Property {
8 pub name: String,
10 pub value: String,
12}
13
14impl Property {
15 #[must_use]
17 pub fn new(name: impl Into<String>, value: impl Into<String>) -> Self {
18 Self {
19 name: name.into(),
20 value: value.into(),
21 }
22 }
23
24 #[must_use]
26 pub fn to_xml_string(&self) -> String {
27 format!(
28 "<Property Name=\"{}\" Value=\"{}\"/>",
29 self.name, self.value
30 )
31 }
32}
33
34#[cfg(test)]
35mod tests {
36 use super::*;
37
38 #[test]
39 fn test_property_new() {
40 let p = Property::new("key", "value");
41 assert_eq!(p.name, "key");
42 assert_eq!(p.value, "value");
43 }
44
45 #[test]
46 fn test_property_xml() {
47 let p = Property::new("encoding", "UTF-8");
48 let xml = p.to_xml_string();
49 assert!(xml.contains("Name=\"encoding\""));
50 assert!(xml.contains("Value=\"UTF-8\""));
51 assert!(xml.contains("/>"));
52 }
53}