Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
Add test of serialize_key/serialize_value map
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Aug 2, 2022
1 parent f7b55f1 commit 3dceb15
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/test_serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
)]

use indoc::indoc;
use serde::ser::SerializeMap;
use serde_derive::{Deserialize, Serialize};
use serde_yaml::{Mapping, Number, Value};
use std::collections::BTreeMap;
Expand Down Expand Up @@ -198,6 +199,29 @@ fn test_map() {
test_serde(&thing, yaml);
}

#[test]
fn test_map_key_value() {
struct Map;

impl serde::Serialize for Map {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
// Test maps which do not serialize using serialize_entry.
let mut map = serializer.serialize_map(Some(1))?;
map.serialize_key("k")?;
map.serialize_value("v")?;
map.end()
}
}

let yaml = indoc! {"
k: v
"};
assert_eq!(yaml, serde_yaml::to_string(&Map).unwrap());
}

#[test]
fn test_basic_struct() {
#[derive(Serialize, Deserialize, PartialEq, Debug)]
Expand Down

0 comments on commit 3dceb15

Please sign in to comment.