use std::fs; use xrust::parser::xml; use xrust::trees::smite::RNode; use xrust::Node; #[test] fn serializer_issue_98() { /* Github issue number 98 We wish to have XML documents output attributes in some stable order for test purposes. IMPORTANT NOTE: We will be stable for a particular version, but XML itself does not care about attribute order. We may switch the ordering between versions if we find a technical reason to do so. */ let data = fs::read_to_string("tests/xml/issue-98.xml").unwrap(); let mut prev_xml_output = None; for iteration in 0..100 { let doc = xml::parse(RNode::new_document(), data.clone().as_str(), None).unwrap(); let xml_output = doc.to_xml(); if let Some(prev_xml_output) = &prev_xml_output { assert_eq!(&xml_output, prev_xml_output, "Failed on run {}", iteration); } prev_xml_output = Some(xml_output); } } #[test] fn serializer_1() { /* Testing the XML output, simple document. */ let data = ""; let doc = xml::parse(RNode::new_document(), data, None).unwrap(); let xml_output = doc.to_xml(); /* Note, xRust currently does not output self closing tags, if it does you'll need to update this test with assert_eq!(xml_output, ""); */ assert_eq!(xml_output, ""); } #[test] fn serializer_2() { /* Testing the XML output, with some namespaces. */ let data = ""; let doc = xml::parse(RNode::new_document(), data, None).unwrap(); let xml_output = doc.to_xml(); /* Note, xRust currently does not output self closing tags, if it does you'll need to update this test with assert_eq!(xml_output, ""); */ assert_eq!( xml_output, "" ); } #[test] fn serializer_3() { /* Testing the XML output, with some namespace aliases. */ let data = ""; let doc = xml::parse(RNode::new_document(), data, None).unwrap(); let xml_output = doc.to_xml(); /* Note, xRust currently does not output self closing tags, if it does you'll need to update this test with assert_eq!(xml_output, ""); */ assert_eq!( xml_output, "" ); } #[test] fn serializer_4() { /* Testing the XML output, mixed content */ let data = r#" text text3 text4 "#; let doc = xml::parse(RNode::new_document(), data, None).unwrap(); let xml_output = doc.to_xml(); /* Note, xRust currently does not output self closing tags, if it does you'll need to update this test with assert_eq!(xml_output, " text text3 text4 "); */ assert_eq!(xml_output, " text text3 text4 "); } #[test] #[ignore] fn serializer_5() { /* Testing the XML output, characters to be escaped */ let data = "XML escape test: < > & ' ""; let doc = xml::parse(RNode::new_document(), data, None).unwrap(); let xml_output = doc.to_xml(); assert_eq!( xml_output, "XML escape test: < > & ' "" ); }