From c383e4f9535e4ffdbda36d5c5c2a01bc0518237a Mon Sep 17 00:00:00 2001 From: Mingun Date: Fri, 16 Aug 2024 22:18:20 +0500 Subject: [PATCH] Tuple: add tests for deserialization from sequence (review this commit with "ignore whitespace changes" option on) --- .../tests/test_enum_adjacently_tagged.rs | 116 +++++++++++------- 1 file changed, 71 insertions(+), 45 deletions(-) diff --git a/test_suite/tests/test_enum_adjacently_tagged.rs b/test_suite/tests/test_enum_adjacently_tagged.rs index d21ac73c..5584f662 100644 --- a/test_suite/tests/test_enum_adjacently_tagged.rs +++ b/test_suite/tests/test_enum_adjacently_tagged.rs @@ -437,53 +437,79 @@ fn newtype_with_newtype() { ); } -#[test] -fn tuple() { - let value = AdjacentlyTagged::Tuple::(1, 1); +mod tuple { + use super::*; - // tuple with tag first - assert_tokens( - &value, - &[ - Token::Struct { - name: "AdjacentlyTagged", - len: 2, - }, - Token::Str("t"), - Token::UnitVariant { - name: "AdjacentlyTagged", - variant: "Tuple", - }, - Token::Str("c"), - Token::Tuple { len: 2 }, - Token::U8(1), - Token::U8(1), - Token::TupleEnd, - Token::StructEnd, - ], - ); + #[test] + fn map() { + let value = AdjacentlyTagged::Tuple::(1, 1); - // tuple with content first - assert_de_tokens( - &value, - &[ - Token::Struct { - name: "AdjacentlyTagged", - len: 2, - }, - Token::Str("c"), - Token::Tuple { len: 2 }, - Token::U8(1), - Token::U8(1), - Token::TupleEnd, - Token::Str("t"), - Token::UnitVariant { - name: "AdjacentlyTagged", - variant: "Tuple", - }, - Token::StructEnd, - ], - ); + // Map: tag + content + assert_tokens( + &value, + &[ + Token::Struct { + name: "AdjacentlyTagged", + len: 2, + }, + Token::Str("t"), + Token::UnitVariant { + name: "AdjacentlyTagged", + variant: "Tuple", + }, + Token::Str("c"), + Token::Tuple { len: 2 }, + Token::U8(1), + Token::U8(1), + Token::TupleEnd, + Token::StructEnd, + ], + ); + + // Map: content + tag + assert_de_tokens( + &value, + &[ + Token::Struct { + name: "AdjacentlyTagged", + len: 2, + }, + Token::Str("c"), + Token::Tuple { len: 2 }, + Token::U8(1), + Token::U8(1), + Token::TupleEnd, + Token::Str("t"), + Token::UnitVariant { + name: "AdjacentlyTagged", + variant: "Tuple", + }, + Token::StructEnd, + ], + ); + } + + #[test] + fn seq() { + let value = AdjacentlyTagged::Tuple::(1, 1); + + // Seq: tag + content + assert_de_tokens( + &value, + &[ + Token::Seq { len: Some(2) }, + Token::UnitVariant { + name: "AdjacentlyTagged", + variant: "Tuple", + }, + Token::Tuple { len: 2 }, + Token::U8(1), + Token::U8(1), + Token::TupleEnd, + Token::SeqEnd, + ], + ); + } } #[test]