xml: Add test that untagged enums work properly

This commit is contained in:
Lennart
2025-01-18 14:00:12 +01:00
parent 808deabad3
commit e04ae59296

View File

@@ -112,3 +112,52 @@ fn test_enum_document() {
Document::Goodbye Document::Goodbye
); );
} }
#[test]
fn test_untagged_enum() {
#[derive(Debug, XmlDeserialize, XmlRootTag, PartialEq)]
#[xml(root = b"document")]
struct Document {
prop: PropElement,
}
#[derive(Debug, XmlDeserialize, PartialEq)]
struct PropElement {
#[xml(ty = "untagged", flatten)]
props: Vec<Prop>,
}
#[derive(Debug, XmlDeserialize, PartialEq)]
#[xml(untagged)]
enum Prop {
DefaultProp(DefaultProp),
ExtensionProp(ExtensionProp),
}
#[derive(Debug, XmlDeserialize, PartialEq)]
enum DefaultProp {
Displayname(String),
}
#[derive(Debug, XmlDeserialize, PartialEq)]
enum ExtensionProp {
Extension(Extension),
}
#[derive(Debug, XmlDeserialize, PartialEq)]
struct Extension {
okay: Option<()>,
nice: Option<()>,
}
let doc = Document::parse_str(
r#"<document>
<prop>
<displayname>Hello</displayname>
<extension><okay /></extension>
<displayname>Hello</displayname>
</prop>
</document>"#,
)
.unwrap();
dbg!(doc);
}