diff --git a/src/se/content.rs b/src/se/content.rs
index 30c7414f..e814f5b9 100644
--- a/src/se/content.rs
+++ b/src/se/content.rs
@@ -651,8 +651,6 @@ pub(super) mod tests {
serialize_as!(char_amp: '&' => "&", SensitiveText);
serialize_as!(char_apos: '\'' => "'", SensitiveText);
serialize_as!(char_quot: '"' => """, SensitiveText);
- //TODO: add a setting to escape leading/trailing spaces, in order to
- // pretty-print does not change the content
serialize_as!(char_space: ' ' => " ", SensitiveText);
serialize_as!(str_non_escaped: "non-escaped string" => "non-escaped string", SensitiveText);
@@ -781,8 +779,6 @@ pub(super) mod tests {
text!(char_amp: '&' => "&");
text!(char_apos: '\'' => "'");
text!(char_quot: '"' => """);
- //TODO: add a setting to escape leading/trailing spaces, in order to
- // pretty-print does not change the content
text!(char_space: ' ' => " ");
text!(str_non_escaped: "non-escaped string" => "non-escaped string");
@@ -908,8 +904,6 @@ pub(super) mod tests {
value!(char_amp: '&' => "&");
value!(char_apos: '\'' => "'");
value!(char_quot: '"' => """);
- //TODO: add a setting to escape leading/trailing spaces, in order to
- // pretty-print does not change the content
value!(char_space: ' ' => " ");
value!(str_non_escaped: "non-escaped string" => "non-escaped string");
@@ -1094,8 +1088,6 @@ pub(super) mod tests {
serialize_as!(char_amp: '&' => "&", SensitiveText);
serialize_as!(char_apos: '\'' => "'", SensitiveText);
serialize_as!(char_quot: '"' => """, SensitiveText);
- //TODO: add a setting to escape leading/trailing spaces, in order to
- // pretty-print does not change the content
serialize_as!(char_space: ' ' => " ", SensitiveText);
serialize_as!(str_non_escaped: "non-escaped string" => "non-escaped string", SensitiveText);
@@ -1119,19 +1111,14 @@ pub(super) mod tests {
serialize_as!(newtype: Newtype(42) => "42", Text);
serialize_as!(enum_newtype: Enum::Newtype(42) => "42");
- // Note that sequences of primitives serialized without delimiters other that indent!
- serialize_as!(seq: vec![1, 2, 3]
- => "1\n\
- 2\n\
- 3", Text);
+ // Note that sequences of primitives serialized without delimiters!
+ serialize_as!(seq: vec![1, 2, 3] => "123", Text);
serialize_as!(seq_empty: Vec::::new() => "", SensitiveNothing);
serialize_as!(tuple: ("<\"&'>", "with\t\r\n spaces", 3usize)
- => "<"&'>\n\
- with\t\r\n spaces\n\
+ => "<"&'>\
+ with\t\r\n spaces\
3", Text);
- serialize_as!(tuple_struct: Tuple("first", 42)
- => "first\n\
- 42", Text);
+ serialize_as!(tuple_struct: Tuple("first", 42) => "first42", Text);
serialize_as!(enum_tuple: Enum::Tuple("first", 42)
=> "first\n\
42");
@@ -1170,9 +1157,7 @@ pub(super) mod tests {
after: "answer",
}
=> "\n \
- answer\n \
- 42 42\n \
- answer\n\
+ answer42 42answer\n\
");
}
@@ -1182,18 +1167,6 @@ pub(super) mod tests {
use pretty_assertions::assert_eq;
macro_rules! text {
- ($name:ident: $data:expr) => {
- serialize_as!($name:
- SpecialEnum::Text {
- before: "answer",
- content: $data,
- after: "answer",
- }
- => "\n \
- answer\n \
- answer\n\
- ");
- };
($name:ident: $data:expr => $expected:literal) => {
serialize_as!($name:
SpecialEnum::Text {
@@ -1202,9 +1175,9 @@ pub(super) mod tests {
after: "answer",
}
=> concat!(
- "\n answer\n ",
+ "\n answer",
$expected,
- "\n answer\n",
+ "answer\n",
));
};
}
@@ -1238,8 +1211,6 @@ pub(super) mod tests {
text!(char_amp: '&' => "&");
text!(char_apos: '\'' => "'");
text!(char_quot: '"' => """);
- //TODO: add a setting to escape leading/trailing spaces, in order to
- // pretty-print does not change the content
text!(char_space: ' ' => " ");
text!(str_non_escaped: "non-escaped string" => "non-escaped string");
@@ -1253,13 +1224,13 @@ pub(super) mod tests {
}
=> Unsupported("`serialize_bytes` not supported yet"));
- text!(option_none: Option::<&str>::None);
+ text!(option_none: Option::<&str>::None => "");
text!(option_some: Some("non-escaped string") => "non-escaped string");
- text!(option_some_empty_str: Some(""));
+ text!(option_some_empty_str: Some("") => "");
- text!(unit: ());
- text!(unit_struct: Unit);
- text!(unit_struct_escaped: UnitEscaped);
+ text!(unit: () => "");
+ text!(unit_struct: Unit => "");
+ text!(unit_struct_escaped: UnitEscaped => "");
text!(enum_unit: Enum::Unit => "Unit");
text!(enum_unit_escaped: Enum::UnitEscaped => "<"&'>");
@@ -1276,7 +1247,7 @@ pub(super) mod tests {
// Sequences are serialized separated by spaces, all spaces inside are escaped
text!(seq: vec![1, 2, 3] => "1 2 3");
- text!(seq_empty: Vec::::new());
+ text!(seq_empty: Vec::::new() => "");
text!(tuple: ("<\"&'>", "with\t\n\r spaces", 3usize)
=> "<"&'> \
with
spaces \
@@ -1321,18 +1292,6 @@ pub(super) mod tests {
use pretty_assertions::assert_eq;
macro_rules! value {
- ($name:ident: $data:expr) => {
- serialize_as!($name:
- SpecialEnum::Value {
- before: "answer",
- content: $data,
- after: "answer",
- }
- => "\n \
- answer\n \
- answer\n\
- ");
- };
($name:ident: $data:expr => $expected:literal) => {
serialize_as!($name:
SpecialEnum::Value {
@@ -1341,9 +1300,9 @@ pub(super) mod tests {
after: "answer",
}
=> concat!(
- "\n answer\n ",
+ "\n answer",
$expected,
- "\n answer\n",
+ "answer\n",
));
};
}
@@ -1377,8 +1336,6 @@ pub(super) mod tests {
value!(char_amp: '&' => "&");
value!(char_apos: '\'' => "'");
value!(char_quot: '"' => """);
- //TODO: add a setting to escape leading/trailing spaces, in order to
- // pretty-print does not change the content
value!(char_space: ' ' => " ");
value!(str_non_escaped: "non-escaped string" => "non-escaped string");
@@ -1392,15 +1349,15 @@ pub(super) mod tests {
}
=> Unsupported("`serialize_bytes` not supported yet"));
- value!(option_none: Option::<&str>::None);
+ value!(option_none: Option::<&str>::None => "");
value!(option_some: Some("non-escaped string") => "non-escaped string");
- value!(option_some_empty_str: Some(""));
+ value!(option_some_empty_str: Some("") => "");
- value!(unit: ());
- value!(unit_struct: Unit);
- value!(unit_struct_escaped: UnitEscaped);
+ value!(unit: () => "\n ");
+ value!(unit_struct: Unit => "\n ");
+ value!(unit_struct_escaped: UnitEscaped => "\n ");
- value!(enum_unit: Enum::Unit => "");
+ value!(enum_unit: Enum::Unit => "\n \n ");
err!(enum_unit_escaped:
SpecialEnum::Value {
before: "answer",
@@ -1410,19 +1367,20 @@ pub(super) mod tests {
=> Unsupported("character `<` is not allowed at the start of an XML name `<\"&'>`"));
value!(newtype: Newtype(42) => "42");
- value!(enum_newtype: Enum::Newtype(42) => "42");
+ value!(enum_newtype: Enum::Newtype(42) => "\n 42\n ");
// Note that sequences of primitives serialized without delimiters!
- value!(seq: vec![1, 2, 3] => "1\n 2\n 3");
- value!(seq_empty: Vec::::new());
+ value!(seq: vec![1, 2, 3] => "123");
+ value!(seq_empty: Vec::::new() => "");
value!(tuple: ("<\"&'>", "with\t\n\r spaces", 3usize)
- => "<"&'>\n \
- with\t\n\r spaces\n \
+ => "<"&'>\
+ with\t\n\r spaces\
3");
- value!(tuple_struct: Tuple("first", 42) => "first\n 42");
+ value!(tuple_struct: Tuple("first", 42) => "first42");
value!(enum_tuple: Enum::Tuple("first", 42)
- => "first\n \
- 42");
+ => "\n \
+ first\n \
+ 42\n ");
// We cannot wrap map or struct in any container and should not
// flatten it, so it is impossible to serialize maps and structs
@@ -1442,11 +1400,12 @@ pub(super) mod tests {
=> Unsupported("serialization of struct `Struct` is not supported in `$value` field"));
value!(enum_struct:
Enum::Struct { key: "answer", val: (42, 42) }
- => "\n \
+ => "\n \
+ \n \
answer\n \
42\n \
42\n \
- ");
+ \n ");
}
mod attributes {
diff --git a/src/se/element.rs b/src/se/element.rs
index 48a93707..10a62389 100644
--- a/src/se/element.rs
+++ b/src/se/element.rs
@@ -800,8 +800,6 @@ mod tests {
text!(char_amp: '&' => "&");
text!(char_apos: '\'' => "'");
text!(char_quot: '"' => """);
- //TODO: add a setting to escape leading/trailing spaces, in order to
- // pretty-print does not change the content
text!(char_space: ' ' => " ");
text!(str_non_escaped: "non-escaped string" => "non-escaped string");
@@ -927,8 +925,6 @@ mod tests {
text!(char_amp: '&' => "&");
text!(char_apos: '\'' => "'");
text!(char_quot: '"' => """);
- //TODO: add a setting to escape leading/trailing spaces, in order to
- // pretty-print does not change the content
text!(char_space: ' ' => " ");
text!(str_non_escaped: "non-escaped string" => "non-escaped string");
@@ -1058,8 +1054,6 @@ mod tests {
value!(char_amp: '&' => "&");
value!(char_apos: '\'' => "'");
value!(char_quot: '"' => """);
- //TODO: add a setting to escape leading/trailing spaces, in order to
- // pretty-print does not change the content
value!(char_space: ' ' => " ");
value!(str_non_escaped: "non-escaped string" => "non-escaped string");
@@ -1164,8 +1158,6 @@ mod tests {
value!(char_amp: '&' => "&");
value!(char_apos: '\'' => "'");
value!(char_quot: '"' => """);
- //TODO: add a setting to escape leading/trailing spaces, in order to
- // pretty-print does not change the content
value!(char_space: ' ' => " ");
value!(str_non_escaped: "non-escaped string" => "non-escaped string");
@@ -1316,7 +1308,8 @@ mod tests {
use crate::writer::Indentation;
use pretty_assertions::assert_eq;
- /// Checks that given `$data` successfully serialized as `$expected`
+ /// Checks that given `$data` successfully serialized as `$expected`.
+ /// Writes `$data` using [`ElementSerializer`] with indent of two spaces.
macro_rules! serialize_as {
($name:ident: $data:expr => $expected:expr) => {
#[test]
@@ -1402,8 +1395,6 @@ mod tests {
serialize_as!(char_amp: '&' => "&");
serialize_as!(char_apos: '\'' => "'");
serialize_as!(char_quot: '"' => """);
- //TODO: add a setting to escape leading/trailing spaces, in order to
- // pretty-print does not change the content
serialize_as!(char_space: ' ' => " ");
serialize_as!(str_non_escaped: "non-escaped string" => "non-escaped string");
@@ -1468,13 +1459,15 @@ mod tests {
macro_rules! text {
($name:ident: $data:expr) => {
serialize_as!($name:
+ // Serialization started from ElementSerializer::serialize_map
BTreeMap::from([("$text", $data)])
=> "");
};
($name:ident: $data:expr => $expected:literal) => {
serialize_as!($name:
+ // Serialization started from ElementSerializer::serialize_map
BTreeMap::from([("$text", $data)])
- => concat!("\n ", $expected,"\n"));
+ => concat!("", $expected,""));
};
}
@@ -1507,8 +1500,6 @@ mod tests {
text!(char_amp: '&' => "&");
text!(char_apos: '\'' => "'");
text!(char_quot: '"' => """);
- //TODO: add a setting to escape leading/trailing spaces, in order to
- // pretty-print does not change the content
text!(char_space: ' ' => " ");
text!(str_non_escaped: "non-escaped string" => "non-escaped string");
@@ -1590,29 +1581,18 @@ mod tests {
use pretty_assertions::assert_eq;
macro_rules! text {
- ($name:ident: $data:expr) => {
- serialize_as!($name:
- Text {
- before: "answer",
- content: $data,
- after: "answer",
- }
- => "\n \
- answer\n \
- answer\n\
- ");
- };
($name:ident: $data:expr => $expected:literal) => {
serialize_as!($name:
+ // Serialization started from ElementSerializer::serialize_struct
Text {
before: "answer",
content: $data,
after: "answer",
}
=> concat!(
- "\n answer\n ",
+ "\n answer",
$expected,
- "\n answer\n",
+ "answer\n",
));
};
}
@@ -1646,8 +1626,6 @@ mod tests {
text!(char_amp: '&' => "&");
text!(char_apos: '\'' => "'");
text!(char_quot: '"' => """);
- //TODO: add a setting to escape leading/trailing spaces, in order to
- // pretty-print does not change the content
text!(char_space: ' ' => " ");
text!(str_non_escaped: "non-escaped string" => "non-escaped string");
@@ -1661,13 +1639,13 @@ mod tests {
}
=> Unsupported("`serialize_bytes` not supported yet"));
- text!(option_none: Option::<&str>::None);
+ text!(option_none: Option::<&str>::None => "");
text!(option_some: Some("non-escaped string") => "non-escaped string");
- text!(option_some_empty_str: Some(""));
+ text!(option_some_empty_str: Some("") => "");
- text!(unit: ());
- text!(unit_struct: Unit);
- text!(unit_struct_escaped: UnitEscaped);
+ text!(unit: () => "");
+ text!(unit_struct: Unit => "");
+ text!(unit_struct_escaped: UnitEscaped => "");
text!(enum_unit: Enum::Unit => "Unit");
text!(enum_unit_escaped: Enum::UnitEscaped => "<"&'>");
@@ -1684,7 +1662,7 @@ mod tests {
// Sequences are serialized separated by spaces, all spaces inside are escaped
text!(seq: vec![1, 2, 3] => "1 2 3");
- text!(seq_empty: Vec::::new());
+ text!(seq_empty: Vec::::new() => "");
text!(tuple: ("<\"&'>", "with\t\n\r spaces", 3usize)
=> "<"&'> \
with
spaces \
@@ -1738,13 +1716,15 @@ mod tests {
macro_rules! value {
($name:ident: $data:expr) => {
serialize_as!($name:
+ // Serialization started from ElementSerializer::serialize_map
BTreeMap::from([("$value", $data)])
=> "");
};
($name:ident: $data:expr => $expected:literal) => {
serialize_as!($name:
+ // Serialization started from ElementSerializer::serialize_map
BTreeMap::from([("$value", $data)])
- => concat!("\n ", $expected,"\n"));
+ => concat!("", $expected,""));
};
}
@@ -1777,8 +1757,6 @@ mod tests {
value!(char_amp: '&' => "&");
value!(char_apos: '\'' => "'");
value!(char_quot: '"' => """);
- //TODO: add a setting to escape leading/trailing spaces, in order to
- // pretty-print does not change the content
value!(char_space: ' ' => " ");
value!(str_non_escaped: "non-escaped string" => "non-escaped string");
@@ -1796,24 +1774,25 @@ mod tests {
value!(unit_struct: Unit);
value!(unit_struct_escaped: UnitEscaped);
- value!(enum_unit: Enum::Unit => "");
+ value!(enum_unit: Enum::Unit => "\n \n");
err!(enum_unit_escaped:
BTreeMap::from([("$value", Enum::UnitEscaped)])
=> Unsupported("character `<` is not allowed at the start of an XML name `<\"&'>`"));
value!(newtype: Newtype(42) => "42");
- value!(enum_newtype: Enum::Newtype(42) => "42");
+ value!(enum_newtype: Enum::Newtype(42) => "\n 42\n");
- value!(seq: vec![1, 2, 3] => "1\n 2\n 3");
+ value!(seq: vec![1, 2, 3] => "123");
value!(seq_empty: Vec::::new());
value!(tuple: ("<\"&'>", "with\t\n\r spaces", 3usize)
- => "<"&'>\n \
- with\t\n\r spaces\n \
+ => "<"&'>\
+ with\t\n\r spaces\
3");
- value!(tuple_struct: Tuple("first", 42) => "first\n 42");
+ value!(tuple_struct: Tuple("first", 42) => "first42");
value!(enum_tuple: Enum::Tuple("first", 42)
- => "first\n \
- 42");
+ => "\n \
+ first\n \
+ 42\n");
// We cannot wrap map or struct in any container and should not
// flatten it, so it is impossible to serialize maps and structs
@@ -1825,11 +1804,12 @@ mod tests {
=> Unsupported("serialization of struct `Struct` is not supported in `$value` field"));
value!(enum_struct:
Enum::Struct { key: "answer", val: (42, 42) }
- => "\n \
+ => "\n \
+ \n \
answer\n \
42\n \
42\n \
- ");
+ \n");
}
/// `$value` field inside a struct
@@ -1838,29 +1818,18 @@ mod tests {
use pretty_assertions::assert_eq;
macro_rules! value {
- ($name:ident: $data:expr) => {
- serialize_as!($name:
- Value {
- before: "answer",
- content: $data,
- after: "answer",
- }
- => "\n \
- answer\n \
- answer\n\
- ");
- };
($name:ident: $data:expr => $expected:literal) => {
serialize_as!($name:
+ // Serialization started from ElementSerializer::serialize_struct
Value {
before: "answer",
content: $data,
after: "answer",
}
=> concat!(
- "\n answer\n ",
+ "\n answer",
$expected,
- "\n answer\n",
+ "answer\n",
));
};
}
@@ -1894,8 +1863,6 @@ mod tests {
value!(char_amp: '&' => "&");
value!(char_apos: '\'' => "'");
value!(char_quot: '"' => """);
- //TODO: add a setting to escape leading/trailing spaces, in order to
- // pretty-print does not change the content
value!(char_space: ' ' => " ");
value!(str_non_escaped: "non-escaped string" => "non-escaped string");
@@ -1909,15 +1876,15 @@ mod tests {
}
=> Unsupported("`serialize_bytes` not supported yet"));
- value!(option_none: Option::<&str>::None);
+ value!(option_none: Option::<&str>::None => "");
value!(option_some: Some("non-escaped string") => "non-escaped string");
- value!(option_some_empty_str: Some(""));
+ value!(option_some_empty_str: Some("") => "");
- value!(unit: ());
- value!(unit_struct: Unit);
- value!(unit_struct_escaped: UnitEscaped);
+ value!(unit: () => "\n ");
+ value!(unit_struct: Unit => "\n ");
+ value!(unit_struct_escaped: UnitEscaped => "\n ");
- value!(enum_unit: Enum::Unit => "");
+ value!(enum_unit: Enum::Unit => "\n \n ");
err!(enum_unit_escaped:
Value {
before: "answer",
@@ -1927,19 +1894,20 @@ mod tests {
=> Unsupported("character `<` is not allowed at the start of an XML name `<\"&'>`"));
value!(newtype: Newtype(42) => "42");
- value!(enum_newtype: Enum::Newtype(42) => "42");
+ value!(enum_newtype: Enum::Newtype(42) => "\n 42\n ");
// Note that sequences of primitives serialized without delimiters!
- value!(seq: vec![1, 2, 3] => "1\n 2\n 3");
- value!(seq_empty: Vec::::new());
+ value!(seq: vec![1, 2, 3] => "123");
+ value!(seq_empty: Vec::::new() => "");
value!(tuple: ("<\"&'>", "with\t\n\r spaces", 3usize)
- => "<"&'>\n \
- with\t\n\r spaces\n \
+ => "<"&'>\
+ with\t\n\r spaces\
3");
- value!(tuple_struct: Tuple("first", 42) => "first\n 42");
+ value!(tuple_struct: Tuple("first", 42) => "first42");
value!(enum_tuple: Enum::Tuple("first", 42)
- => "first\n \
- 42");
+ => "\n \
+ first\n \
+ 42\n ");
// We cannot wrap map or struct in any container and should not
// flatten it, so it is impossible to serialize maps and structs
@@ -1959,11 +1927,12 @@ mod tests {
=> Unsupported("serialization of struct `Struct` is not supported in `$value` field"));
value!(enum_struct:
Enum::Struct { key: "answer", val: (42, 42) }
- => "\n \
+ => "\n \
+ \n \
answer\n \
42\n \
42\n \
- ");
+ \n ");
}
}
diff --git a/tests/serde-se.rs b/tests/serde-se.rs
index fc560628..ec73b4ee 100644
--- a/tests/serde-se.rs
+++ b/tests/serde-se.rs
@@ -1380,9 +1380,7 @@ mod without_root {
float: 42.0,
string: "answer"
}
- => "\n \
- 42\n \
- answer\n\
+ => "42answer\n\
");
mod enum_ {
@@ -1439,9 +1437,7 @@ mod without_root {
float: 42.0,
string: "answer"
}
- => "\n \
- 42\n \
- answer\n\
+ => "42answer\n\
");
/// Test serialization of the specially named variant `$text`
@@ -1544,9 +1540,7 @@ mod without_root {
string: "answer"
}
=> "\n \
- Text\n \
- 42\n \
- answer\n\
+ Text42answer\n\
");
}
@@ -1624,9 +1618,7 @@ mod without_root {
}
=> "\n \
Text\n \
- \n \
- 42\n \
- answer\n \
+ 42answer\n \
\n\
");
}
@@ -1676,9 +1668,7 @@ mod without_root {
float: 42.0,
string: "answer"
}
- => "\n \
- 42\n \
- answer\n\
+ => "42answer\n\
");
}
}
diff --git a/tests/writer-indentation.rs b/tests/writer-indentation.rs
index f96f6063..baabd967 100644
--- a/tests/writer-indentation.rs
+++ b/tests/writer-indentation.rs
@@ -222,9 +222,7 @@ fn serializable() {
43
first element
- second element
- text
- foo
+ second element
textfoo
"#
);