Skip to content

Commit

Permalink
Add a test for an internally tagged unit enum flattened with a second…
Browse files Browse the repository at this point in the history
… internally tagged unit enum.
  • Loading branch information
dreid committed Sep 6, 2018
1 parent 27478b6 commit 389b9b5
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test_suite/tests/test_annotations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2269,3 +2269,45 @@ fn test_internally_tagged_unit_enum_with_unknown_fields() {
],
);
}

#[test]
fn test_flattened_internally_tagged_unit_enum_with_unknown_fields() {
#[derive(Deserialize, PartialEq, Debug)]
struct S {
#[serde(flatten)]
x: X,
#[serde(flatten)]
y: Y,
}

#[derive(Deserialize, PartialEq, Debug)]
#[serde(tag = "typeX")]
enum X {
A,
}

#[derive(Deserialize, PartialEq, Debug)]
#[serde(tag = "typeY")]
enum Y {
B { c: u32 },
}

let s = S {
x: X::A,
y: Y::B { c: 0 },
};

assert_de_tokens(
&s,
&[
Token::Map { len: None },
Token::Str("typeX"),
Token::Str("A"),
Token::Str("typeY"),
Token::Str("B"),
Token::Str("c"),
Token::I32(0),
Token::MapEnd,
],
);
}

0 comments on commit 389b9b5

Please sign in to comment.