summaryrefslogtreecommitdiffstats
path: root/third_party/rust/darling/tests/skip.rs
blob: b4e0f64dc13af01ddad5214b66d1f05a00b57091 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//! Test that skipped fields are not read into structs when they appear in input.

#[macro_use]
extern crate darling;
#[macro_use]
extern crate syn;
#[macro_use]
extern crate quote;

use darling::FromDeriveInput;

#[derive(Debug, PartialEq, Eq, FromDeriveInput)]
#[darling(attributes(skip_test))]
pub struct Lorem {
    ipsum: String,

    #[darling(skip)]
    dolor: u8,
}

/// Verify variant-level and field-level skip work correctly for enums.
#[derive(Debug, FromMeta)]
pub enum Sit {
    Amet(bool),

    #[darling(skip)]
    Foo {
        hello: bool,
    },

    Bar {
        hello: bool,
        #[darling(skip)]
        world: u8,
    },
}

#[test]
fn verify_skipped_field_not_required() {
    let di = parse_quote! {
        #[skip_test(ipsum = "Hello")]
        struct Baz;
    };

    assert_eq!(
        Lorem::from_derive_input(&di).unwrap(),
        Lorem {
            ipsum: "Hello".to_string(),
            dolor: 0,
        }
    );
}