Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ serde = { version = "1.0", features = ["derive"] }
simple_logger = "2.1"
docmatic = "0.1"
rstest = "0.12"
indoc = "2.0.6"
2 changes: 1 addition & 1 deletion src/ser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
where
W: Write,
{
fn new_from_writer(writer: EventWriter<W>) -> Self {
pub fn new_from_writer(writer: EventWriter<W>) -> Self {
Self {
writer,
root: true,
Expand Down Expand Up @@ -269,7 +269,7 @@
Ok(())
}

fn serialize_some<T: ?Sized>(self, value: &T) -> Result<Self::Ok>

Check warning on line 272 in src/ser/mod.rs

View workflow job for this annotation

GitHub Actions / Clippy Output

bound is defined in more than one place

warning: bound is defined in more than one place --> src/ser/mod.rs:272:23 | 272 | fn serialize_some<T: ?Sized>(self, value: &T) -> Result<Self::Ok> | ^ 273 | where 274 | T: Serialize, | ^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations
where
T: Serialize,
{
Expand Down Expand Up @@ -304,7 +304,7 @@
Ok(())
}

fn serialize_newtype_struct<T: ?Sized>(self, name: &'static str, value: &T) -> Result<Self::Ok>

Check warning on line 307 in src/ser/mod.rs

View workflow job for this annotation

GitHub Actions / Clippy Output

bound is defined in more than one place

warning: bound is defined in more than one place --> src/ser/mod.rs:307:33 | 307 | fn serialize_newtype_struct<T: ?Sized>(self, name: &'static str, value: &T) -> Result<Self::Ok> | ^ 308 | where 309 | T: Serialize, | ^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations
where
T: Serialize,
{
Expand All @@ -312,7 +312,7 @@
value.serialize(self)
}

fn serialize_newtype_variant<T: ?Sized>(

Check warning on line 315 in src/ser/mod.rs

View workflow job for this annotation

GitHub Actions / Clippy Output

bound is defined in more than one place

warning: bound is defined in more than one place --> src/ser/mod.rs:315:34 | 315 | fn serialize_newtype_variant<T: ?Sized>( | ^ ... 323 | T: Serialize, | ^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations
self,
name: &'static str,
_variant_index: u32,
Expand Down
58 changes: 58 additions & 0 deletions tests/api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
pub use rstest::{fixture, rstest};
use simple_logger::SimpleLogger;

#[fixture]
fn logger() {
let _ = SimpleLogger::new().init();
}

mod given_custom_event_writer {
use super::*;
use indoc::indoc;
use serde::Serialize;
use xml::EmitterConfig;

#[derive(Debug, Serialize)]
struct Document {
content: Content,
}

#[derive(Debug, Serialize)]
struct Content {
text: String,
}

#[fixture]
fn document() -> Document {
Document {
content: Content {
text: "content text".into(),
},
}
}

#[rstest]
fn should_accept_custom_event_writer(_logger: (), document: Document) {
let mut output = Vec::new();
let writer = EmitterConfig::new()
.perform_indent(true)
.create_writer(&mut output);
let mut s = serde_xml_rs::ser::Serializer::new_from_writer(writer);

document.serialize(&mut s).unwrap();
let actual = String::from_utf8(output).unwrap();

assert_eq!(
actual,
indoc!(
r#"
<?xml version="1.0" encoding="UTF-8"?>
<Document>
<content>
<text>content text</text>
</content>
</Document>"#
)
);
}
}
Loading