Reorder enum variants and tests to canonical order (Unit, Newtype, Tuple, Struct)

This commit is contained in:
Mingun 2023-04-22 20:54:00 +05:00 committed by Mingun
parent da0ed4021d
commit 8c60f5aea7

View File

@ -693,39 +693,11 @@ mod internally_tagged_enum {
#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(tag = "type")]
enum InternallyTagged {
Struct { a: u8 },
Unit,
NewtypeMap(BTreeMap<String, String>),
NewtypeNewtype(Newtype),
NewtypeMap(BTreeMap<String, String>),
NewtypeStruct(Struct),
}
#[test]
fn struct_() {
assert_tokens(
&InternallyTagged::Struct { a: 1 },
&[
Token::Struct {
name: "InternallyTagged",
len: 2,
},
Token::Str("type"),
Token::Str("Struct"),
Token::Str("a"),
Token::U8(1),
Token::StructEnd,
],
);
assert_de_tokens(
&InternallyTagged::Struct { a: 1 },
&[
Token::Seq { len: Some(2) },
Token::Str("Struct"),
Token::U8(1),
Token::SeqEnd,
],
);
Struct { a: u8 },
}
#[test]
@ -753,6 +725,19 @@ mod internally_tagged_enum {
);
}
#[test]
fn newtype_newtype() {
assert_tokens(
&InternallyTagged::NewtypeNewtype(Newtype(BTreeMap::new())),
&[
Token::Map { len: Some(1) },
Token::Str("type"),
Token::Str("NewtypeNewtype"),
Token::MapEnd,
],
);
}
#[test]
fn newtype_map() {
assert_tokens(
@ -777,19 +762,6 @@ mod internally_tagged_enum {
);
}
#[test]
fn newtype_newtype() {
assert_tokens(
&InternallyTagged::NewtypeNewtype(Newtype(BTreeMap::new())),
&[
Token::Map { len: Some(1) },
Token::Str("type"),
Token::Str("NewtypeNewtype"),
Token::MapEnd,
],
);
}
#[test]
fn newtype_struct() {
assert_tokens(
@ -818,6 +790,34 @@ mod internally_tagged_enum {
);
}
#[test]
fn struct_() {
assert_tokens(
&InternallyTagged::Struct { a: 1 },
&[
Token::Struct {
name: "InternallyTagged",
len: 2,
},
Token::Str("type"),
Token::Str("Struct"),
Token::Str("a"),
Token::U8(1),
Token::StructEnd,
],
);
assert_de_tokens(
&InternallyTagged::Struct { a: 1 },
&[
Token::Seq { len: Some(2) },
Token::Str("Struct"),
Token::U8(1),
Token::SeqEnd,
],
);
}
#[test]
fn wrong_tag() {
assert_de_tokens_error::<InternallyTagged>(
@ -832,7 +832,7 @@ mod internally_tagged_enum {
Token::Str("Z"),
Token::MapEnd,
],
"unknown variant `Z`, expected one of `Struct`, `Unit`, `NewtypeMap`, `NewtypeNewtype`, `NewtypeStruct`",
"unknown variant `Z`, expected one of `Unit`, `NewtypeNewtype`, `NewtypeMap`, `NewtypeStruct`, `Struct`",
);
}