format code

This commit is contained in:
Marc-Antoine Arnaud
2019-10-08 09:04:29 +02:00
parent dd5ca6df6b
commit 29e6736d8d
10 changed files with 172 additions and 114 deletions

View File

@@ -12,7 +12,10 @@ pub fn to_string<T: YaSerialize>(model: &T) -> Result<String, String> {
Ok(String::from(data))
}
pub fn to_string_with_config<T: YaSerialize>(model: &T, _config: &Config) -> Result<String, String> {
pub fn to_string_with_config<T: YaSerialize>(
model: &T,
_config: &Config,
) -> Result<String, String> {
let buf = Cursor::new(Vec::new());
let cursor = serialize_with_writer(model, buf)?;
let data = str::from_utf8(cursor.get_ref()).expect("Found invalid UTF-8");
@@ -104,5 +107,5 @@ impl<'de, W: Write> Serializer<W> {
pub struct Config {
perform_indent: bool,
write_document_declaration: bool,
indent_string: Option<String>
indent_string: Option<String>,
}

View File

@@ -23,7 +23,7 @@ fn de_struct_namespace() {
root = "book",
prefix = "ns",
namespace = "ns: http://www.sample.com/ns/domain",
namespace = "ns2: http://www.sample.com/ns/domain_2",
namespace = "ns2: http://www.sample.com/ns/domain_2"
)]
pub struct Book {
#[yaserde(prefix = "ns")]
@@ -83,7 +83,10 @@ fn de_struct_namespace() {
<ns:title>Little prince</ns:title>
</ns:book>"#;
let loaded: Result<Book, String> = from_str(content);
assert_eq!(loaded, Err("bad namespace for book, found http://www.sample.com/ns/domain2".to_string()));
assert_eq!(
loaded,
Err("bad namespace for book, found http://www.sample.com/ns/domain2".to_string())
);
}
#[test]

View File

@@ -36,7 +36,8 @@ fn se_default_field_string() {
},
content
);
let content = "<?xml version=\"1.0\" encoding=\"utf-8\"?><base><background>my_value</background></base>";
let content =
"<?xml version=\"1.0\" encoding=\"utf-8\"?><base><background>my_value</background></base>";
convert_and_validate!(
XmlStruct {
background: "my_value".to_string(),
@@ -61,13 +62,9 @@ fn se_default_field_boolean() {
let content = "<?xml version=\"1.0\" encoding=\"utf-8\"?><base />";
convert_and_validate!(XmlStruct { background: true }, content);
let content = "<?xml version=\"1.0\" encoding=\"utf-8\"?><base><background>false</background></base>";
convert_and_validate!(
XmlStruct {
background: false,
},
content
);
let content =
"<?xml version=\"1.0\" encoding=\"utf-8\"?><base><background>false</background></base>";
convert_and_validate!(XmlStruct { background: false }, content);
}
#[test]