Reuse type in newtype_variant_containing_unit_struct
This commit is contained in:
parent
48de0c51b0
commit
d3492d8d36
@ -28,6 +28,7 @@ struct Struct {
|
||||
enum InternallyTagged {
|
||||
Unit,
|
||||
NewtypeUnit(()),
|
||||
NewtypeUnitStruct(Unit),
|
||||
NewtypeNewtype(Newtype),
|
||||
NewtypeMap(BTreeMap<String, String>),
|
||||
NewtypeStruct(Struct),
|
||||
@ -169,6 +170,7 @@ fn wrong_tag() {
|
||||
"unknown variant `Z`, expected one of \
|
||||
`Unit`, \
|
||||
`NewtypeUnit`, \
|
||||
`NewtypeUnitStruct`, \
|
||||
`NewtypeNewtype`, \
|
||||
`NewtypeMap`, \
|
||||
`NewtypeStruct`, \
|
||||
@ -638,40 +640,36 @@ fn newtype_variant_containing_externally_tagged_enum() {
|
||||
|
||||
#[test]
|
||||
fn newtype_variant_containing_unit_struct() {
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(tag = "tag")]
|
||||
enum Message {
|
||||
Info(Unit),
|
||||
}
|
||||
let value = InternallyTagged::NewtypeUnitStruct(Unit);
|
||||
|
||||
assert_tokens(
|
||||
&Message::Info(Unit),
|
||||
&value,
|
||||
&[
|
||||
Token::Map { len: Some(1) },
|
||||
Token::Str("tag"),
|
||||
Token::Str("Info"),
|
||||
Token::Str("NewtypeUnitStruct"),
|
||||
Token::MapEnd,
|
||||
],
|
||||
);
|
||||
|
||||
assert_de_tokens(
|
||||
&Message::Info(Unit),
|
||||
&value,
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "Message",
|
||||
name: "InternallyTagged",
|
||||
len: 1,
|
||||
},
|
||||
Token::Str("tag"),
|
||||
Token::Str("Info"),
|
||||
Token::Str("NewtypeUnitStruct"),
|
||||
Token::StructEnd,
|
||||
],
|
||||
);
|
||||
|
||||
assert_de_tokens(
|
||||
&Message::Info(Unit),
|
||||
&value,
|
||||
&[
|
||||
Token::Seq { len: Some(1) },
|
||||
Token::Str("Info"),
|
||||
Token::Str("NewtypeUnitStruct"), // tag
|
||||
Token::SeqEnd,
|
||||
],
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user