mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 01:12:24 +00:00
xml: Implement XmlSerialize for enums
This commit is contained in:
27
crates/xml/tests/se_enum.rs
Normal file
27
crates/xml/tests/se_enum.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
use rustical_xml::{XmlRootTag, XmlSerialize, XmlSerializeRoot};
|
||||
|
||||
#[test]
|
||||
fn test_struct_value_tagged() {
|
||||
#[derive(Debug, XmlRootTag, XmlSerialize, PartialEq)]
|
||||
#[xml(root = b"propfind")]
|
||||
struct Document {
|
||||
prop: Prop,
|
||||
}
|
||||
|
||||
#[derive(Debug, XmlSerialize, PartialEq)]
|
||||
enum Prop {
|
||||
Test(String),
|
||||
Hello(usize),
|
||||
Unit,
|
||||
}
|
||||
|
||||
let mut buf = Vec::new();
|
||||
let mut writer = quick_xml::Writer::new(&mut buf);
|
||||
Document {
|
||||
prop: Prop::Test("asd".to_owned()),
|
||||
}
|
||||
.serialize_root(&mut writer)
|
||||
.unwrap();
|
||||
let out = String::from_utf8(buf).unwrap();
|
||||
assert_eq!(out, "<propfind><prop><test>asd</test></prop></propfind>");
|
||||
}
|
||||
Reference in New Issue
Block a user