use xot::Xot;
#[test]
fn test_parse_invalid_close_tag() {
let xml = r#""#;
let mut xot = Xot::new();
let err = xot.parse(xml).unwrap_err();
assert!(matches!(err, xot::ParseError::InvalidCloseTag { .. }));
assert_eq!(err.span(), (7..8).into());
}
#[test]
fn test_parse_invalid_close_tag_prefix() {
let xml = r#""#;
let mut xot = Xot::new();
let err = xot.parse(xml).unwrap_err();
assert!(matches!(err, xot::ParseError::InvalidCloseTag { .. }));
assert_eq!(err.span(), (36..41).into());
}
#[test]
fn test_unknown_prefix() {
let xml = r#""#;
let mut xot = Xot::new();
let err = xot.parse(xml).unwrap_err();
assert!(matches!(err, xot::ParseError::UnknownPrefix { .. }));
assert_eq!(err.span(), (6..7).into());
}
#[test]
fn test_unsupported_version() {
let xml = r#""#;
let mut xot = Xot::new();
let err = xot.parse(xml).unwrap_err();
assert!(matches!(err, xot::ParseError::UnsupportedVersion { .. }));
assert_eq!(err.span(), (15..18).into());
}
#[test]
fn test_unsupported_not_standalone() {
let xml = r#""#;
let mut xot = Xot::new();
let err = xot.parse(xml).unwrap_err();
assert!(matches!(
err,
xot::ParseError::UnsupportedNotStandalone { .. }
));
assert_eq!(err.span(), (0..37).into());
}
#[test]
fn test_xmlparser_error() {
let xml = r#"<"#;
let mut xot = Xot::new();
let err = xot.parse(xml).unwrap_err();
assert!(matches!(err, xot::ParseError::XmlParser { .. }));
assert_eq!(err.span(), (5..5).into());
}
#[test]
fn test_duplicate_attribute() {
let xml = r#""#;
let mut xot = Xot::new();
let err = xot.parse(xml).unwrap_err();
assert!(matches!(err, xot::ParseError::DuplicateAttribute { .. }));
assert_eq!(err.span(), (11..12).into());
}
#[test]
fn test_duplicate_attribute_with_prefix() {
let xml = r#""#;
let mut xot = Xot::new();
let err = xot.parse(xml).unwrap_err();
assert!(matches!(err, xot::ParseError::DuplicateAttribute { .. }));
assert_eq!(err.span(), (42..45).into());
}
#[test]
fn test_invalid_dtd() {
let xml = r#""#;
let mut xot = Xot::new();
let err = xot.parse(xml).unwrap_err();
assert!(matches!(err, xot::ParseError::DtdUnsupported { .. }));
assert_eq!(err.span(), (0..15).into());
}
#[test]
fn test_dtd_unsupported() {
let xml = r#""#;
let mut xot = Xot::new();
let err = xot.parse(xml).unwrap_err();
assert!(matches!(err, xot::ParseError::DtdUnsupported { .. }));
assert_eq!(err.span(), (0..33).into());
}
#[test]
fn test_dtd_unsupported2() {
let xml = r#""#;
let mut xot = Xot::new();
let err = xot.parse(xml).unwrap_err();
assert!(matches!(err, xot::ParseError::DtdUnsupported { .. }));
assert_eq!(err.span(), (21..54).into());
}
#[test]
fn test_unclosed_tag() {
let xml = r#""#;
let mut xot = Xot::new();
let err = xot.parse(xml).unwrap_err();
assert!(matches!(err, xot::ParseError::UnclosedTag(_)));
assert_eq!(err.span(), (1..4).into());
}
#[test]
fn test_unclosed_tag_middle() {
let xml = r#""#;
let mut xot = Xot::new();
let err = xot.parse(xml).unwrap_err();
assert!(matches!(err, xot::ParseError::InvalidCloseTag(_, _, _)));
assert_eq!(err.span(), (10..13).into());
}
#[test]
fn test_unclosed_tag_with_prefix() {
let xml = r#""#;
let mut xot = Xot::new();
let err = xot.parse(xml).unwrap_err();
assert!(matches!(err, xot::ParseError::UnclosedTag(_)));
assert_eq!(err.span(), (1..6).into());
}
#[test]
fn test_only_text_top_level() {
let xml = r#"abc"#;
let mut xot = Xot::new();
let err = xot.parse(xml).unwrap_err();
assert!(matches!(err, xot::ParseError::XmlParser { .. }));
assert_eq!(err.span(), (0..0).into());
}
#[test]
fn test_only_comment_top_level() {
let xml = r#""#;
let mut xot = Xot::new();
let err = xot.parse(xml).unwrap_err();
assert!(matches!(err, xot::ParseError::NoElementAtTopLevel { .. }));
assert_eq!(err.span(), (12..12).into());
}
#[test]
fn test_unclosed_entity() {
let xml = r#"&foo"#;
let mut xot = Xot::new();
let err = xot.parse(xml).unwrap_err();
assert!(matches!(err, xot::ParseError::UnclosedEntity(_, _)));
assert_eq!(err.span(), (5..5).into());
}
#[test]
fn test_invalid_entity() {
let xml = r#"&foo;"#;
let mut xot = Xot::new();
let err = xot.parse(xml).unwrap_err();
assert!(matches!(err, xot::ParseError::InvalidEntity(_, _)));
assert_eq!(err.span(), (5..10).into());
}