easyofd_core/action/
uri.rs1use super::OfdAction;
6
7#[derive(Debug, Clone)]
13pub struct URI {
14 pub uri: String,
18}
19
20impl URI {
21 #[must_use]
25 pub fn new(uri: impl Into<String>) -> Self {
26 Self { uri: uri.into() }
27 }
28}
29
30impl OfdAction for URI {
31 fn to_xml_string(&self) -> String {
32 format!("<ofd:URI URI=\"{}\"/>", self.uri)
33 }
34
35 fn clone_box(&self) -> Box<dyn OfdAction> {
36 Box::new(self.clone())
37 }
38}
39
40#[cfg(test)]
41mod tests {
42 use super::*;
43
44 #[test]
45 fn test_uri_new() {
46 let uri = URI::new("https://example.com");
47 assert_eq!(uri.uri, "https://example.com");
48 }
49
50 #[test]
51 fn test_uri_to_xml() {
52 let uri = URI::new("https://example.com/path?q=1");
53 let xml = uri.to_xml_string();
54 assert!(xml.contains("URI=\"https://example.com/path?q=1\""));
55 assert!(xml.contains("<ofd:URI"));
56 assert!(xml.ends_with("/>"));
57 }
58
59 #[test]
60 fn test_uri_from_string() {
61 let s = String::from("http://test.org");
62 let uri = URI::new(s);
63 assert_eq!(uri.uri, "http://test.org");
64 }
65
66 #[test]
67 fn test_uri_clone_debug() {
68 let uri = URI::new("https://a.b");
69 let uri2 = uri.clone();
70 assert_eq!(uri2.uri, "https://a.b");
71 let dbg = format!("{uri:?}");
72 assert!(dbg.contains("URI"));
73 }
74}