serde-ignored icon indicating copy to clipboard operation
serde-ignored copied to clipboard

Not detecting ignored fields in internally tagged enums

Open ttencate opened this issue 2 years ago • 0 comments

Drop-in unit test:

#[test]
fn test_internally_tagged_enum() {
    #[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Deserialize)]
    struct Struct {
        field: String,
    }

    #[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Deserialize)]
    #[serde(tag = "type")]
    enum Enum {
        Variant(Struct),
    }

    let json = r#"{
        "type": "Variant",
        "field": "value",
        "typo": "bork"
    }"#;

    let ignored = &["typo"];
    assert_ignored::<Enum>(json, ignored);
}

Output:

---- test_enum stdout ----
thread 'test_internally_tagged_enum' panicked at 'assertion failed: `(left == right)`
  left: `{}`,
 right: `{"typo"}`', tests/test.rs:22:5

ttencate avatar Feb 17 '22 16:02 ttencate