#![allow(unused_imports, unused_variables, unused_mut)]
#[test]
fn lib_rs_example_1() -> impl std::process::Termination {
use crate::parser_xmloxide as xmloxide;
use xmloxide::Document;
let doc = Document::parse_str("<root><child>Hello</child></root>").unwrap();
let root = doc.root_element().unwrap();
assert_eq!(doc.node_name(root), Some("root"));
}
#[test]
fn parser_mod_rs_example_1() -> impl std::process::Termination {
use crate::parser_xmloxide as xmloxide;
use xmloxide::parser::ParseOptions;
let opts = ParseOptions::default()
.recover(true)
.no_blanks(true)
.max_depth(128);
}
#[test]
fn parser_push_rs_example_1() -> impl std::process::Termination {
use crate::parser_xmloxide as xmloxide;
use xmloxide::parser::PushParser;
let mut parser = PushParser::new();
parser.push(b"<root>");
parser.push(b"<child>Hello</child>");
parser.push(b"</root>");
let doc = parser.finish().unwrap();
let root = doc.root_element().unwrap();
assert_eq!(doc.node_name(root), Some("root"));
}
#[test]
fn parser_push_rs_example_2() -> impl std::process::Termination {
use crate::parser_xmloxide as xmloxide;
use xmloxide::parser::PushParser;
let mut parser = PushParser::new();
parser.push(b"<?xml version=\"1.0\"?>");
parser.push(b"<root attr=\"value\">");
parser.push(b"Hello, world!");
parser.push(b"</root>");
let doc = parser.finish().unwrap();
let root = doc.root_element().unwrap();
assert_eq!(doc.node_name(root), Some("root"));
assert_eq!(doc.text_content(root), "Hello, world!");
}
#[test]
fn parser_push_rs_example_3() -> impl std::process::Termination {
use crate::parser_xmloxide as xmloxide;
use xmloxide::parser::{ParseOptions, PushParser};
let opts = ParseOptions::default().recover(true);
let mut parser = PushParser::with_options(opts);
parser.push(b"<root>");
parser.push(b"</root>");
let doc = parser.finish().unwrap();
assert!(doc.root_element().is_some());
}
#[test]
fn parser_push_rs_example_4() -> impl std::process::Termination {
use crate::parser_xmloxide as xmloxide;
use xmloxide::parser::PushParser;
let mut parser = PushParser::new();
parser.push(b"<root/>");
let doc = parser.finish().unwrap();
}
#[test]
fn parser_push_rs_example_5() -> impl std::process::Termination {
use crate::parser_xmloxide as xmloxide;
use xmloxide::parser::{ParseOptions, PushParser};
let parser = PushParser::with_options(ParseOptions::default().recover(true).no_blanks(true));
}
#[test]
fn parser_push_rs_example_6() -> impl std::process::Termination {
use crate::parser_xmloxide as xmloxide;
use xmloxide::parser::PushParser;
let mut parser = PushParser::new();
parser.push(b"<ro");
parser.push(b"ot/>");
let doc = parser.finish().unwrap();
}
#[test]
fn parser_push_rs_example_7() -> impl std::process::Termination {
use crate::parser_xmloxide as xmloxide;
use xmloxide::parser::PushParser;
let mut parser = PushParser::new();
parser.push(b"<root><child/></root>");
let doc = parser.finish().unwrap();
}
#[test]
fn parser_push_rs_example_8() -> impl std::process::Termination {
use crate::parser_xmloxide as xmloxide;
use xmloxide::parser::PushParser;
let mut parser = PushParser::new();
assert_eq!(parser.buffered_bytes(), 0);
parser.push(b"<root/>");
assert_eq!(parser.buffered_bytes(), 7);
}
#[test]
fn parser_push_rs_example_9() -> impl std::process::Termination {
use crate::parser_xmloxide as xmloxide;
use xmloxide::parser::PushParser;
let mut parser = PushParser::new();
assert!(parser.is_empty());
parser.push(b"<root/>");
assert!(!parser.is_empty());
}
#[test]
fn parser_push_rs_example_10() -> impl std::process::Termination {
use crate::parser_xmloxide as xmloxide;
use xmloxide::parser::PushParser;
let mut parser = PushParser::new();
parser.push(b"<root/>");
parser.reset();
assert!(parser.is_empty());
parser.push(b"<other/>");
let doc = parser.finish().unwrap();
}
#[test]
fn tree_mod_rs_example_1() -> impl std::process::Termination {
use crate::parser_xmloxide as xmloxide;
use xmloxide::Document;
let doc = Document::parse_str("<root/>").unwrap();
let root = doc.root_element().unwrap();
assert_eq!(doc.node_name(root), Some("root"));
}
#[test]
fn tree_mod_rs_example_2() -> impl std::process::Termination {
use crate::parser_xmloxide as xmloxide;
use xmloxide::Document;
let doc = Document::parse_str("<root><child/></root>").unwrap();
}
#[test]
fn tree_mod_rs_example_3() -> impl std::process::Termination {
use crate::parser_xmloxide as xmloxide;
use xmloxide::Document;
let doc = Document::parse_bytes(b"<root/>").unwrap();
let root = doc.root_element().unwrap();
assert_eq!(doc.node_name(root), Some("root"));
}
#[test]
fn tree_mod_rs_example_4() -> impl std::process::Termination {
use crate::parser_xmloxide as xmloxide;
let _compile_only = || {
use xmloxide::Document;
let doc = Document::parse_file("document.xml").unwrap();
};
}
#[test]
fn tree_mod_rs_example_5() -> impl std::process::Termination {
use crate::parser_xmloxide as xmloxide;
use xmloxide::Document;
let mut doc = Document::parse_str("<root><child>Hello</child></root>").unwrap();
let root = doc.root_element().unwrap();
let child = doc.first_child(root).unwrap();
let cloned = doc.clone_node(child, true);
doc.append_child(root, cloned);
}
#[test]
fn tree_mod_rs_example_6() -> impl std::process::Termination {
use crate::parser_xmloxide as xmloxide;
use xmloxide::Document;
let mut doc = Document::parse_str("<root>old</root>").unwrap();
let root = doc.root_element().unwrap();
let text_node = doc.first_child(root).unwrap();
assert!(doc.set_text_content(text_node, "new"));
assert_eq!(doc.text_content(root), "new");
}
#[test]
fn encoding_mod_rs_example_1() -> impl std::process::Termination {
use crate::parser_xmloxide as xmloxide;
use xmloxide::encoding::detect_encoding;
let (enc, skip) = detect_encoding(b"\xEF\xBB\xBFhello");
assert_eq!(enc, "UTF-8");
assert_eq!(skip, 3);
let (enc, skip) = detect_encoding(b"<root/>");
assert_eq!(enc, "UTF-8");
assert_eq!(skip, 0);
}
#[test]
fn encoding_mod_rs_example_2() -> impl std::process::Termination {
use crate::parser_xmloxide as xmloxide;
use xmloxide::encoding::transcode;
let result = transcode(b"hello", "UTF-8").unwrap();
assert_eq!(result, "hello");
}
#[test]
fn encoding_mod_rs_example_3() -> impl std::process::Termination {
use crate::parser_xmloxide as xmloxide;
use xmloxide::encoding::decode_to_utf8;
let xml = b"<?xml version=\"1.0\"?><root/>";
let result = decode_to_utf8(xml).unwrap();
assert!(result.contains("<root/>"));
}
#[test]
fn validation_mod_rs_example_1() -> impl std::process::Termination {
use crate::parser_xmloxide as xmloxide;
use xmloxide::validation::ValidationResult;
let result = ValidationResult {
is_valid: true,
errors: vec![],
warnings: vec![],
};
assert!(result.is_valid);
}
#[test]
fn validation_dtd_rs_example_1() -> impl std::process::Termination {
use crate::parser_xmloxide as xmloxide;
use xmloxide::validation::dtd::parse_dtd;
let dtd = parse_dtd("<!ELEMENT root (#PCDATA)>").unwrap();
assert!(dtd.elements.contains_key("root"));
}
#[test]
fn validation_dtd_rs_example_2() -> impl std::process::Termination {
use crate::parser_xmloxide as xmloxide;
use xmloxide::Document;
use xmloxide::validation::dtd::{parse_dtd, validate};
let dtd = parse_dtd("<!ELEMENT root (#PCDATA)>").unwrap();
let mut doc = Document::parse_str("<!DOCTYPE root><root>hello</root>").unwrap();
let result = validate(&mut doc, &dtd);
assert!(result.is_valid);
}
#[test]
fn serial_xml_rs_example_1() -> impl std::process::Termination {
use crate::parser_xmloxide as xmloxide;
use xmloxide::Document;
use xmloxide::serial::{SerializeOptions, serialize_with_options};
let doc = Document::parse_str("<root><child>Hello</child></root>").unwrap();
let xml = serialize_with_options(&doc, &SerializeOptions::default().indent(true));
assert!(xml.contains(" <child>"));
}
#[test]
fn serial_xml_rs_example_2() -> impl std::process::Termination {
use crate::parser_xmloxide as xmloxide;
use xmloxide::Document;
use xmloxide::serial::serialize;
let doc = Document::parse_str("<root><child>Hello</child></root>").unwrap();
let xml = serialize(&doc);
assert!(xml.contains("<root>"));
}
#[test]
fn serial_xml_rs_example_3() -> impl std::process::Termination {
use crate::parser_xmloxide as xmloxide;
use xmloxide::Document;
use xmloxide::serial::{SerializeOptions, serialize_with_options};
let doc = Document::parse_str("<root><child>Hello</child></root>").unwrap();
let xml = serialize_with_options(&doc, &SerializeOptions::default().indent(true));
assert!(xml.contains(" <child>"));
}