diff --git a/src/writer.rs b/src/writer.rs index 74a70317..7dec0ccf 100644 --- a/src/writer.rs +++ b/src/writer.rs @@ -647,558 +647,3 @@ impl Indentation { } } } - -#[cfg(test)] -mod indentation { - use super::*; - use crate::events::*; - use pretty_assertions::assert_eq; - - #[test] - fn self_closed() { - let mut buffer = Vec::new(); - let mut writer = Writer::new_with_indent(&mut buffer, b' ', 4); - - let tag = BytesStart::new("self-closed") - .with_attributes(vec![("attr1", "value1"), ("attr2", "value2")].into_iter()); - writer - .write_event(Event::Empty(tag)) - .expect("write tag failed"); - - assert_eq!( - std::str::from_utf8(&buffer).unwrap(), - r#""# - ); - } - - #[test] - fn empty_paired() { - let mut buffer = Vec::new(); - let mut writer = Writer::new_with_indent(&mut buffer, b' ', 4); - - let start = BytesStart::new("paired") - .with_attributes(vec![("attr1", "value1"), ("attr2", "value2")].into_iter()); - let end = start.to_end(); - writer - .write_event(Event::Start(start.clone())) - .expect("write start tag failed"); - writer - .write_event(Event::End(end)) - .expect("write end tag failed"); - - assert_eq!( - std::str::from_utf8(&buffer).unwrap(), - r#" -"# - ); - } - - #[test] - fn paired_with_inner() { - let mut buffer = Vec::new(); - let mut writer = Writer::new_with_indent(&mut buffer, b' ', 4); - - let start = BytesStart::new("paired") - .with_attributes(vec![("attr1", "value1"), ("attr2", "value2")].into_iter()); - let end = start.to_end(); - let inner = BytesStart::new("inner"); - - writer - .write_event(Event::Start(start.clone())) - .expect("write start tag failed"); - writer - .write_event(Event::Empty(inner)) - .expect("write inner tag failed"); - writer - .write_event(Event::End(end)) - .expect("write end tag failed"); - - assert_eq!( - std::str::from_utf8(&buffer).unwrap(), - r#" - -"# - ); - } - - #[test] - fn paired_with_text() { - let mut buffer = Vec::new(); - let mut writer = Writer::new_with_indent(&mut buffer, b' ', 4); - - let start = BytesStart::new("paired") - .with_attributes(vec![("attr1", "value1"), ("attr2", "value2")].into_iter()); - let end = start.to_end(); - let text = BytesText::new("text"); - - writer - .write_event(Event::Start(start.clone())) - .expect("write start tag failed"); - writer - .write_event(Event::Text(text)) - .expect("write text failed"); - writer - .write_event(Event::End(end)) - .expect("write end tag failed"); - - assert_eq!( - std::str::from_utf8(&buffer).unwrap(), - r#"text"# - ); - } - - #[test] - fn mixed_content() { - let mut buffer = Vec::new(); - let mut writer = Writer::new_with_indent(&mut buffer, b' ', 4); - - let start = BytesStart::new("paired") - .with_attributes(vec![("attr1", "value1"), ("attr2", "value2")].into_iter()); - let end = start.to_end(); - let text = BytesText::new("text"); - let inner = BytesStart::new("inner"); - - writer - .write_event(Event::Start(start.clone())) - .expect("write start tag failed"); - writer - .write_event(Event::Text(text)) - .expect("write text failed"); - writer - .write_event(Event::Empty(inner)) - .expect("write inner tag failed"); - writer - .write_event(Event::End(end)) - .expect("write end tag failed"); - - assert_eq!( - std::str::from_utf8(&buffer).unwrap(), - r#"text -"# - ); - } - - #[test] - fn nested() { - let mut buffer = Vec::new(); - let mut writer = Writer::new_with_indent(&mut buffer, b' ', 4); - - let start = BytesStart::new("paired") - .with_attributes(vec![("attr1", "value1"), ("attr2", "value2")].into_iter()); - let end = start.to_end(); - let inner = BytesStart::new("inner"); - - writer - .write_event(Event::Start(start.clone())) - .expect("write start 1 tag failed"); - writer - .write_event(Event::Start(start.clone())) - .expect("write start 2 tag failed"); - writer - .write_event(Event::Empty(inner)) - .expect("write inner tag failed"); - writer - .write_event(Event::End(end.clone())) - .expect("write end tag 2 failed"); - writer - .write_event(Event::End(end)) - .expect("write end tag 1 failed"); - - assert_eq!( - std::str::from_utf8(&buffer).unwrap(), - r#" - - - -"# - ); - } - - #[cfg(feature = "serialize")] - #[test] - fn serializable() { - #[derive(Serialize)] - struct Foo { - #[serde(rename = "@attribute")] - attribute: &'static str, - - element: Bar, - list: Vec<&'static str>, - - #[serde(rename = "$text")] - text: &'static str, - - val: String, - } - - #[derive(Serialize)] - struct Bar { - baz: usize, - bat: usize, - } - - let mut buffer = Vec::new(); - let mut writer = Writer::new_with_indent(&mut buffer, b' ', 4); - - let content = Foo { - attribute: "attribute", - element: Bar { baz: 42, bat: 43 }, - list: vec!["first element", "second element"], - text: "text", - val: "foo".to_owned(), - }; - - let start = BytesStart::new("paired") - .with_attributes(vec![("attr1", "value1"), ("attr2", "value2")].into_iter()); - let end = start.to_end(); - - writer - .write_event(Event::Start(start.clone())) - .expect("write start tag failed"); - writer - .write_serializable("foo_element", &content) - .expect("write serializable inner contents failed"); - writer - .write_event(Event::End(end)) - .expect("write end tag failed"); - - assert_eq!( - std::str::from_utf8(&buffer).unwrap(), - r#" - - - 42 - 43 - - first element - second element - text - foo - -"# - ); - } - - #[test] - fn element_writer_empty() { - let mut buffer = Vec::new(); - let mut writer = Writer::new_with_indent(&mut buffer, b' ', 4); - - writer - .create_element("empty") - .with_attribute(("attr1", "value1")) - .with_attribute(("attr2", "value2")) - .write_empty() - .expect("failure"); - - assert_eq!( - std::str::from_utf8(&buffer).unwrap(), - r#""# - ); - } - - #[test] - fn element_writer_text() { - let mut buffer = Vec::new(); - let mut writer = Writer::new_with_indent(&mut buffer, b' ', 4); - - writer - .create_element("paired") - .with_attribute(("attr1", "value1")) - .with_attribute(("attr2", "value2")) - .write_text_content(BytesText::new("text")) - .expect("failure"); - - assert_eq!( - std::str::from_utf8(&buffer).unwrap(), - r#"text"# - ); - } - - #[test] - fn element_writer_nested() { - let mut buffer = Vec::new(); - let mut writer = Writer::new_with_indent(&mut buffer, b' ', 4); - - writer - .create_element("outer") - .with_attribute(("attr1", "value1")) - .with_attribute(("attr2", "value2")) - .write_inner_content::<_, Error>(|writer| { - let fruits = ["apple", "orange", "banana"]; - for (quant, item) in fruits.iter().enumerate() { - writer - .create_element("fruit") - .with_attribute(("quantity", quant.to_string().as_str())) - .write_text_content(BytesText::new(item))?; - } - writer - .create_element("inner") - .write_inner_content(|writer| { - writer.create_element("empty").write_empty().map(|_| ()) - })?; - - Ok(()) - }) - .expect("failure"); - - assert_eq!( - std::str::from_utf8(&buffer).unwrap(), - r#" - apple - orange - banana - - - -"# - ); - } - - mod in_attributes { - use super::*; - use pretty_assertions::assert_eq; - - #[test] - fn newline_first() { - let mut buffer = Vec::new(); - let mut writer = Writer::new_with_indent(&mut buffer, b'_', 1); - - writer - .create_element("element") - .new_line() - .with_attribute(("first", "1")) - .with_attribute(("second", "2")) - .new_line() - .with_attribute(("third", "3")) - .with_attribute(("fourth", "4")) - .write_empty() - .expect("write tag failed"); - - assert_eq!( - std::str::from_utf8(&buffer).unwrap(), - "" - ); - } - - #[test] - fn newline_inside() { - let mut buffer = Vec::new(); - let mut writer = Writer::new_with_indent(&mut buffer, b'_', 1); - - writer - .create_element("element") - .with_attribute(("first", "1")) - .with_attribute(("second", "2")) - .new_line() - .with_attribute(("third", "3")) - .with_attribute(("fourth", "4")) - .write_empty() - .expect("write tag failed"); - - assert_eq!( - std::str::from_utf8(&buffer).unwrap(), - "" - ); - } - - #[test] - fn newline_last() { - let mut buffer = Vec::new(); - let mut writer = Writer::new_with_indent(&mut buffer, b'_', 1); - - writer - .create_element("element") - .new_line() - .with_attribute(("first", "1")) - .with_attribute(("second", "2")) - .new_line() - .with_attribute(("third", "3")) - .with_attribute(("fourth", "4")) - .new_line() - .write_empty() - .expect("write tag failed"); - - writer - .create_element("element") - .with_attribute(("first", "1")) - .with_attribute(("second", "2")) - .new_line() - .with_attribute(("third", "3")) - .with_attribute(("fourth", "4")) - .new_line() - .write_empty() - .expect("write tag failed"); - - assert_eq!( - std::str::from_utf8(&buffer).unwrap(), - "\ - \n" - ); - } - - #[test] - fn newline_twice() { - let mut buffer = Vec::new(); - let mut writer = Writer::new_with_indent(&mut buffer, b'_', 1); - - writer - .create_element("element") - .new_line() - .new_line() - .write_empty() - .expect("write tag failed"); - - writer - .create_element("element") - .with_attribute(("first", "1")) - .new_line() - .new_line() - .with_attribute(("second", "2")) - .write_empty() - .expect("write tag failed"); - - assert_eq!( - std::str::from_utf8(&buffer).unwrap(), - r#" -"# - ); - } - - #[test] - fn without_indent() { - let mut buffer = Vec::new(); - let mut writer = Writer::new(&mut buffer); - - writer - .create_element("element") - .new_line() - .new_line() - .write_empty() - .expect("write tag failed"); - - writer - .create_element("element") - .with_attribute(("first", "1")) - .new_line() - .new_line() - .with_attribute(("second", "2")) - .write_empty() - .expect("write tag failed"); - - assert_eq!( - std::str::from_utf8(&buffer).unwrap(), - r#""# - ); - } - - #[test] - fn long_element_name() { - let mut buffer = Vec::new(); - let mut writer = Writer::new_with_indent(&mut buffer, b't', 1); - - writer - .create_element(String::from("x").repeat(128).as_str()) - .with_attribute(("first", "1")) - .new_line() - .with_attribute(("second", "2")) - .write_empty() - .expect("Problem with indentation reference"); - } - } - - mod in_attributes_multi { - use super::*; - use pretty_assertions::assert_eq; - - #[test] - fn newline_first() { - let mut buffer = Vec::new(); - let mut writer = Writer::new_with_indent(&mut buffer, b'_', 1); - - writer - .create_element("element") - .new_line() - .with_attributes([("first", "1"), ("second", "2")]) - .new_line() - .with_attributes([("third", "3"), ("fourth", "4")]) - .write_empty() - .expect("write tag failed"); - - assert_eq!( - std::str::from_utf8(&buffer).unwrap(), - "" - ); - } - - #[test] - fn newline_inside() { - let mut buffer = Vec::new(); - let mut writer = Writer::new_with_indent(&mut buffer, b'_', 1); - - writer - .create_element("element") - .with_attributes([("first", "1"), ("second", "2")]) - .new_line() - .with_attributes([("third", "3"), ("fourth", "4")]) - .write_empty() - .expect("write tag failed"); - - assert_eq!( - std::str::from_utf8(&buffer).unwrap(), - r#""# - ); - } - - #[test] - fn newline_last() { - let mut buffer = Vec::new(); - let mut writer = Writer::new_with_indent(&mut buffer, b'_', 1); - - writer - .create_element("element") - .new_line() - .with_attributes([("first", "1"), ("second", "2")]) - .new_line() - .with_attributes([("third", "3"), ("fourth", "4")]) - .new_line() - .write_empty() - .expect("write tag failed"); - - writer - .create_element("element") - .with_attributes([("first", "1"), ("second", "2")]) - .new_line() - .with_attributes([("third", "3"), ("fourth", "4")]) - .new_line() - .write_empty() - .expect("write tag failed"); - - assert_eq!( - std::str::from_utf8(&buffer).unwrap(), - "\ - \n" - ); - } - } -} diff --git a/tests/writer-indentation.rs b/tests/writer-indentation.rs new file mode 100644 index 00000000..b53d207a --- /dev/null +++ b/tests/writer-indentation.rs @@ -0,0 +1,554 @@ +use quick_xml::errors::Error; +use quick_xml::events::{BytesStart, BytesText, Event}; +use quick_xml::writer::Writer; +use pretty_assertions::assert_eq; + +#[test] +fn self_closed() { + let mut buffer = Vec::new(); + let mut writer = Writer::new_with_indent(&mut buffer, b' ', 4); + + let tag = BytesStart::new("self-closed") + .with_attributes(vec![("attr1", "value1"), ("attr2", "value2")].into_iter()); + writer + .write_event(Event::Empty(tag)) + .expect("write tag failed"); + + assert_eq!( + std::str::from_utf8(&buffer).unwrap(), + r#""# + ); +} + +#[test] +fn empty_paired() { + let mut buffer = Vec::new(); + let mut writer = Writer::new_with_indent(&mut buffer, b' ', 4); + + let start = BytesStart::new("paired") + .with_attributes(vec![("attr1", "value1"), ("attr2", "value2")].into_iter()); + let end = start.to_end(); + writer + .write_event(Event::Start(start.clone())) + .expect("write start tag failed"); + writer + .write_event(Event::End(end)) + .expect("write end tag failed"); + + assert_eq!( + std::str::from_utf8(&buffer).unwrap(), + r#" +"# + ); +} + +#[test] +fn paired_with_inner() { + let mut buffer = Vec::new(); + let mut writer = Writer::new_with_indent(&mut buffer, b' ', 4); + + let start = BytesStart::new("paired") + .with_attributes(vec![("attr1", "value1"), ("attr2", "value2")].into_iter()); + let end = start.to_end(); + let inner = BytesStart::new("inner"); + + writer + .write_event(Event::Start(start.clone())) + .expect("write start tag failed"); + writer + .write_event(Event::Empty(inner)) + .expect("write inner tag failed"); + writer + .write_event(Event::End(end)) + .expect("write end tag failed"); + + assert_eq!( + std::str::from_utf8(&buffer).unwrap(), + r#" + +"# + ); +} + +#[test] +fn paired_with_text() { + let mut buffer = Vec::new(); + let mut writer = Writer::new_with_indent(&mut buffer, b' ', 4); + + let start = BytesStart::new("paired") + .with_attributes(vec![("attr1", "value1"), ("attr2", "value2")].into_iter()); + let end = start.to_end(); + let text = BytesText::new("text"); + + writer + .write_event(Event::Start(start.clone())) + .expect("write start tag failed"); + writer + .write_event(Event::Text(text)) + .expect("write text failed"); + writer + .write_event(Event::End(end)) + .expect("write end tag failed"); + + assert_eq!( + std::str::from_utf8(&buffer).unwrap(), + r#"text"# + ); +} + +#[test] +fn mixed_content() { + let mut buffer = Vec::new(); + let mut writer = Writer::new_with_indent(&mut buffer, b' ', 4); + + let start = BytesStart::new("paired") + .with_attributes(vec![("attr1", "value1"), ("attr2", "value2")].into_iter()); + let end = start.to_end(); + let text = BytesText::new("text"); + let inner = BytesStart::new("inner"); + + writer + .write_event(Event::Start(start.clone())) + .expect("write start tag failed"); + writer + .write_event(Event::Text(text)) + .expect("write text failed"); + writer + .write_event(Event::Empty(inner)) + .expect("write inner tag failed"); + writer + .write_event(Event::End(end)) + .expect("write end tag failed"); + + assert_eq!( + std::str::from_utf8(&buffer).unwrap(), + r#"text +"# + ); +} + +#[test] +fn nested() { + let mut buffer = Vec::new(); + let mut writer = Writer::new_with_indent(&mut buffer, b' ', 4); + + let start = BytesStart::new("paired") + .with_attributes(vec![("attr1", "value1"), ("attr2", "value2")].into_iter()); + let end = start.to_end(); + let inner = BytesStart::new("inner"); + + writer + .write_event(Event::Start(start.clone())) + .expect("write start 1 tag failed"); + writer + .write_event(Event::Start(start.clone())) + .expect("write start 2 tag failed"); + writer + .write_event(Event::Empty(inner)) + .expect("write inner tag failed"); + writer + .write_event(Event::End(end.clone())) + .expect("write end tag 2 failed"); + writer + .write_event(Event::End(end)) + .expect("write end tag 1 failed"); + + assert_eq!( + std::str::from_utf8(&buffer).unwrap(), + r#" + + + +"# + ); +} + +#[cfg(feature = "serialize")] +#[test] +fn serializable() { + use serde::Serialize; + + #[derive(Serialize)] + struct Foo { + #[serde(rename = "@attribute")] + attribute: &'static str, + + element: Bar, + list: Vec<&'static str>, + + #[serde(rename = "$text")] + text: &'static str, + + val: String, + } + + #[derive(Serialize)] + struct Bar { + baz: usize, + bat: usize, + } + + let mut buffer = Vec::new(); + let mut writer = Writer::new_with_indent(&mut buffer, b' ', 4); + + let content = Foo { + attribute: "attribute", + element: Bar { baz: 42, bat: 43 }, + list: vec!["first element", "second element"], + text: "text", + val: "foo".to_owned(), + }; + + let start = BytesStart::new("paired") + .with_attributes(vec![("attr1", "value1"), ("attr2", "value2")].into_iter()); + let end = start.to_end(); + + writer + .write_event(Event::Start(start.clone())) + .expect("write start tag failed"); + writer + .write_serializable("foo_element", &content) + .expect("write serializable inner contents failed"); + writer + .write_event(Event::End(end)) + .expect("write end tag failed"); + + assert_eq!( + std::str::from_utf8(&buffer).unwrap(), + r#" + + + 42 + 43 + + first element + second element + text + foo + +"# + ); +} + +#[test] +fn element_writer_empty() { + let mut buffer = Vec::new(); + let mut writer = Writer::new_with_indent(&mut buffer, b' ', 4); + + writer + .create_element("empty") + .with_attribute(("attr1", "value1")) + .with_attribute(("attr2", "value2")) + .write_empty() + .expect("failure"); + + assert_eq!( + std::str::from_utf8(&buffer).unwrap(), + r#""# + ); +} + +#[test] +fn element_writer_text() { + let mut buffer = Vec::new(); + let mut writer = Writer::new_with_indent(&mut buffer, b' ', 4); + + writer + .create_element("paired") + .with_attribute(("attr1", "value1")) + .with_attribute(("attr2", "value2")) + .write_text_content(BytesText::new("text")) + .expect("failure"); + + assert_eq!( + std::str::from_utf8(&buffer).unwrap(), + r#"text"# + ); +} + +#[test] +fn element_writer_nested() { + let mut buffer = Vec::new(); + let mut writer = Writer::new_with_indent(&mut buffer, b' ', 4); + + writer + .create_element("outer") + .with_attribute(("attr1", "value1")) + .with_attribute(("attr2", "value2")) + .write_inner_content::<_, Error>(|writer| { + let fruits = ["apple", "orange", "banana"]; + for (quant, item) in fruits.iter().enumerate() { + writer + .create_element("fruit") + .with_attribute(("quantity", quant.to_string().as_str())) + .write_text_content(BytesText::new(item))?; + } + writer + .create_element("inner") + .write_inner_content(|writer| { + writer.create_element("empty").write_empty().map(|_| ()) + })?; + + Ok(()) + }) + .expect("failure"); + + assert_eq!( + std::str::from_utf8(&buffer).unwrap(), + r#" + apple + orange + banana + + + +"# + ); +} + +mod in_attributes { + use super::*; + use pretty_assertions::assert_eq; + + #[test] + fn newline_first() { + let mut buffer = Vec::new(); + let mut writer = Writer::new_with_indent(&mut buffer, b'_', 1); + + writer + .create_element("element") + .new_line() + .with_attribute(("first", "1")) + .with_attribute(("second", "2")) + .new_line() + .with_attribute(("third", "3")) + .with_attribute(("fourth", "4")) + .write_empty() + .expect("write tag failed"); + + assert_eq!( + std::str::from_utf8(&buffer).unwrap(), + "" + ); + } + + #[test] + fn newline_inside() { + let mut buffer = Vec::new(); + let mut writer = Writer::new_with_indent(&mut buffer, b'_', 1); + + writer + .create_element("element") + .with_attribute(("first", "1")) + .with_attribute(("second", "2")) + .new_line() + .with_attribute(("third", "3")) + .with_attribute(("fourth", "4")) + .write_empty() + .expect("write tag failed"); + + assert_eq!( + std::str::from_utf8(&buffer).unwrap(), + "" + ); + } + + #[test] + fn newline_last() { + let mut buffer = Vec::new(); + let mut writer = Writer::new_with_indent(&mut buffer, b'_', 1); + + writer + .create_element("element") + .new_line() + .with_attribute(("first", "1")) + .with_attribute(("second", "2")) + .new_line() + .with_attribute(("third", "3")) + .with_attribute(("fourth", "4")) + .new_line() + .write_empty() + .expect("write tag failed"); + + writer + .create_element("element") + .with_attribute(("first", "1")) + .with_attribute(("second", "2")) + .new_line() + .with_attribute(("third", "3")) + .with_attribute(("fourth", "4")) + .new_line() + .write_empty() + .expect("write tag failed"); + + assert_eq!( + std::str::from_utf8(&buffer).unwrap(), + "\ + \n" + ); + } + + #[test] + fn newline_twice() { + let mut buffer = Vec::new(); + let mut writer = Writer::new_with_indent(&mut buffer, b'_', 1); + + writer + .create_element("element") + .new_line() + .new_line() + .write_empty() + .expect("write tag failed"); + + writer + .create_element("element") + .with_attribute(("first", "1")) + .new_line() + .new_line() + .with_attribute(("second", "2")) + .write_empty() + .expect("write tag failed"); + + assert_eq!( + std::str::from_utf8(&buffer).unwrap(), + r#" +"# + ); + } + + #[test] + fn without_indent() { + let mut buffer = Vec::new(); + let mut writer = Writer::new(&mut buffer); + + writer + .create_element("element") + .new_line() + .new_line() + .write_empty() + .expect("write tag failed"); + + writer + .create_element("element") + .with_attribute(("first", "1")) + .new_line() + .new_line() + .with_attribute(("second", "2")) + .write_empty() + .expect("write tag failed"); + + assert_eq!( + std::str::from_utf8(&buffer).unwrap(), + r#""# + ); + } + + #[test] + fn long_element_name() { + let mut buffer = Vec::new(); + let mut writer = Writer::new_with_indent(&mut buffer, b't', 1); + + writer + .create_element(String::from("x").repeat(128).as_str()) + .with_attribute(("first", "1")) + .new_line() + .with_attribute(("second", "2")) + .write_empty() + .expect("Problem with indentation reference"); + } +} + +mod in_attributes_multi { + use super::*; + use pretty_assertions::assert_eq; + + #[test] + fn newline_first() { + let mut buffer = Vec::new(); + let mut writer = Writer::new_with_indent(&mut buffer, b'_', 1); + + writer + .create_element("element") + .new_line() + .with_attributes([("first", "1"), ("second", "2")]) + .new_line() + .with_attributes([("third", "3"), ("fourth", "4")]) + .write_empty() + .expect("write tag failed"); + + assert_eq!( + std::str::from_utf8(&buffer).unwrap(), + "" + ); + } + + #[test] + fn newline_inside() { + let mut buffer = Vec::new(); + let mut writer = Writer::new_with_indent(&mut buffer, b'_', 1); + + writer + .create_element("element") + .with_attributes([("first", "1"), ("second", "2")]) + .new_line() + .with_attributes([("third", "3"), ("fourth", "4")]) + .write_empty() + .expect("write tag failed"); + + assert_eq!( + std::str::from_utf8(&buffer).unwrap(), + r#""# + ); + } + + #[test] + fn newline_last() { + let mut buffer = Vec::new(); + let mut writer = Writer::new_with_indent(&mut buffer, b'_', 1); + + writer + .create_element("element") + .new_line() + .with_attributes([("first", "1"), ("second", "2")]) + .new_line() + .with_attributes([("third", "3"), ("fourth", "4")]) + .new_line() + .write_empty() + .expect("write tag failed"); + + writer + .create_element("element") + .with_attributes([("first", "1"), ("second", "2")]) + .new_line() + .with_attributes([("third", "3"), ("fourth", "4")]) + .new_line() + .write_empty() + .expect("write tag failed"); + + assert_eq!( + std::str::from_utf8(&buffer).unwrap(), + "\ + \n" + ); + } +}