#[cfg(all(test, feature = "test-conformance-xml"))]
use std::fs;
#[cfg(all(test, feature = "test-conformance-xml"))]
use chadpath::item::Node;
#[cfg(all(test, feature = "test-conformance-xml"))]
use chadpath::parser::{ParseError, ParserStateBuilder, StaticStateBuilder, xml};
#[cfg(all(test, feature = "test-conformance-xml"))]
use chadpath::trees::smite::RNode;
#[cfg(all(test, feature = "test-conformance-xml"))]
use chadpath::{Error, ErrorKind};
#[cfg(all(test, feature = "test-conformance-xml"))]
fn test_xmltest_invalid(xmldoc: &str) {
let ss = StaticStateBuilder::new()
.dtd_resolver(dtdfileresolve())
.namespace(|_: &_| Err(ParseError::MissingNameSpace))
.build();
let testxml = RNode::new_document();
let ps = ParserStateBuilder::new()
.doc(testxml)
.document_location("tests/conformance/xml/xmlconf/xmltest/valid/not-sa/".to_string())
.build();
let parseresult = xml::parse_with_state(xmldoc, ps, ss);
assert!(parseresult.is_err());
}
#[cfg(all(test, feature = "test-conformance-xml"))]
fn dtdfileresolve() -> fn(Option<String>, String) -> Result<String, Error> {
move |locdir, uri| {
let u = match locdir {
None => uri,
Some(ld) => ld + uri.as_str(),
};
match fs::read_to_string(u) {
Err(_) => Err(Error::new(
ErrorKind::Unknown,
"Unable to read external DTD".to_string(),
)),
Ok(s) => Ok(s),
}
}
}
#[test]
#[ignore]
#[cfg(all(test, feature = "test-conformance-xml"))]
fn invalid002() {
test_xmltest_invalid(
fs::read_to_string("tests/conformance/xml/xmlconf/xmltest/invalid/002.xml")
.unwrap()
.as_str(),
);
}
#[test]
#[cfg(all(test, feature = "test-conformance-xml"))]
fn invalid005() {
test_xmltest_invalid(
fs::read_to_string("tests/conformance/xml/xmlconf/xmltest/invalid/005.xml")
.unwrap()
.as_str(),
);
}
#[test]
#[ignore]
#[cfg(all(test, feature = "test-conformance-xml"))]
fn invalid006() {
test_xmltest_invalid(
fs::read_to_string("tests/conformance/xml/xmlconf/xmltest/invalid/006.xml")
.unwrap()
.as_str(),
);
}
#[test]
#[cfg(all(test, feature = "test-conformance-xml"))]
fn invalidnotsa022() {
test_xmltest_invalid(
fs::read_to_string("tests/conformance/xml/xmlconf/xmltest/invalid/not-sa/022.xml")
.unwrap()
.as_str(),
);
}