Unnamed repository; edit this file 'description' to name the repository.
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
//! proc-macro tests

#[macro_use]
mod utils;
use utils::*;

use expect_test::expect;

#[test]
fn test_derive_empty() {
    assert_expand(
        "DeriveEmpty",
        r#"struct S;"#,
        expect!["SUBTREE $$ 1 1"],
        expect!["SUBTREE $$ 42:[email protected]#0 42:[email protected]#0"],
    );
}

#[test]
fn test_derive_error() {
    assert_expand(
        "DeriveError",
        r#"struct S;"#,
        expect![[r##"
            SUBTREE $$ 1 1
              IDENT   compile_error 1
              PUNCH   ! [alone] 1
              SUBTREE () 1 1
                LITERAL "#[derive(DeriveError)] struct S ;"1
              PUNCH   ; [alone] 1"##]],
        expect![[r##"
            SUBTREE $$ 42:[email protected]#0 42:[email protected]#0
              IDENT   compile_error 42:[email protected]#0
              PUNCH   ! [alone] 42:[email protected]#0
              SUBTREE () 42:[email protected]#0 42:[email protected]#0
                LITERAL "#[derive(DeriveError)] struct S ;"42:[email protected]#0
              PUNCH   ; [alone] 42:[email protected]#0"##]],
    );
}

#[test]
fn test_fn_like_macro_noop() {
    assert_expand(
        "fn_like_noop",
        r#"ident, 0, 1, []"#,
        expect![[r#"
            SUBTREE $$ 1 1
              IDENT   ident 1
              PUNCH   , [alone] 1
              LITERAL 01
              PUNCH   , [alone] 1
              LITERAL 11
              PUNCH   , [alone] 1
              SUBTREE [] 1 1"#]],
        expect![[r#"
            SUBTREE $$ 42:[email protected]#0 42:[email protected]#0
              IDENT   ident 42:[email protected]#0
              PUNCH   , [alone] 42:[email protected]#0
              LITERAL 042:[email protected]#0
              PUNCH   , [alone] 42:[email protected]#0
              LITERAL 142:[email protected]#0
              PUNCH   , [alone] 42:[email protected]#0
              SUBTREE [] 42:[email protected]#0 42:[email protected]#0"#]],
    );
}

#[test]
fn test_fn_like_macro_clone_ident_subtree() {
    assert_expand(
        "fn_like_clone_tokens",
        r#"ident, []"#,
        expect![[r#"
            SUBTREE $$ 1 1
              IDENT   ident 1
              PUNCH   , [alone] 1
              SUBTREE [] 1 1"#]],
        expect![[r#"
            SUBTREE $$ 42:[email protected]#0 42:[email protected]#0
              IDENT   ident 42:[email protected]#0
              PUNCH   , [alone] 42:[email protected]#0
              SUBTREE [] 42:[email protected]#0 42:[email protected]#0"#]],
    );
}

#[test]
fn test_fn_like_macro_clone_raw_ident() {
    assert_expand(
        "fn_like_clone_tokens",
        "r#async",
        expect![[r#"
            SUBTREE $$ 1 1
              IDENT   r#async 1"#]],
        expect![[r#"
            SUBTREE $$ 42:[email protected]#0 42:[email protected]#0
              IDENT   r#async 42:[email protected]#0"#]],
    );
}

#[test]
fn test_fn_like_fn_like_span_join() {
    assert_expand(
        "fn_like_span_join",
        "foo     bar",
        expect![[r#"
            SUBTREE $$ 1 1
              IDENT   r#joined 1"#]],
        expect![[r#"
            SUBTREE $$ 42:[email protected]#0 42:[email protected]#0
              IDENT   r#joined 42:[email protected]#0"#]],
    );
}

#[test]
fn test_fn_like_fn_like_span_ops() {
    assert_expand(
        "fn_like_span_ops",
        "set_def_site resolved_at_def_site start_span",
        expect![[r#"
            SUBTREE $$ 1 1
              IDENT   set_def_site 0
              IDENT   resolved_at_def_site 1
              IDENT   start_span 1"#]],
        expect![[r#"
            SUBTREE $$ 42:[email protected]#0 42:[email protected]#0
              IDENT   set_def_site 41:[email protected]#0
              IDENT   resolved_at_def_site 42:[email protected]#0
              IDENT   start_span 42:[email protected]#0"#]],
    );
}

#[test]
fn test_fn_like_mk_literals() {
    assert_expand(
        "fn_like_mk_literals",
        r#""#,
        expect![[r#"
            SUBTREE $$ 1 1
              LITERAL b"byte_string"1
              LITERAL 'c'1
              LITERAL "string"1
              LITERAL 3.14f641
              LITERAL 3.141
              LITERAL 123i641
              LITERAL 1231"#]],
        expect![[r#"
            SUBTREE $$ 42:[email protected]#0 42:[email protected]#0
              LITERAL b"byte_string"42:[email protected]#0
              LITERAL 'c'42:[email protected]#0
              LITERAL "string"42:[email protected]#0
              LITERAL 3.14f6442:[email protected]#0
              LITERAL 3.1442:[email protected]#0
              LITERAL 123i6442:[email protected]#0
              LITERAL 12342:[email protected]#0"#]],
    );
}

#[test]
fn test_fn_like_mk_idents() {
    assert_expand(
        "fn_like_mk_idents",
        r#""#,
        expect![[r#"
            SUBTREE $$ 1 1
              IDENT   standard 1
              IDENT   r#raw 1"#]],
        expect![[r#"
            SUBTREE $$ 42:[email protected]#0 42:[email protected]#0
              IDENT   standard 42:[email protected]#0
              IDENT   r#raw 42:[email protected]#0"#]],
    );
}

#[test]
fn test_fn_like_macro_clone_literals() {
    assert_expand(
        "fn_like_clone_tokens",
        r###"1u16, 2_u32, -4i64, 3.14f32, "hello bridge", "suffixed"suffix, r##"raw"##, 'a', b'b', c"null""###,
        expect![[r###"
            SUBTREE $$ 1 1
              LITERAL 1u161
              PUNCH   , [alone] 1
              LITERAL 2_u321
              PUNCH   , [alone] 1
              PUNCH   - [alone] 1
              LITERAL 4i641
              PUNCH   , [alone] 1
              LITERAL 3.14f321
              PUNCH   , [alone] 1
              LITERAL "hello bridge"1
              PUNCH   , [alone] 1
              LITERAL "suffixed"suffix1
              PUNCH   , [alone] 1
              LITERAL r##"raw"##1
              PUNCH   , [alone] 1
              LITERAL 'a'1
              PUNCH   , [alone] 1
              LITERAL b'b'1
              PUNCH   , [alone] 1
              LITERAL c"null"1"###]],
        expect![[r###"
            SUBTREE $$ 42:[email protected]#0 42:[email protected]#0
              LITERAL 1u1642:[email protected]#0
              PUNCH   , [alone] 42:[email protected]#0
              LITERAL 2_u3242:[email protected]#0
              PUNCH   , [alone] 42:[email protected]#0
              PUNCH   - [alone] 42:[email protected]#0
              LITERAL 4i6442:[email protected]#0
              PUNCH   , [alone] 42:[email protected]#0
              LITERAL 3.14f3242:[email protected]#0
              PUNCH   , [alone] 42:[email protected]#0
              LITERAL "hello bridge"42:[email protected]#0
              PUNCH   , [alone] 42:[email protected]#0
              LITERAL "suffixed"suffix42:[email protected]#0
              PUNCH   , [alone] 42:[email protected]#0
              LITERAL r##"raw"##42:[email protected]#0
              PUNCH   , [alone] 42:[email protected]#0
              LITERAL 'a'42:[email protected]#0
              PUNCH   , [alone] 42:[email protected]#0
              LITERAL b'b'42:[email protected]#0
              PUNCH   , [alone] 42:[email protected]#0
              LITERAL c"null"42:[email protected]#0"###]],
    );
}

#[test]
fn test_attr_macro() {
    // Corresponds to
    //    #[proc_macro_test::attr_error(some arguments)]
    //    mod m {}
    assert_expand_attr(
        "attr_error",
        r#"mod m {}"#,
        r#"some arguments"#,
        expect![[r##"
            SUBTREE $$ 1 1
              IDENT   compile_error 1
              PUNCH   ! [alone] 1
              SUBTREE () 1 1
                LITERAL "#[attr_error(some arguments)] mod m {}"1
              PUNCH   ; [alone] 1"##]],
        expect![[r##"
            SUBTREE $$ 42:[email protected]#0 42:[email protected]#0
              IDENT   compile_error 42:[email protected]#0
              PUNCH   ! [alone] 42:[email protected]#0
              SUBTREE () 42:[email protected]#0 42:[email protected]#0
                LITERAL "#[attr_error(some arguments)] mod m {}"42:[email protected]#0
              PUNCH   ; [alone] 42:[email protected]#0"##]],
    );
}

/// Tests that we find and classify all proc macros correctly.
#[test]
fn list_test_macros() {
    let res = list().join("\n");

    expect![[r#"
        fn_like_noop [Bang]
        fn_like_panic [Bang]
        fn_like_error [Bang]
        fn_like_clone_tokens [Bang]
        fn_like_mk_literals [Bang]
        fn_like_mk_idents [Bang]
        fn_like_span_join [Bang]
        fn_like_span_ops [Bang]
        attr_noop [Attr]
        attr_panic [Attr]
        attr_error [Attr]
        DeriveEmpty [CustomDerive]
        DerivePanic [CustomDerive]
        DeriveError [CustomDerive]"#]]
    .assert_eq(&res);
}