mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 16:32:29 +00:00
xml serialize_to_string: Enable indentation
This commit is contained in:
@@ -33,7 +33,13 @@ mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
out,
|
out,
|
||||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<document><resourcetype><displayname xmlns=\"DAV:\"/><calendar-color xmlns=\"http://calendarserver.org/ns/\"/></resourcetype></document>"
|
r#"<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<document>
|
||||||
|
<resourcetype>
|
||||||
|
<displayname xmlns="DAV:"/>
|
||||||
|
<calendar-color xmlns="http://calendarserver.org/ns/"/>
|
||||||
|
</resourcetype>
|
||||||
|
</document>"#
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ pub trait XmlSerializeRoot {
|
|||||||
|
|
||||||
fn serialize_to_string(&self) -> std::io::Result<String> {
|
fn serialize_to_string(&self) -> std::io::Result<String> {
|
||||||
let mut buf: Vec<_> = b"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".into();
|
let mut buf: Vec<_> = b"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".into();
|
||||||
let mut writer = quick_xml::Writer::new(&mut buf);
|
let mut writer = quick_xml::Writer::new_with_indent(&mut buf, b' ', 4);
|
||||||
self.serialize_root(&mut writer)?;
|
self.serialize_root(&mut writer)?;
|
||||||
Ok(String::from_utf8_lossy(&buf).to_string())
|
Ok(String::from_utf8_lossy(&buf).to_string())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,11 @@ fn test_struct_value_tagged() {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
out,
|
out,
|
||||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<propfind><prop><test>asd</test></prop></propfind>"
|
r#"<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<propfind>
|
||||||
|
<prop>
|
||||||
|
<test>asd</test>
|
||||||
|
</prop>
|
||||||
|
</propfind>"#
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,11 @@ fn test_struct_value_tagged() {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
out,
|
out,
|
||||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<document><href>okay</href><num>123</num></document>"
|
r#"<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<document>
|
||||||
|
<href>okay</href>
|
||||||
|
<num>123</num>
|
||||||
|
</document>"#
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,7 +95,8 @@ fn test_struct_value_untagged() {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
out,
|
out,
|
||||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<document>okays</document>"
|
r#"<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<document>okays</document>"#
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,7 +116,11 @@ fn test_struct_vec() {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
out,
|
out,
|
||||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<document><href>okay</href><href>wow</href></document>"
|
r#"<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<document>
|
||||||
|
<href>okay</href>
|
||||||
|
<href>wow</href>
|
||||||
|
</document>"#
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +150,10 @@ fn test_struct_serialize_with() {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
out,
|
out,
|
||||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<document><href>OKAY</href></document>"
|
r#"<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<document>
|
||||||
|
<href>OKAY</href>
|
||||||
|
</document>"#
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user