easyofd_core/action/
gotoa.rs1use super::OfdAction;
6
7#[derive(Debug, Clone)]
13pub struct GotoA {
14 pub attach_id: String,
18}
19
20impl GotoA {
21 #[must_use]
25 pub fn new(attach_id: impl Into<String>) -> Self {
26 Self {
27 attach_id: attach_id.into(),
28 }
29 }
30}
31
32impl OfdAction for GotoA {
33 fn to_xml_string(&self) -> String {
34 format!("<ofd:GotoA AttachID=\"{}\"/>", self.attach_id)
35 }
36
37 fn clone_box(&self) -> Box<dyn OfdAction> {
38 Box::new(self.clone())
39 }
40}
41
42#[cfg(test)]
43mod tests {
44 use super::*;
45
46 #[test]
47 fn test_gotoa_new() {
48 let gotoa = GotoA::new("att_001");
49 assert_eq!(gotoa.attach_id, "att_001");
50 }
51
52 #[test]
53 fn test_gotoa_to_xml() {
54 let gotoa = GotoA::new("att_002");
55 let xml = gotoa.to_xml_string();
56 assert!(xml.contains("AttachID=\"att_002\""));
57 assert!(xml.contains("<ofd:GotoA"));
58 assert!(xml.ends_with("/>"));
59 }
60
61 #[test]
62 fn test_gotoa_from_string() {
63 let s = String::from("attachment_1");
64 let gotoa = GotoA::new(s);
65 assert_eq!(gotoa.attach_id, "attachment_1");
66 }
67
68 #[test]
69 fn test_gotoa_clone_debug() {
70 let gotoa = GotoA::new("att_1");
71 let gotoa2 = gotoa.clone();
72 assert_eq!(gotoa2.attach_id, "att_1");
73 let dbg = format!("{gotoa:?}");
74 assert!(dbg.contains("GotoA"));
75 }
76}