use super::{CTDest, OfdAction};
#[derive(Debug, Clone)]
pub struct Goto {
pub dest: CTDest,
}
impl Goto {
#[must_use]
pub fn new(dest: CTDest) -> Self {
Self { dest }
}
}
impl OfdAction for Goto {
fn to_xml_string(&self) -> String {
format!("<ofd:Goto>{}</ofd:Goto>", self.dest.to_xml_string())
}
fn clone_box(&self) -> Box<dyn OfdAction> {
Box::new(self.clone())
}
}
#[cfg(test)]
mod tests {
use super::super::DestType;
use super::*;
#[test]
fn test_goto_new() {
let dest = CTDest::new(3).dest_type(DestType::XYZ).left(10.0).top(20.0);
let goto = Goto::new(dest);
assert_eq!(goto.dest.page, 3);
}
#[test]
fn test_goto_to_xml() {
let dest = CTDest::new(1).dest_type(DestType::Fit);
let goto = Goto::new(dest);
let xml = goto.to_xml_string();
assert!(xml.contains("<ofd:Goto>"));
assert!(xml.contains("PageID=\"1\""));
assert!(xml.contains("Type=\"Fit\""));
assert!(xml.contains("</ofd:Goto>"));
}
#[test]
fn test_goto_clone_debug() {
let dest = CTDest::new(5);
let goto = Goto::new(dest);
let goto2 = goto.clone();
assert_eq!(goto2.dest.page, 5);
let dbg = format!("{goto:?}");
assert!(dbg.contains("Goto"));
}
}