mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 18:12:27 +00:00
xml: Add test that untagged enums work properly
This commit is contained in:
@@ -112,3 +112,52 @@ fn test_enum_document() {
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user