mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 07:02:24 +00:00
Some initial work on xml parsing
This commit is contained in:
45
crates/xml/tests/de_enum.rs
Normal file
45
crates/xml/tests/de_enum.rs
Normal file
@@ -0,0 +1,45 @@
|
||||
use rustical_xml::XmlRoot;
|
||||
use xml_derive::XmlDeserialize;
|
||||
|
||||
#[test]
|
||||
fn test_struct_untagged_enum() {
|
||||
#[derive(Debug, XmlDeserialize, PartialEq)]
|
||||
struct Propfind {
|
||||
prop: Prop,
|
||||
}
|
||||
|
||||
#[derive(Debug, XmlDeserialize, PartialEq)]
|
||||
struct Prop {
|
||||
#[xml(untagged)]
|
||||
prop: PropEnum,
|
||||
}
|
||||
|
||||
#[derive(Debug, XmlDeserialize, PartialEq)]
|
||||
enum PropEnum {
|
||||
A,
|
||||
B,
|
||||
}
|
||||
|
||||
impl XmlRoot for Propfind {
|
||||
fn root_tag() -> &'static [u8] {
|
||||
b"propfind"
|
||||
}
|
||||
}
|
||||
|
||||
let doc = Propfind::parse_str(
|
||||
r#"
|
||||
<propfind>
|
||||
<prop>
|
||||
<A/>
|
||||
</prop>
|
||||
</propfind>
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
doc,
|
||||
Propfind {
|
||||
prop: Prop { prop: PropEnum::A }
|
||||
}
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user