// Support functions for smite tests use std::rc::Rc; use xrust::item::{Item, Node}; use xrust::namespace::NamespaceMap; use xrust::parser::xml::{parse as xmlparse, parse_with_ns}; use xrust::qname::QualifiedName; use xrust::trees::smite::RNode; use xrust::value::Value; use xrust::xdmerror::Error; #[allow(dead_code)] pub fn make_empty_doc() -> RNode { RNode::new_document() } #[allow(dead_code)] pub fn make_doc(n: Rc, v: Value) -> RNode { let mut d = RNode::new_document(); let mut child = d.new_element(n).expect("unable to create element"); d.push(child.clone()).expect("unable to add element node"); child .push( child .new_text(Rc::new(v)) .expect("unable to create text node"), ) .expect("unable to add text node"); d } #[allow(dead_code)] pub fn make_sd_raw() -> RNode { let doc = RNode::new_document(); xmlparse(doc.clone(), "", None).expect("unable to parse XML"); doc } #[allow(dead_code)] pub fn make_sd_cooked() -> Result { Ok(make_sd_raw()) } #[allow(dead_code)] pub fn make_sd() -> Item { Item::Node(make_sd_raw()) } #[allow(dead_code)] pub fn make_from_str(s: &str) -> Result { let doc = RNode::new_document(); xmlparse(doc.clone(), s, None)?; Ok(doc) } #[allow(dead_code)] pub fn make_from_str_with_ns(s: &str) -> Result<(RNode, Rc), Error> { let doc = RNode::new_document(); let r = parse_with_ns(doc.clone(), s, None)?; Ok(r) }