Skip to content

Commit

Permalink
Merge torrust#2: Introduce failing test for flattened enums
Browse files Browse the repository at this point in the history
43ba81e Introduce failing test for flattened enums (Nicholas Rempel)

Pull request description:

  From: #31 (comment)
  By: [nrempel](https://github.com/nrempel)

  ```
  Hello,

  This pull request adds a failing test for deserializing flattened structs containing enums.

  Is it expected that this test should pass or is there some serde caveat that I'm unaware of here? I'm happy to take a crack at fixing this if it's fixable. Any pointers would be appreciated.

  Thanks.
  ```

ACKs for top commit:
  josecelano:
    ACK 43ba81e

Tree-SHA512: aa996152a2a7a583b7a6eff54b99edfb0872ebf77803cab376e9db19200cbacd42bef11fc51a33254fd13d6eb5f67f483e23a90bf008f2fe1ade4aa55118453e
  • Loading branch information
josecelano committed Sep 25, 2023
2 parents ecd700c + 43ba81e commit 686a005
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
});
}

0 comments on commit 686a005

Please sign in to comment.