use super::*;
use serde::Deserialize;
fn permissive_de(xml: &str) -> Deserializer<'_, SliceReader<'_>> {
let mut reader = NsReader::from_str(xml);
reader.config_mut().allow_unmatched_ends = true;
Deserializer::borrowing(reader)
}
#[test]
fn primitive() {
let mut de = permissive_de("</b>");
match String::deserialize(&mut de) {
Err(DeError::InvalidXml(Error::IllFormed(cause))) => {
assert_eq!(cause, IllFormedError::UnmatchedEndTag("b".into()))
}
x => panic!(
"Expected `Err(InvalidXml(IllFormed(UnmatchedEndTag(_))))`, but got `{:?}`",
x
),
}
}
#[test]
fn struct_() {
#[derive(Debug, Deserialize)]
#[allow(unused)]
struct Foo {
a: String,
}
let mut de = permissive_de("</b>");
match Foo::deserialize(&mut de) {
Err(DeError::InvalidXml(Error::IllFormed(cause))) => {
assert_eq!(cause, IllFormedError::UnmatchedEndTag("b".into()))
}
x => panic!(
"Expected `Err(InvalidXml(IllFormed(UnmatchedEndTag(_))))`, but got `{:?}`",
x
),
}
}
#[test]
fn unit_struct() {
#[derive(Debug, Deserialize)]
struct Unit;
let mut de = permissive_de("</b>");
match Unit::deserialize(&mut de) {
Err(DeError::InvalidXml(Error::IllFormed(cause))) => {
assert_eq!(cause, IllFormedError::UnmatchedEndTag("b".into()))
}
x => panic!(
"Expected `Err(InvalidXml(IllFormed(UnmatchedEndTag(_))))`, but got `{:?}`",
x
),
}
}
#[test]
fn enum_() {
#[derive(Debug, Deserialize)]
#[allow(unused)]
enum E {
A,
B,
}
let mut de = permissive_de("</b>");
match E::deserialize(&mut de) {
Err(DeError::InvalidXml(Error::IllFormed(cause))) => {
assert_eq!(cause, IllFormedError::UnmatchedEndTag("b".into()))
}
x => panic!(
"Expected `Err(InvalidXml(IllFormed(UnmatchedEndTag(_))))`, but got `{:?}`",
x
),
}
}
#[test]
fn leading_stray_end_before_valid_document() {
#[derive(Debug, Deserialize)]
#[allow(unused)]
struct Foo {
a: String,
}
let mut de = permissive_de("</b><Foo><a>1</a></Foo>");
match Foo::deserialize(&mut de) {
Err(DeError::InvalidXml(Error::IllFormed(cause))) => {
assert_eq!(cause, IllFormedError::UnmatchedEndTag("b".into()))
}
x => panic!(
"Expected `Err(InvalidXml(IllFormed(UnmatchedEndTag(_))))`, but got `{:?}`",
x
),
}
}