use sup_xml::{parse_str, xpath_str, ParseOptions};
fn parse(xml: &str) -> sup_xml::Document {
parse_str(xml, &ParseOptions::default()).expect("test document must parse")
}
#[test]
fn version_1_1_decl_is_accepted() {
let d = parse(r#"<?xml version="1.1"?><r><a>hello</a></r>"#);
assert_eq!(d.version, "1.1");
}
#[test]
fn version_1_1_decl_with_encoding_and_standalone() {
let d = parse(
r#"<?xml version="1.1" encoding="UTF-8" standalone="yes"?><r/>"#,
);
assert_eq!(d.version, "1.1");
assert_eq!(d.encoding, "UTF-8");
assert_eq!(d.standalone, Some(true));
}
#[test]
fn version_1_0_decl_still_default() {
let d = parse("<r/>");
assert_eq!(d.version, "1.0");
}
#[test]
fn nel_is_normalized_to_lf_in_1_1_text() {
let bytes: Vec<u8> = b"<?xml version=\"1.1\"?><r>a\xc2\x85b</r>".to_vec();
let xml = std::str::from_utf8(&bytes).unwrap();
let d = parse_str(xml, &ParseOptions::default())
.expect("NEL must parse in 1.1 text content");
assert_eq!(xpath_str(&d, "string(/r)").unwrap(), "a\nb");
}
#[test]
fn ls_is_normalized_to_lf_in_1_1_text() {
let bytes: Vec<u8> = b"<?xml version=\"1.1\"?><r>a\xe2\x80\xa8b</r>".to_vec();
let xml = std::str::from_utf8(&bytes).unwrap();
let d = parse_str(xml, &ParseOptions::default())
.expect("LS must parse in 1.1 text content");
assert_eq!(xpath_str(&d, "string(/r)").unwrap(), "a\nb");
}
#[test]
fn cr_nel_pair_collapses_in_1_1_text() {
let bytes: Vec<u8> = b"<?xml version=\"1.1\"?><r>a\r\xc2\x85b</r>".to_vec();
let xml = std::str::from_utf8(&bytes).unwrap();
let d = parse_str(xml, &ParseOptions::default()).unwrap();
assert_eq!(xpath_str(&d, "string(/r)").unwrap(), "a\nb");
}
#[test]
fn nel_left_alone_in_1_0_text() {
let bytes: Vec<u8> = b"<?xml version=\"1.0\"?><r>a\xc2\x85b</r>".to_vec();
let xml = std::str::from_utf8(&bytes).unwrap();
let d = parse_str(xml, &ParseOptions::default()).unwrap();
assert_eq!(xpath_str(&d, "string(/r)").unwrap(), "a\u{85}b");
}
#[test]
fn external_entity_version_check_is_documented() {
let xml = r#"<?xml version="1.1"?><r>ok</r>"#;
assert_eq!(parse(xml).version, "1.1");
}