From 2adb0e99b024aab039a9fc6fdd384e84c8ae8297 Mon Sep 17 00:00:00 2001 From: Mingun Date: Tue, 8 Aug 2023 01:56:51 +0500 Subject: [PATCH] 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 --- .../tests/test_enum_internally_tagged.rs | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/test_suite/tests/test_enum_internally_tagged.rs b/test_suite/tests/test_enum_internally_tagged.rs index 9527da58..b4d428c4 100644 --- a/test_suite/tests/test_enum_internally_tagged.rs +++ b/test_suite/tests/test_enum_internally_tagged.rs @@ -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]