format code

This commit is contained in:
Marc-Antoine Arnaud
2018-11-05 17:17:27 +01:00
parent 96bac71db5
commit 69a54eebcf
20 changed files with 113 additions and 91 deletions

View File

@@ -1,6 +1,6 @@
use std::io::Read;
use xml::reader::{EventReader, ParserConfig, XmlEvent};
use xml::name::OwnedName;
use xml::reader::{EventReader, ParserConfig, XmlEvent};
use YaDeserialize;
pub fn from_str<T: YaDeserialize>(s: &str) -> Result<T, String> {

View File

@@ -74,7 +74,7 @@ pub trait Visitor<'de>: Sized {
}
macro_rules! serialize_type {
($type: ty) => {
($type:ty) => {
impl YaSerialize for $type {
fn serialize<W: Write>(&self, writer: &mut ser::Serializer<W>) -> Result<(), String> {
let content = format!("{}", self);
@@ -112,7 +112,7 @@ fn default_visitor() {
}
macro_rules! test_type {
($visitor: tt, $message: expr) => {{
($visitor:tt, $message:expr) => {{
let t = Test {};
assert_eq!(t.$visitor(""), Err($message.to_string()));
}};

View File

@@ -1,8 +1,8 @@
use std::str;
use std::io::{Cursor, Write};
use xml::{EmitterConfig, EventWriter};
use std::str;
use xml;
use xml::writer::XmlEvent;
use xml::{EmitterConfig, EventWriter};
use YaSerialize;
pub fn to_string<T: YaSerialize>(model: &T) -> Result<String, String> {

View File

@@ -6,8 +6,8 @@ extern crate yaserde;
extern crate yaserde_derive;
use std::io::Read;
use yaserde::YaDeserialize;
use yaserde::de::from_str;
use yaserde::YaDeserialize;
macro_rules! convert_and_validate {
($content: expr, $struct: tt, $model: expr) => {
@@ -19,7 +19,11 @@ macro_rules! convert_and_validate {
#[test]
fn de_struct_namespace() {
#[derive(YaDeserialize, PartialEq, Debug)]
#[yaserde(root = "book", prefix = "ns", namespace = "ns: http://www.sample.com/ns/domain")]
#[yaserde(
root = "book",
prefix = "ns",
namespace = "ns: http://www.sample.com/ns/domain"
)]
pub struct Book {
#[yaserde(prefix = "ns")]
author: String,
@@ -45,7 +49,11 @@ fn de_struct_namespace() {
#[test]
fn de_enum_namespace() {
#[derive(YaDeserialize, PartialEq, Debug)]
#[yaserde(root = "root", prefix = "ns", namespace = "ns: http://www.sample.com/ns/domain")]
#[yaserde(
root = "root",
prefix = "ns",
namespace = "ns: http://www.sample.com/ns/domain"
)]
pub enum XmlStruct {
#[yaserde(prefix = "ns")]
Item,

View File

@@ -6,8 +6,8 @@ extern crate yaserde;
extern crate yaserde_derive;
use std::io::Read;
use yaserde::YaDeserialize;
use yaserde::de::from_str;
use yaserde::YaDeserialize;
macro_rules! convert_and_validate {
($type: ty, $value: expr, $content: expr) => {{
@@ -20,7 +20,8 @@ macro_rules! convert_and_validate {
let model = Data { item: $value };
let source = if let Some(content) = $content {
String::from("<?xml version=\"1.0\" encoding=\"utf-8\"?><data><item>") + content
String::from("<?xml version=\"1.0\" encoding=\"utf-8\"?><data><item>")
+ content
+ "</item></data>"
} else {
String::from("<?xml version=\"1.0\" encoding=\"utf-8\"?><data />")
@@ -43,7 +44,8 @@ macro_rules! convert_and_validate_for_attribute {
let model = Data { item: $value };
let source = if let Some(content) = $content {
String::from("<?xml version=\"1.0\" encoding=\"utf-8\"?><data item=\"") + content
String::from("<?xml version=\"1.0\" encoding=\"utf-8\"?><data item=\"")
+ content
+ "\"></data>"
} else {
String::from("<?xml version=\"1.0\" encoding=\"utf-8\"?><data />")

View File

@@ -6,11 +6,11 @@ extern crate yaserde;
extern crate yaserde_derive;
use std::io::Read;
use yaserde::YaDeserialize;
use yaserde::de::from_str;
use yaserde::YaDeserialize;
macro_rules! convert_and_validate {
($type: ty, $value: expr, $content: expr) => {{
($type:ty, $value:expr, $content:expr) => {{
#[derive(YaDeserialize, PartialEq, Debug)]
#[yaserde(root = "data")]
pub struct Data {
@@ -19,7 +19,8 @@ macro_rules! convert_and_validate {
let model = Data { item: $value };
let content = String::from("<?xml version=\"1.0\" encoding=\"utf-8\"?><data><item>") + $content
let content = String::from("<?xml version=\"1.0\" encoding=\"utf-8\"?><data><item>")
+ $content
+ "</item></data>";
let loaded: Result<Data, String> = from_str(&content);
@@ -28,7 +29,7 @@ macro_rules! convert_and_validate {
}
macro_rules! convert_and_validate_for_attribute {
($type: ty, $value: expr, $content: expr) => {{
($type:ty, $value:expr, $content:expr) => {{
#[derive(YaDeserialize, PartialEq, Debug)]
#[yaserde(root = "data")]
pub struct Data {

View File

@@ -6,8 +6,8 @@ extern crate yaserde;
extern crate yaserde_derive;
use std::io::Read;
use yaserde::YaDeserialize;
use yaserde::de::from_str;
use yaserde::YaDeserialize;
macro_rules! convert_and_validate {
($content: expr, $struct: tt, $model: expr) => {

View File

@@ -6,8 +6,8 @@ extern crate yaserde;
extern crate yaserde_derive;
use std::io::Read;
use yaserde::YaDeserialize;
use yaserde::de::from_str;
use yaserde::YaDeserialize;
#[test]
fn de_no_content() {

View File

@@ -6,11 +6,11 @@ extern crate yaserde;
extern crate yaserde_derive;
use std::io::Write;
use yaserde::YaSerialize;
use yaserde::ser::to_string;
use yaserde::YaSerialize;
macro_rules! convert_and_validate {
($model: expr, $content: expr) => {
($model:expr, $content:expr) => {
let data: Result<String, String> = to_string(&$model);
assert_eq!(data, Ok(String::from($content)));
};
@@ -19,7 +19,11 @@ macro_rules! convert_and_validate {
#[test]
fn ser_struct_namespace() {
#[derive(YaSerialize, PartialEq, Debug)]
#[yaserde(root = "root", prefix = "ns", namespace = "ns: http://www.sample.com/ns/domain")]
#[yaserde(
root = "root",
prefix = "ns",
namespace = "ns: http://www.sample.com/ns/domain"
)]
pub struct XmlStruct {
#[yaserde(prefix = "ns")]
item: String,
@@ -36,7 +40,11 @@ fn ser_struct_namespace() {
#[test]
fn ser_enum_namespace() {
#[derive(YaSerialize, PartialEq, Debug)]
#[yaserde(root = "root", prefix = "ns", namespace = "ns: http://www.sample.com/ns/domain")]
#[yaserde(
root = "root",
prefix = "ns",
namespace = "ns: http://www.sample.com/ns/domain"
)]
pub enum XmlStruct {
#[yaserde(prefix = "ns")]
Item,
@@ -51,8 +59,11 @@ fn ser_enum_namespace() {
#[test]
fn ser_struct_multi_namespace() {
#[derive(YaSerialize, PartialEq, Debug)]
#[yaserde(root = "root", namespace = "ns1: http://www.sample.com/ns/domain1",
namespace = "ns2: http://www.sample.com/ns/domain2")]
#[yaserde(
root = "root",
namespace = "ns1: http://www.sample.com/ns/domain1",
namespace = "ns2: http://www.sample.com/ns/domain2"
)]
pub struct XmlStruct {
#[yaserde(prefix = "ns1")]
item_1: String,
@@ -72,8 +83,11 @@ fn ser_struct_multi_namespace() {
#[test]
fn ser_enum_multi_namespace() {
#[derive(YaSerialize, PartialEq, Debug)]
#[yaserde(root = "root", namespace = "ns1: http://www.sample.com/ns/domain1",
namespace = "ns2: http://www.sample.com/ns/domain2")]
#[yaserde(
root = "root",
namespace = "ns1: http://www.sample.com/ns/domain1",
namespace = "ns2: http://www.sample.com/ns/domain2"
)]
pub enum XmlStruct {
#[yaserde(prefix = "ns1")]
Item1,
@@ -92,8 +106,11 @@ fn ser_enum_multi_namespace() {
#[test]
fn ser_struct_attribute_namespace() {
#[derive(YaSerialize, PartialEq, Debug)]
#[yaserde(root = "root", namespace = "ns1: http://www.sample.com/ns/domain1",
namespace = "ns2: http://www.sample.com/ns/domain2")]
#[yaserde(
root = "root",
namespace = "ns1: http://www.sample.com/ns/domain1",
namespace = "ns2: http://www.sample.com/ns/domain2"
)]
pub struct XmlStruct {
#[yaserde(prefix = "ns1")]
item_1: String,
@@ -113,8 +130,11 @@ fn ser_struct_attribute_namespace() {
#[test]
fn ser_struct_default_namespace() {
#[derive(YaSerialize, PartialEq, Debug)]
#[yaserde(root = "tt", namespace = "http://www.w3.org/ns/ttml",
namespace = "ttm: http://www.w3.org/ns/ttml#metadata")]
#[yaserde(
root = "tt",
namespace = "http://www.w3.org/ns/ttml",
namespace = "ttm: http://www.w3.org/ns/ttml#metadata"
)]
pub struct XmlStruct {
item: String,
}

View File

@@ -6,8 +6,8 @@ extern crate yaserde;
extern crate yaserde_derive;
use std::io::Write;
use yaserde::YaSerialize;
use yaserde::ser::to_string;
use yaserde::YaSerialize;
macro_rules! convert_and_validate {
($type: ty, $value: expr, $content: expr) => {{

View File

@@ -6,8 +6,8 @@ extern crate yaserde;
extern crate yaserde_derive;
use std::io::Write;
use yaserde::YaSerialize;
use yaserde::ser::to_string;
use yaserde::YaSerialize;
macro_rules! convert_and_validate {
($type: ty, $value: expr, $content: expr) => {{
@@ -20,11 +20,12 @@ macro_rules! convert_and_validate {
let data: Result<String, String> = to_string(&model);
let content = if $content == "" {
String::from("<?xml version=\"1.0\" encoding=\"utf-8\"?><data />")
} else {
String::from("<?xml version=\"1.0\" encoding=\"utf-8\"?><data><item>") + $content
String::from("<?xml version=\"1.0\" encoding=\"utf-8\"?><data />")
} else {
String::from("<?xml version=\"1.0\" encoding=\"utf-8\"?><data><item>")
+ $content
+ "</item></data>"
};
};
assert_eq!(data, Ok(content));
}};
}

View File

@@ -6,8 +6,8 @@ extern crate yaserde;
extern crate yaserde_derive;
use std::io::Write;
use yaserde::YaSerialize;
use yaserde::ser::to_string;
use yaserde::YaSerialize;
macro_rules! convert_and_validate {
($model: expr, $content: expr) => {