Skip to content

Commit

Permalink
Change expectations about indentation - never indent text productions
Browse files Browse the repository at this point in the history
That means, never indent "$text" fields and do not indent "$value" fields that
produces string without surrounding tags

failures (208):
    se::content::tests::with_indent::enum_with_text_field::char_amp
    se::content::tests::with_indent::enum_with_text_field::char_apos
    se::content::tests::with_indent::enum_with_text_field::char_gt
    se::content::tests::with_indent::enum_with_text_field::char_lt
    se::content::tests::with_indent::enum_with_text_field::char_non_escaped
    se::content::tests::with_indent::enum_with_text_field::char_quot
    se::content::tests::with_indent::enum_with_text_field::char_space
    se::content::tests::with_indent::enum_with_text_field::enum_unit
    se::content::tests::with_indent::enum_with_text_field::enum_unit_escaped
    se::content::tests::with_indent::enum_with_text_field::f32_
    se::content::tests::with_indent::enum_with_text_field::f64_
    se::content::tests::with_indent::enum_with_text_field::false_
    se::content::tests::with_indent::enum_with_text_field::i128_
    se::content::tests::with_indent::enum_with_text_field::i16_
    se::content::tests::with_indent::enum_with_text_field::i32_
    se::content::tests::with_indent::enum_with_text_field::i64_
    se::content::tests::with_indent::enum_with_text_field::i8_
    se::content::tests::with_indent::enum_with_text_field::isize_
    se::content::tests::with_indent::enum_with_text_field::newtype
    se::content::tests::with_indent::enum_with_text_field::option_none
    se::content::tests::with_indent::enum_with_text_field::option_some
    se::content::tests::with_indent::enum_with_text_field::option_some_empty_str
    se::content::tests::with_indent::enum_with_text_field::seq
    se::content::tests::with_indent::enum_with_text_field::seq_empty
    se::content::tests::with_indent::enum_with_text_field::str_escaped
    se::content::tests::with_indent::enum_with_text_field::str_non_escaped
    se::content::tests::with_indent::enum_with_text_field::true_
    se::content::tests::with_indent::enum_with_text_field::tuple
    se::content::tests::with_indent::enum_with_text_field::tuple_struct
    se::content::tests::with_indent::enum_with_text_field::u128_
    se::content::tests::with_indent::enum_with_text_field::u16_
    se::content::tests::with_indent::enum_with_text_field::u32_
    se::content::tests::with_indent::enum_with_text_field::u64_
    se::content::tests::with_indent::enum_with_text_field::u8_
    se::content::tests::with_indent::enum_with_text_field::unit
    se::content::tests::with_indent::enum_with_text_field::unit_struct
    se::content::tests::with_indent::enum_with_text_field::unit_struct_escaped
    se::content::tests::with_indent::enum_with_text_field::usize_
    se::content::tests::with_indent::enum_with_value_field::char_amp
    se::content::tests::with_indent::enum_with_value_field::char_apos
    se::content::tests::with_indent::enum_with_value_field::char_gt
    se::content::tests::with_indent::enum_with_value_field::char_lt
    se::content::tests::with_indent::enum_with_value_field::char_non_escaped
    se::content::tests::with_indent::enum_with_value_field::char_quot
    se::content::tests::with_indent::enum_with_value_field::char_space
    se::content::tests::with_indent::enum_with_value_field::f32_
    se::content::tests::with_indent::enum_with_value_field::f64_
    se::content::tests::with_indent::enum_with_value_field::false_
    se::content::tests::with_indent::enum_with_value_field::i128_
    se::content::tests::with_indent::enum_with_value_field::i16_
    se::content::tests::with_indent::enum_with_value_field::i32_
    se::content::tests::with_indent::enum_with_value_field::i64_
    se::content::tests::with_indent::enum_with_value_field::i8_
    se::content::tests::with_indent::enum_with_value_field::isize_
    se::content::tests::with_indent::enum_with_value_field::newtype
    se::content::tests::with_indent::enum_with_value_field::option_none
    se::content::tests::with_indent::enum_with_value_field::option_some
    se::content::tests::with_indent::enum_with_value_field::option_some_empty_str
    se::content::tests::with_indent::enum_with_value_field::seq
    se::content::tests::with_indent::enum_with_value_field::seq_empty
    se::content::tests::with_indent::enum_with_value_field::str_escaped
    se::content::tests::with_indent::enum_with_value_field::str_non_escaped
    se::content::tests::with_indent::enum_with_value_field::true_
    se::content::tests::with_indent::enum_with_value_field::tuple
    se::content::tests::with_indent::enum_with_value_field::tuple_struct
    se::content::tests::with_indent::enum_with_value_field::u128_
    se::content::tests::with_indent::enum_with_value_field::u16_
    se::content::tests::with_indent::enum_with_value_field::u32_
    se::content::tests::with_indent::enum_with_value_field::u64_
    se::content::tests::with_indent::enum_with_value_field::u8_
    se::content::tests::with_indent::enum_with_value_field::usize_
    se::content::tests::with_indent::seq
    se::content::tests::with_indent::text_field::enum_struct
    se::content::tests::with_indent::tuple
    se::content::tests::with_indent::tuple_struct
    se::element::tests::with_indent::text_field::map::char_amp
    se::element::tests::with_indent::text_field::map::char_apos
    se::element::tests::with_indent::text_field::map::char_gt
    se::element::tests::with_indent::text_field::map::char_lt
    se::element::tests::with_indent::text_field::map::char_non_escaped
    se::element::tests::with_indent::text_field::map::char_quot
    se::element::tests::with_indent::text_field::map::char_space
    se::element::tests::with_indent::text_field::map::enum_unit
    se::element::tests::with_indent::text_field::map::enum_unit_escaped
    se::element::tests::with_indent::text_field::map::f32_
    se::element::tests::with_indent::text_field::map::f64_
    se::element::tests::with_indent::text_field::map::false_
    se::element::tests::with_indent::text_field::map::i128_
    se::element::tests::with_indent::text_field::map::i16_
    se::element::tests::with_indent::text_field::map::i32_
    se::element::tests::with_indent::text_field::map::i64_
    se::element::tests::with_indent::text_field::map::i8_
    se::element::tests::with_indent::text_field::map::isize_
    se::element::tests::with_indent::text_field::map::newtype
    se::element::tests::with_indent::text_field::map::option_some
    se::element::tests::with_indent::text_field::map::seq
    se::element::tests::with_indent::text_field::map::str_escaped
    se::element::tests::with_indent::text_field::map::str_non_escaped
    se::element::tests::with_indent::text_field::map::true_
    se::element::tests::with_indent::text_field::map::tuple
    se::element::tests::with_indent::text_field::map::tuple_struct
    se::element::tests::with_indent::text_field::map::u128_
    se::element::tests::with_indent::text_field::map::u16_
    se::element::tests::with_indent::text_field::map::u32_
    se::element::tests::with_indent::text_field::map::u64_
    se::element::tests::with_indent::text_field::map::u8_
    se::element::tests::with_indent::text_field::map::usize_
    se::element::tests::with_indent::text_field::struct_::char_amp
    se::element::tests::with_indent::text_field::struct_::char_apos
    se::element::tests::with_indent::text_field::struct_::char_gt
    se::element::tests::with_indent::text_field::struct_::char_lt
    se::element::tests::with_indent::text_field::struct_::char_non_escaped
    se::element::tests::with_indent::text_field::struct_::char_quot
    se::element::tests::with_indent::text_field::struct_::char_space
    se::element::tests::with_indent::text_field::struct_::enum_unit
    se::element::tests::with_indent::text_field::struct_::enum_unit_escaped
    se::element::tests::with_indent::text_field::struct_::f32_
    se::element::tests::with_indent::text_field::struct_::f64_
    se::element::tests::with_indent::text_field::struct_::false_
    se::element::tests::with_indent::text_field::struct_::i128_
    se::element::tests::with_indent::text_field::struct_::i16_
    se::element::tests::with_indent::text_field::struct_::i32_
    se::element::tests::with_indent::text_field::struct_::i64_
    se::element::tests::with_indent::text_field::struct_::i8_
    se::element::tests::with_indent::text_field::struct_::isize_
    se::element::tests::with_indent::text_field::struct_::newtype
    se::element::tests::with_indent::text_field::struct_::option_none
    se::element::tests::with_indent::text_field::struct_::option_some
    se::element::tests::with_indent::text_field::struct_::option_some_empty_str
    se::element::tests::with_indent::text_field::struct_::seq
    se::element::tests::with_indent::text_field::struct_::seq_empty
    se::element::tests::with_indent::text_field::struct_::str_escaped
    se::element::tests::with_indent::text_field::struct_::str_non_escaped
    se::element::tests::with_indent::text_field::struct_::true_
    se::element::tests::with_indent::text_field::struct_::tuple
    se::element::tests::with_indent::text_field::struct_::tuple_struct
    se::element::tests::with_indent::text_field::struct_::u128_
    se::element::tests::with_indent::text_field::struct_::u16_
    se::element::tests::with_indent::text_field::struct_::u32_
    se::element::tests::with_indent::text_field::struct_::u64_
    se::element::tests::with_indent::text_field::struct_::u8_
    se::element::tests::with_indent::text_field::struct_::unit
    se::element::tests::with_indent::text_field::struct_::unit_struct
    se::element::tests::with_indent::text_field::struct_::unit_struct_escaped
    se::element::tests::with_indent::text_field::struct_::usize_
    se::element::tests::with_indent::value_field::map::char_amp
    se::element::tests::with_indent::value_field::map::char_apos
    se::element::tests::with_indent::value_field::map::char_gt
    se::element::tests::with_indent::value_field::map::char_lt
    se::element::tests::with_indent::value_field::map::char_non_escaped
    se::element::tests::with_indent::value_field::map::char_quot
    se::element::tests::with_indent::value_field::map::char_space
    se::element::tests::with_indent::value_field::map::f32_
    se::element::tests::with_indent::value_field::map::f64_
    se::element::tests::with_indent::value_field::map::false_
    se::element::tests::with_indent::value_field::map::i128_
    se::element::tests::with_indent::value_field::map::i16_
    se::element::tests::with_indent::value_field::map::i32_
    se::element::tests::with_indent::value_field::map::i64_
    se::element::tests::with_indent::value_field::map::i8_
    se::element::tests::with_indent::value_field::map::isize_
    se::element::tests::with_indent::value_field::map::newtype
    se::element::tests::with_indent::value_field::map::option_some
    se::element::tests::with_indent::value_field::map::seq
    se::element::tests::with_indent::value_field::map::str_escaped
    se::element::tests::with_indent::value_field::map::str_non_escaped
    se::element::tests::with_indent::value_field::map::true_
    se::element::tests::with_indent::value_field::map::tuple
    se::element::tests::with_indent::value_field::map::tuple_struct
    se::element::tests::with_indent::value_field::map::u128_
    se::element::tests::with_indent::value_field::map::u16_
    se::element::tests::with_indent::value_field::map::u32_
    se::element::tests::with_indent::value_field::map::u64_
    se::element::tests::with_indent::value_field::map::u8_
    se::element::tests::with_indent::value_field::map::usize_
    se::element::tests::with_indent::value_field::struct_::char_amp
    se::element::tests::with_indent::value_field::struct_::char_apos
    se::element::tests::with_indent::value_field::struct_::char_gt
    se::element::tests::with_indent::value_field::struct_::char_lt
    se::element::tests::with_indent::value_field::struct_::char_non_escaped
    se::element::tests::with_indent::value_field::struct_::char_quot
    se::element::tests::with_indent::value_field::struct_::char_space
    se::element::tests::with_indent::value_field::struct_::f32_
    se::element::tests::with_indent::value_field::struct_::f64_
    se::element::tests::with_indent::value_field::struct_::false_
    se::element::tests::with_indent::value_field::struct_::i128_
    se::element::tests::with_indent::value_field::struct_::i16_
    se::element::tests::with_indent::value_field::struct_::i32_
    se::element::tests::with_indent::value_field::struct_::i64_
    se::element::tests::with_indent::value_field::struct_::i8_
    se::element::tests::with_indent::value_field::struct_::isize_
    se::element::tests::with_indent::value_field::struct_::newtype
    se::element::tests::with_indent::value_field::struct_::option_none
    se::element::tests::with_indent::value_field::struct_::option_some
    se::element::tests::with_indent::value_field::struct_::option_some_empty_str
    se::element::tests::with_indent::value_field::struct_::seq
    se::element::tests::with_indent::value_field::struct_::seq_empty
    se::element::tests::with_indent::value_field::struct_::str_escaped
    se::element::tests::with_indent::value_field::struct_::str_non_escaped
    se::element::tests::with_indent::value_field::struct_::true_
    se::element::tests::with_indent::value_field::struct_::tuple
    se::element::tests::with_indent::value_field::struct_::tuple_struct
    se::element::tests::with_indent::value_field::struct_::u128_
    se::element::tests::with_indent::value_field::struct_::u16_
    se::element::tests::with_indent::value_field::struct_::u32_
    se::element::tests::with_indent::value_field::struct_::u64_
    se::element::tests::with_indent::value_field::struct_::u8_
    se::element::tests::with_indent::value_field::struct_::usize_
  • Loading branch information
RedIODev authored and Mingun committed Oct 13, 2024
1 parent 4934d7b commit 65b9003
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 174 deletions.
109 changes: 34 additions & 75 deletions src/se/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand All @@ -1119,19 +1111,14 @@ pub(super) mod tests {
serialize_as!(newtype: Newtype(42) => "42", Text);
serialize_as!(enum_newtype: Enum::Newtype(42) => "<Newtype>42</Newtype>");

// 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::<usize>::new() => "", SensitiveNothing);
serialize_as!(tuple: ("<\"&'>", "with\t\r\n spaces", 3usize)
=> "&lt;&quot;&amp;&apos;&gt;\n\
with\t\r\n spaces\n\
=> "&lt;&quot;&amp;&apos;&gt;\
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)
=> "<Tuple>first</Tuple>\n\
<Tuple>42</Tuple>");
Expand Down Expand Up @@ -1170,9 +1157,7 @@ pub(super) mod tests {
after: "answer",
}
=> "<Text>\n \
<before>answer</before>\n \
42 42\n \
<after>answer</after>\n\
<before>answer</before>42 42<after>answer</after>\n\
</Text>");
}

Expand All @@ -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",
}
=> "<Text>\n \
<before>answer</before>\n \
<after>answer</after>\n\
</Text>");
};
($name:ident: $data:expr => $expected:literal) => {
serialize_as!($name:
SpecialEnum::Text {
Expand All @@ -1202,9 +1175,9 @@ pub(super) mod tests {
after: "answer",
}
=> concat!(
"<Text>\n <before>answer</before>\n ",
"<Text>\n <before>answer</before>",
$expected,
"\n <after>answer</after>\n</Text>",
"<after>answer</after>\n</Text>",
));
};
}
Expand Down Expand Up @@ -1238,8 +1211,6 @@ pub(super) mod tests {
text!(char_amp: '&' => "&amp;");
text!(char_apos: '\'' => "&apos;");
text!(char_quot: '"' => "&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");
Expand All @@ -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 => "&lt;&quot;&amp;&apos;&gt;");
Expand All @@ -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::<usize>::new());
text!(seq_empty: Vec::<usize>::new() => "");
text!(tuple: ("<\"&'>", "with\t\n\r spaces", 3usize)
=> "&lt;&quot;&amp;&apos;&gt; \
with&#9;&#10;&#13;&#32;spaces \
Expand Down Expand Up @@ -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",
}
=> "<Value>\n \
<before>answer</before>\n \
<after>answer</after>\n\
</Value>");
};
($name:ident: $data:expr => $expected:literal) => {
serialize_as!($name:
SpecialEnum::Value {
Expand All @@ -1341,9 +1300,9 @@ pub(super) mod tests {
after: "answer",
}
=> concat!(
"<Value>\n <before>answer</before>\n ",
"<Value>\n <before>answer</before>",
$expected,
"\n <after>answer</after>\n</Value>",
"<after>answer</after>\n</Value>",
));
};
}
Expand Down Expand Up @@ -1377,8 +1336,6 @@ pub(super) mod tests {
value!(char_amp: '&' => "&amp;");
value!(char_apos: '\'' => "&apos;");
value!(char_quot: '"' => "&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");
Expand All @@ -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 => "<Unit/>");
value!(enum_unit: Enum::Unit => "\n <Unit/>\n ");
err!(enum_unit_escaped:
SpecialEnum::Value {
before: "answer",
Expand All @@ -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) => "<Newtype>42</Newtype>");
value!(enum_newtype: Enum::Newtype(42) => "\n <Newtype>42</Newtype>\n ");

// Note that sequences of primitives serialized without delimiters!
value!(seq: vec![1, 2, 3] => "1\n 2\n 3");
value!(seq_empty: Vec::<usize>::new());
value!(seq: vec![1, 2, 3] => "123");
value!(seq_empty: Vec::<usize>::new() => "");
value!(tuple: ("<\"&'>", "with\t\n\r spaces", 3usize)
=> "&lt;&quot;&amp;&apos;&gt;\n \
with\t\n\r spaces\n \
=> "&lt;&quot;&amp;&apos;&gt;\
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)
=> "<Tuple>first</Tuple>\n \
<Tuple>42</Tuple>");
=> "\n \
<Tuple>first</Tuple>\n \
<Tuple>42</Tuple>\n ");

// We cannot wrap map or struct in any container and should not
// flatten it, so it is impossible to serialize maps and structs
Expand All @@ -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) }
=> "<Struct>\n \
=> "\n \
<Struct>\n \
<key>answer</key>\n \
<val>42</val>\n \
<val>42</val>\n \
</Struct>");
</Struct>\n ");
}

mod attributes {
Expand Down
Loading

0 comments on commit 65b9003

Please sign in to comment.