Add test for #[derive_serialize] for structs

This commit is contained in:
Erick Tryzelaar 2015-03-03 21:42:33 -08:00
parent 4db8b732f1
commit 189b3f0394

View File

@ -281,12 +281,21 @@ impl<'a> Visitor for AssertSerializer<'a> {
} }
} }
//////////////////////////////////////////////////////////////////////////
#[derive_serialize] #[derive_serialize]
struct NamedUnit; struct NamedUnit;
#[derive_serialize] #[derive_serialize]
struct NamedSeq(i32, i32, i32); struct NamedSeq(i32, i32, i32);
#[derive_serialize]
struct NamedMap {
a: i32,
b: i32,
c: i32,
}
#[derive_serialize] #[derive_serialize]
enum Enum { enum Enum {
Unit, Unit,
@ -294,6 +303,8 @@ enum Enum {
Map { a: i32, b: i32 }, Map { a: i32, b: i32 },
} }
//////////////////////////////////////////////////////////////////////////
macro_rules! btreemap { macro_rules! btreemap {
() => { () => {
BTreeMap::new() BTreeMap::new()
@ -490,6 +501,23 @@ declare_tests! {
Token::SeqEnd, Token::SeqEnd,
], ],
} }
test_named_map {
NamedMap { a: 1, b: 2, c: 3 } => vec![
Token::NamedMapStart("NamedMap", 3),
Token::MapSep(true),
Token::Str("a"),
Token::I32(1),
Token::MapSep(false),
Token::Str("b"),
Token::I32(2),
Token::MapSep(false),
Token::Str("c"),
Token::I32(3),
Token::MapEnd,
],
}
test_enum { test_enum {
Enum::Unit => vec![Token::EnumUnit("Enum", "Unit")], Enum::Unit => vec![Token::EnumUnit("Enum", "Unit")],
Enum::Seq(1, 2) => vec![ Enum::Seq(1, 2) => vec![