xso-proc: add support for optional children

This commit is contained in:
Jonas Schäfer 2024-06-30 09:21:46 +02:00
commit 01336802b4
6 changed files with 133 additions and 11 deletions

View file

@ -521,3 +521,32 @@ fn parent_positive() {
.unwrap();
assert_eq!(v.child.foo, "hello world!");
}
#[derive(FromXml, AsXml, PartialEq, Debug, Clone)]
#[xml(namespace = NS1, name = "parent")]
struct OptionalChild {
#[xml(child(default))]
child: std::option::Option<RequiredAttribute>,
}
#[test]
fn optional_child_roundtrip_present() {
#[allow(unused_imports)]
use std::{
option::Option::{None, Some},
result::Result::{Err, Ok},
};
roundtrip_full::<OptionalChild>(
"<parent xmlns='urn:example:ns1'><attr foo='hello world!'/></parent>",
)
}
#[test]
fn optional_child_roundtrip_absent() {
#[allow(unused_imports)]
use std::{
option::Option::{None, Some},
result::Result::{Err, Ok},
};
roundtrip_full::<OptionalChild>("<parent xmlns='urn:example:ns1'/>")
}