Add additional checks for unit and newtype_unit tests

- check that unit variant can be deserialized from a map
- check that newtype variant with unit can be deserialized from a struct
This commit is contained in:
Mingun 2023-08-08 01:56:51 +05:00
parent 71ed1f2f12
commit 2adb0e99b0

View File

@ -73,6 +73,25 @@ fn unit() {
],
);
assert_de_tokens(
&InternallyTagged::Unit,
&[
Token::Map { len: Some(1) },
Token::Str("tag"),
Token::Str("Unit"),
Token::MapEnd,
],
);
assert_de_tokens(
&InternallyTagged::Unit,
&[
Token::Map { len: Some(1) },
Token::BorrowedStr("tag"),
Token::BorrowedStr("Unit"),
Token::MapEnd,
],
);
assert_de_tokens(
&InternallyTagged::Unit,
&[
@ -113,6 +132,31 @@ fn newtype_unit() {
Token::MapEnd,
],
);
assert_de_tokens(
&value,
&[
Token::Struct {
name: "InternallyTagged",
len: 1,
},
Token::Str("tag"),
Token::Str("NewtypeUnit"),
Token::StructEnd,
],
);
assert_de_tokens(
&value,
&[
Token::Struct {
name: "InternallyTagged",
len: 1,
},
Token::BorrowedStr("tag"),
Token::BorrowedStr("NewtypeUnit"),
Token::StructEnd,
],
);
}
#[test]