summaryrefslogtreecommitdiffstats
path: root/vendor/syn/tests/test_receiver.rs
blob: 923df96ba9a1fab5101d2dc40c1f9bc448b392f0 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
use syn::{parse_quote, FnArg, Receiver, TraitItemMethod};

#[test]
fn test_by_value() {
    let TraitItemMethod { sig, .. } = parse_quote! {
        fn by_value(self: Self);
    };
    match sig.receiver() {
        Some(FnArg::Typed(_)) => (),
        value => panic!("expected FnArg::Typed, got {:?}", value),
    }
}

#[test]
fn test_by_mut_value() {
    let TraitItemMethod { sig, .. } = parse_quote! {
        fn by_mut(mut self: Self);
    };
    match sig.receiver() {
        Some(FnArg::Typed(_)) => (),
        value => panic!("expected FnArg::Typed, got {:?}", value),
    }
}

#[test]
fn test_by_ref() {
    let TraitItemMethod { sig, .. } = parse_quote! {
        fn by_ref(self: &Self);
    };
    match sig.receiver() {
        Some(FnArg::Typed(_)) => (),
        value => panic!("expected FnArg::Typed, got {:?}", value),
    }
}

#[test]
fn test_by_box() {
    let TraitItemMethod { sig, .. } = parse_quote! {
        fn by_box(self: Box<Self>);
    };
    match sig.receiver() {
        Some(FnArg::Typed(_)) => (),
        value => panic!("expected FnArg::Typed, got {:?}", value),
    }
}

#[test]
fn test_by_pin() {
    let TraitItemMethod { sig, .. } = parse_quote! {
        fn by_pin(self: Pin<Self>);
    };
    match sig.receiver() {
        Some(FnArg::Typed(_)) => (),
        value => panic!("expected FnArg::Typed, got {:?}", value),
    }
}

#[test]
fn test_explicit_type() {
    let TraitItemMethod { sig, .. } = parse_quote! {
        fn explicit_type(self: Pin<MyType>);
    };
    match sig.receiver() {
        Some(FnArg::Typed(_)) => (),
        value => panic!("expected FnArg::Typed, got {:?}", value),
    }
}

#[test]
fn test_value_shorthand() {
    let TraitItemMethod { sig, .. } = parse_quote! {
        fn value_shorthand(self);
    };
    match sig.receiver() {
        Some(FnArg::Receiver(Receiver {
            reference: None,
            mutability: None,
            ..
        })) => (),
        value => panic!("expected FnArg::Receiver without ref/mut, got {:?}", value),
    }
}

#[test]
fn test_mut_value_shorthand() {
    let TraitItemMethod { sig, .. } = parse_quote! {
        fn mut_value_shorthand(mut self);
    };
    match sig.receiver() {
        Some(FnArg::Receiver(Receiver {
            reference: None,
            mutability: Some(_),
            ..
        })) => (),
        value => panic!("expected FnArg::Receiver with mut, got {:?}", value),
    }
}

#[test]
fn test_ref_shorthand() {
    let TraitItemMethod { sig, .. } = parse_quote! {
        fn ref_shorthand(&self);
    };
    match sig.receiver() {
        Some(FnArg::Receiver(Receiver {
            reference: Some(_),
            mutability: None,
            ..
        })) => (),
        value => panic!("expected FnArg::Receiver with ref, got {:?}", value),
    }
}

#[test]
fn test_ref_mut_shorthand() {
    let TraitItemMethod { sig, .. } = parse_quote! {
        fn ref_mut_shorthand(&mut self);
    };
    match sig.receiver() {
        Some(FnArg::Receiver(Receiver {
            reference: Some(_),
            mutability: Some(_),
            ..
        })) => (),
        value => panic!("expected FnArg::Receiver with ref+mut, got {:?}", value),
    }
}