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)] #[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(tag = "type")] #[serde(tag = "type")]
enum InternallyTagged { enum InternallyTagged {
Struct { a: u8 },
Unit, Unit,
NewtypeMap(BTreeMap<String, String>),
NewtypeNewtype(Newtype), NewtypeNewtype(Newtype),
NewtypeMap(BTreeMap<String, String>),
NewtypeStruct(Struct), NewtypeStruct(Struct),
} Struct { a: u8 },
#[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] #[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] #[test]
fn newtype_map() { fn newtype_map() {
assert_tokens( 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] #[test]
fn newtype_struct() { fn newtype_struct() {
assert_tokens( 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] #[test]
fn wrong_tag() { fn wrong_tag() {
assert_de_tokens_error::<InternallyTagged>( assert_de_tokens_error::<InternallyTagged>(
@ -832,7 +832,7 @@ mod internally_tagged_enum {
Token::Str("Z"), Token::Str("Z"),
Token::MapEnd, Token::MapEnd,
], ],
"unknown variant `Z`, expected one of `Struct`, `Unit`, `NewtypeMap`, `NewtypeNewtype`, `NewtypeStruct`", "unknown variant `Z`, expected one of `Unit`, `NewtypeNewtype`, `NewtypeMap`, `NewtypeStruct`, `Struct`",
); );
} }