Hello
\n"); } #[test] fn test_serialize_element_with_attributes() { let mut doc = Document::new(); let root = doc.root(); let elem = doc.create_node(NodeKind::Element { name: "div".to_string(), prefix: None, namespace: None, attributes: vec![ Attribute { name: "id".to_string(), value: "main".to_string(), prefix: None, namespace: None, raw_value: None, }, Attribute { name: "class".to_string(), value: "big".to_string(), prefix: None, namespace: None, raw_value: None, }, ], }); doc.append_child(root, elem); assert_eq!( serialize(&doc), "\na < b & c > d
\n" ); } #[test] fn test_serialize_comment() { let mut doc = Document::new(); let root = doc.root(); let comment = doc.create_node(NodeKind::Comment { content: " a comment ".to_string(), }); doc.append_child(root, comment); assert_eq!( serialize(&doc), "\n\n" ); } #[test] fn test_serialize_cdata() { let mut doc = Document::new(); let root = doc.root(); let elem = doc.create_node(NodeKind::Element { name: "script".to_string(), prefix: None, namespace: None, attributes: vec![], }); let cdata = doc.create_node(NodeKind::CData { content: "x < 1 && y > 2".to_string(), }); doc.append_child(root, elem); doc.append_child(elem, cdata); assert_eq!( serialize(&doc), "\n\n" ); } #[test] fn test_serialize_processing_instruction() { let mut doc = Document::new(); let root = doc.root(); let pi = doc.create_node(NodeKind::ProcessingInstruction { target: "xml-stylesheet".to_string(), data: Some("type=\"text/css\" href=\"style.css\"".to_string()), }); doc.append_child(root, pi); assert_eq!( serialize(&doc), "\n\n" ); } #[test] fn test_serialize_xml_declaration() { let mut doc = Document::new(); doc.version = Some("1.0".to_string()); doc.encoding = Some("UTF-8".to_string()); let root = doc.root(); let elem = doc.create_node(NodeKind::Element { name: "root".to_string(), prefix: None, namespace: None, attributes: vec![], }); doc.append_child(root, elem); assert_eq!( serialize(&doc), "\nHello world
Hello world
")); } #[test] fn test_serialize_pretty_print_custom_indent() { let doc = Document::parse_str("