From 01da3f79c9a41220174e8b7e89c3e836325e97ff Mon Sep 17 00:00:00 2001 From: bebecue Date: Tue, 7 Mar 2023 08:09:01 +0800 Subject: [PATCH] Add tests for #2387 --- test_suite/tests/test_annotations.rs | 62 ++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/test_suite/tests/test_annotations.rs b/test_suite/tests/test_annotations.rs index 75b7ffdd0..8ff725e01 100644 --- a/test_suite/tests/test_annotations.rs +++ b/test_suite/tests/test_annotations.rs @@ -2658,6 +2658,68 @@ fn test_flatten_any_after_flatten_struct() { ); } +#[test] +fn test_alias_in_flatten_context() { + #[derive(Debug, PartialEq, Deserialize)] + struct Outer { + #[serde(flatten)] + a: AliasStruct, + b: i32, + } + + assert_de_tokens( + &Outer { + a: AliasStruct { + a1: 1, + a2: 2, + a4: 4, + }, + b: 7, + }, + &[ + Token::Struct { + name: "Outer", + len: 4, + }, + Token::Str("a1"), + Token::I32(1), + Token::Str("a2"), + Token::I32(2), + Token::Str("a5"), + Token::I32(4), + Token::Str("b"), + Token::I32(7), + Token::StructEnd, + ], + ); + + assert_de_tokens( + &Outer { + a: AliasStruct { + a1: 1, + a2: 2, + a4: 4, + }, + b: 7, + }, + &[ + Token::Struct { + name: "Outer", + len: 4, + }, + Token::Str("a1"), + Token::I32(1), + Token::Str("a2"), + Token::I32(2), + Token::Str("a6"), + Token::I32(4), + Token::Str("b"), + Token::I32(7), + Token::StructEnd, + ], + ); +} + #[test] fn test_expecting_message() { #[derive(Deserialize, PartialEq, Debug)]