use async_xml::from_str;
use async_xml_derive::FromXml;
#[tokio::test]
async fn test_children() {
let xml = r#"
text
some random text whatever
"#;
let de: TestChildren = from_str(xml).await.unwrap();
let expected = TestChildren {
text: "text".into(),
};
assert_eq!(de, expected);
}
#[tokio::test]
#[should_panic]
async fn test_children_disallowed() {
let xml = r#"
text
some random text whatever
"#;
let _: Test = from_str(xml).await.unwrap();
}
#[tokio::test]
async fn test_attributes() {
let xml = r#"
text
"#;
let de: TestAttributes = from_str(xml).await.unwrap();
let expected = TestAttributes {
text: "text".into(),
};
assert_eq!(de, expected);
}
#[tokio::test]
#[should_panic]
async fn test_attributes_disallowed() {
let xml = r#"
text
"#;
let _: Test = from_str(xml).await.unwrap();
}
#[derive(Debug, PartialEq, FromXml)]
pub struct Test {
#[async_xml(value)]
text: String,
}
#[derive(Debug, PartialEq, FromXml)]
#[async_xml(allow_unknown_children)]
pub struct TestChildren {
#[async_xml(value)]
text: String,
}
#[derive(Debug, PartialEq, FromXml)]
#[async_xml(allow_unknown_attributes)]
pub struct TestAttributes {
#[async_xml(value)]
text: String,
}