Reuse type in struct_variant_containing_unit_variant

This commit is contained in:
Mingun 2023-08-07 22:55:35 +05:00
parent 41b9c33c2b
commit 7c0e6bd18f

View File

@ -42,6 +42,7 @@ enum InternallyTagged {
NewtypeStruct(Struct),
NewtypeEnum(Enum),
Struct { a: u8 },
StructEnum { enum_: Enum },
}
#[test]
@ -184,7 +185,8 @@ fn wrong_tag() {
`NewtypeMap`, \
`NewtypeStruct`, \
`NewtypeEnum`, \
`Struct`",
`Struct`, \
`StructEnum`",
);
}
@ -460,12 +462,6 @@ mod string_and_bytes {
#[test]
fn struct_variant_containing_unit_variant() {
#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(tag = "tag")]
enum Message {
Log { level: Enum },
}
assert_de_tokens(
&Enum::Unit,
&[
@ -475,18 +471,18 @@ fn struct_variant_containing_unit_variant() {
],
);
let value = Message::Log { level: Enum::Unit };
let value = InternallyTagged::StructEnum { enum_: Enum::Unit };
assert_de_tokens(
&value,
&[
Token::Struct {
name: "Message",
name: "InternallyTagged",
len: 2,
},
Token::Str("tag"),
Token::Str("Log"),
Token::Str("level"),
Token::Str("StructEnum"),
Token::Str("enum_"),
Token::Enum { name: "Enum" },
Token::BorrowedStr("Unit"),
Token::Unit,
@ -499,8 +495,8 @@ fn struct_variant_containing_unit_variant() {
&[
Token::Map { len: Some(2) },
Token::Str("tag"),
Token::Str("Log"),
Token::Str("level"),
Token::Str("StructEnum"),
Token::Str("enum_"),
Token::Enum { name: "Enum" },
Token::BorrowedStr("Unit"),
Token::Unit,
@ -512,8 +508,8 @@ fn struct_variant_containing_unit_variant() {
&value,
&[
Token::Seq { len: Some(2) },
Token::Str("Log"),
Token::Enum { name: "Enum" },
Token::Str("StructEnum"), // tag
Token::Enum { name: "Enum" }, // enum_
Token::BorrowedStr("Unit"),
Token::Unit,
Token::SeqEnd,