From be2267974cc4fc3338c67721794617cc427ba8b7 Mon Sep 17 00:00:00 2001 From: Hendrik Sollich Date: Sun, 8 Sep 2024 22:02:07 +0200 Subject: [PATCH] test: add another escaping test --- src/properties.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/properties.rs b/src/properties.rs index 11dab6a..b502c35 100644 --- a/src/properties.rs +++ b/src/properties.rs @@ -447,6 +447,21 @@ mod tests { assert_eq!(expected, Property::escape_text(line)); } + #[test] + fn escape_special_characters_in_serialized_property() { + let line = "\n\\;,:"; + let expected = r"\N\\\;\,:"; + + let prop = Property::new("DESCRIPTION", line) + .append_parameter(("VALUE", "TEXT")) + .done(); + let expected = format!("DESCRIPTION;VALUE=TEXT:{expected}\r\n"); + + let mut buf = String::new(); + prop.fmt_write(&mut buf).unwrap(); + assert_eq!(expected, buf); + } + #[cfg(feature = "parser")] #[test] fn preserve_spaces() { @@ -462,4 +477,13 @@ mod tests { assert_eq!(line, unfolded); } } + + #[test] + fn serialize_property() { + let prop = Property::new("SUMMARY", "This is a summary"); + let expected = "SUMMARY:This is a summary\r\n"; + let mut buf = String::new(); + prop.fmt_write(&mut buf).unwrap(); + assert_eq!(expected, buf); + } }