Implement tests for crate::private:🇩🇪:content::VariantDeserializer

failures (1):
    flatten::enum_::externally_tagged::tuple
This commit is contained in:
Mingun 2023-05-09 13:02:44 +05:00
parent 5b96cf1bde
commit 993966600e
2 changed files with 79 additions and 1 deletions

View File

@ -2841,11 +2841,66 @@ mod flatten {
#[derive(Debug, PartialEq, Serialize, Deserialize)] #[derive(Debug, PartialEq, Serialize, Deserialize)]
enum Enum { enum Enum {
Tuple(u32, u32),
Struct { index: u32, value: u32 }, Struct { index: u32, value: u32 },
} }
/// Reaches crate::private::de::content::VariantDeserializer::tuple_variant
/// Content::Seq case
/// via FlatMapDeserializer::deserialize_enum
#[test] #[test]
fn struct_() { fn tuple() {
assert_tokens(
&Flatten {
data: Enum::Tuple(0, 42),
extra: HashMap::from_iter([("extra_key".into(), "extra value".into())]),
},
&[
Token::Map { len: None },
Token::Str("Tuple"), // variant
Token::Seq { len: Some(2) },
Token::U32(0),
Token::U32(42),
Token::SeqEnd,
Token::Str("extra_key"),
Token::Str("extra value"),
Token::MapEnd,
],
);
}
/// Reaches crate::private::de::content::VariantDeserializer::struct_variant
/// Content::Seq case
/// via FlatMapDeserializer::deserialize_enum
#[test]
fn struct_from_seq() {
assert_de_tokens(
&Flatten {
data: Enum::Struct {
index: 0,
value: 42,
},
extra: HashMap::from_iter([("extra_key".into(), "extra value".into())]),
},
&[
Token::Map { len: None },
Token::Str("Struct"), // variant
Token::Seq { len: Some(2) },
Token::U32(0), // index
Token::U32(42), // value
Token::SeqEnd,
Token::Str("extra_key"),
Token::Str("extra value"),
Token::MapEnd,
],
);
}
/// Reaches crate::private::de::content::VariantDeserializer::struct_variant
/// Content::Map case
/// via FlatMapDeserializer::deserialize_enum
#[test]
fn struct_from_map() {
assert_tokens( assert_tokens(
&Flatten { &Flatten {
data: Enum::Struct { data: Enum::Struct {

View File

@ -1430,6 +1430,9 @@ fn test_enum_in_internally_tagged_enum() {
], ],
); );
// Reaches crate::private::de::content::VariantDeserializer::tuple_variant
// Content::Seq case
// via ContentDeserializer::deserialize_enum
assert_tokens( assert_tokens(
&Outer::Inner(Inner::Tuple(1, 1)), &Outer::Inner(Inner::Tuple(1, 1)),
&[ &[
@ -1448,6 +1451,9 @@ fn test_enum_in_internally_tagged_enum() {
], ],
); );
// Reaches crate::private::de::content::VariantDeserializer::struct_variant
// Content::Map case
// via ContentDeserializer::deserialize_enum
assert_tokens( assert_tokens(
&Outer::Inner(Inner::Struct { f: 1 }), &Outer::Inner(Inner::Struct { f: 1 }),
&[ &[
@ -1465,6 +1471,23 @@ fn test_enum_in_internally_tagged_enum() {
Token::MapEnd, Token::MapEnd,
], ],
); );
// Reaches crate::private::de::content::VariantDeserializer::struct_variant
// Content::Seq case
// via ContentDeserializer::deserialize_enum
assert_de_tokens(
&Outer::Inner(Inner::Struct { f: 1 }),
&[
Token::Map { len: Some(2) },
Token::Str("type"),
Token::Str("Inner"),
Token::Str("Struct"),
Token::Seq { len: Some(1) },
Token::U8(1), // f
Token::SeqEnd,
Token::MapEnd,
],
);
} }
#[test] #[test]