rustical_xml: Use darling for proc-macro parsing

This commit is contained in:
Lennart
2024-11-27 17:47:55 +01:00
parent a9ef680c30
commit 57268f202d
11 changed files with 227 additions and 479 deletions

View File

@@ -62,8 +62,9 @@ fn test_struct_document() {
#[test]
fn test_struct_rename_field() {
#[derive(Debug, XmlDeserialize, PartialEq)]
#[xml(root = b"document")]
struct Document {
#[xml(rename = "ok-wow")]
#[xml(rename = b"ok-wow")]
child: Child,
}
@@ -73,12 +74,6 @@ fn test_struct_rename_field() {
text: String,
}
impl XmlRoot for Document {
fn root_tag() -> &'static [u8] {
b"document"
}
}
let doc = Document::parse_str(r#"<document><ok-wow>Hello!</ok-wow></document>"#).unwrap();
assert_eq!(
doc,
@@ -93,17 +88,12 @@ fn test_struct_rename_field() {
#[test]
fn test_struct_optional_field() {
#[derive(Debug, XmlDeserialize, PartialEq)]
#[xml(root = b"document")]
struct Document {
#[xml(default = "Default::default")]
child: Option<Child>,
}
impl XmlRoot for Document {
fn root_tag() -> &'static [u8] {
b"document"
}
}
#[derive(Debug, XmlDeserialize, PartialEq, Default)]
struct Child;
@@ -119,7 +109,7 @@ fn test_struct_vec() {
#[derive(Debug, XmlDeserialize, PartialEq)]
#[xml(root = b"document")]
struct Document {
#[xml(rename = "child", flatten)]
#[xml(rename = b"child", flatten)]
children: Vec<Child>,
}
@@ -147,7 +137,7 @@ fn test_struct_set() {
#[derive(Debug, XmlDeserialize, PartialEq)]
#[xml(root = b"document")]
struct Document {
#[xml(rename = "child", flatten)]
#[xml(rename = b"child", flatten)]
children: HashSet<Child>,
}