mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 07:02:24 +00:00
Migrate propfind and report to rustical_xml
This commit is contained in:
87
crates/dav/tests/propfind.rs
Normal file
87
crates/dav/tests/propfind.rs
Normal file
@@ -0,0 +1,87 @@
|
||||
use rustical_dav::xml::{PropElement, PropfindElement, PropfindType, Propname};
|
||||
use rustical_xml::de::XmlDocument;
|
||||
|
||||
#[test]
|
||||
fn propfind_allprop() {
|
||||
let propfind = PropfindElement::parse_str(
|
||||
r#"
|
||||
<propfind xmlns="DAV:">
|
||||
<allprop />
|
||||
</propfind>
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
propfind,
|
||||
PropfindElement {
|
||||
prop: PropfindType::Allprop
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn propfind_propname() {
|
||||
let propfind = PropfindElement::parse_str(
|
||||
r#"
|
||||
<propfind xmlns="DAV:">
|
||||
<propname />
|
||||
</propfind>
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
propfind,
|
||||
PropfindElement {
|
||||
prop: PropfindType::Propname
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn propfind_prop() {
|
||||
let propfind = PropfindElement::parse_str(
|
||||
r#"
|
||||
<propfind xmlns="DAV:">
|
||||
<prop>
|
||||
<displayname />
|
||||
<color />
|
||||
</prop>
|
||||
</propfind>
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
propfind,
|
||||
PropfindElement {
|
||||
prop: PropfindType::Prop(PropElement {
|
||||
prop: vec![
|
||||
Propname {
|
||||
name: "displayname".to_owned()
|
||||
},
|
||||
Propname {
|
||||
name: "color".to_owned()
|
||||
},
|
||||
]
|
||||
})
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/// Example taken from DAVx5
|
||||
#[test]
|
||||
fn propfind_decl() {
|
||||
let propfind = PropfindElement::parse_str(
|
||||
r#"
|
||||
<?xml version='1.0' encoding='UTF-8' ?>
|
||||
<propfind xmlns="DAV:" xmlns:CAL="urn:ietf:params:xml:ns:caldav" xmlns:CARD="urn:ietf:params:xml:ns:carddav">
|
||||
<prop>
|
||||
<CARD:max-resource-size />
|
||||
<CARD:supported-address-data />
|
||||
<supported-report-set />
|
||||
<n0:getctag xmlns:n0="http://calendarserver.org/ns/" />
|
||||
<sync-token />
|
||||
</prop>
|
||||
</propfind>
|
||||
"#
|
||||
).unwrap();
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
use rustical_dav::xml::TagList;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const INPUT: &str = r#"<Document>
|
||||
<prop>
|
||||
<nicename/>
|
||||
<anotherprop/>
|
||||
</prop>
|
||||
</Document>"#;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
struct PropElement {
|
||||
#[serde(flatten)]
|
||||
tags: TagList,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
struct Document {
|
||||
prop: PropElement,
|
||||
}
|
||||
|
||||
fn expected_output() -> Document {
|
||||
Document {
|
||||
prop: PropElement {
|
||||
tags: vec!["nicename".to_owned(), "anotherprop".to_owned()].into(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_tagname_deserialize() {
|
||||
let result: Document = quick_xml::de::from_str(INPUT).unwrap();
|
||||
assert_eq!(result, expected_output());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_tagname_serialize() {
|
||||
let mut result = String::new();
|
||||
let mut ser = quick_xml::se::Serializer::new(&mut result);
|
||||
ser.indent(' ', 4);
|
||||
|
||||
let to_serialize = &expected_output();
|
||||
to_serialize.serialize(ser).unwrap();
|
||||
|
||||
assert_eq!(result, INPUT);
|
||||
}
|
||||
Reference in New Issue
Block a user