easyofd_core/action/
goto.rs1use super::{CTDest, OfdAction};
6
7#[derive(Debug, Clone)]
13pub struct Goto {
14 pub dest: CTDest,
18}
19
20impl Goto {
21 #[must_use]
25 pub fn new(dest: CTDest) -> Self {
26 Self { dest }
27 }
28}
29
30impl OfdAction for Goto {
31 fn to_xml_string(&self) -> String {
32 format!("<ofd:Goto>{}</ofd:Goto>", self.dest.to_xml_string())
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::super::DestType;
43 use super::*;
44
45 #[test]
46 fn test_goto_new() {
47 let dest = CTDest::new(3).dest_type(DestType::XYZ).left(10.0).top(20.0);
48 let goto = Goto::new(dest);
49 assert_eq!(goto.dest.page, 3);
50 }
51
52 #[test]
53 fn test_goto_to_xml() {
54 let dest = CTDest::new(1).dest_type(DestType::Fit);
55 let goto = Goto::new(dest);
56 let xml = goto.to_xml_string();
57 assert!(xml.contains("<ofd:Goto>"));
58 assert!(xml.contains("PageID=\"1\""));
59 assert!(xml.contains("Type=\"Fit\""));
60 assert!(xml.contains("</ofd:Goto>"));
61 }
62
63 #[test]
64 fn test_goto_clone_debug() {
65 let dest = CTDest::new(5);
66 let goto = Goto::new(dest);
67 let goto2 = goto.clone();
68 assert_eq!(goto2.dest.page, 5);
69 let dbg = format!("{goto:?}");
70 assert!(dbg.contains("Goto"));
71 }
72}