From 43ba81eba064959a37447f1fa68a670445c2675c Mon Sep 17 00:00:00 2001 From: Nicholas Rempel Date: Mon, 25 Sep 2023 15:50:00 +0100 Subject: [PATCH] Introduce failing test for flattened enums --- tests/tests.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/tests.rs b/tests/tests.rs index bfa6d99..d37afb1 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -444,3 +444,35 @@ fn ser_de_field_vec_tuple() { test_ser_de_eq(foo); } + +#[test] +fn ser_de_flattened_enum() { + #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] + struct KrpcMessage { + message_type: MessageType, + } + + #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] + enum MessageType { + Query, + Response, + } + + #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] + struct KrpcResponse { + #[serde(flatten)] + krpc: KrpcMessage, + } + + // Passes + test_ser_de_eq(KrpcMessage { + message_type: MessageType::Response, + }); + + // Fails + test_ser_de_eq(KrpcResponse { + krpc: KrpcMessage { + message_type: MessageType::Response, + }, + }); +}