]> git.lizzy.rs Git - rust.git/blob - crates/hir_def/src/macro_expansion_tests/proc_macros.rs
Merge #10785
[rust.git] / crates / hir_def / src / macro_expansion_tests / proc_macros.rs
1 //! Tests for user-defined procedural macros.
2 //!
3 //! Note `//- proc_macros: identity` fixture metas in tests -- we don't use real
4 //! proc-macros here, as that would be slow. Instead, we use several hard-coded
5 //! in-memory macros.
6 use expect_test::expect;
7
8 use crate::macro_expansion_tests::check;
9
10 #[test]
11 fn attribute_macro_attr_censoring() {
12     cov_mark::check!(attribute_macro_attr_censoring);
13     check(
14         r#"
15 //- proc_macros: identity
16 #[attr1] #[proc_macros::identity] #[attr2]
17 struct S;
18 "#,
19         expect![[r##"
20 #[attr1] #[proc_macros::identity] #[attr2]
21 struct S;
22
23 #[attr1]
24 #[attr2] struct S;"##]],
25     );
26 }
27
28 #[test]
29 fn derive_censoring() {
30     cov_mark::check!(derive_censoring);
31     check(
32         r#"
33 //- proc_macros: derive_identity
34 //- minicore:derive
35 #[attr1]
36 #[derive(Foo)]
37 #[derive(proc_macros::DeriveIdentity)]
38 #[derive(Bar)]
39 #[attr2]
40 struct S;
41 "#,
42         expect![[r##"
43 #[attr1]
44 #[derive(Foo)]
45 #[derive(proc_macros::DeriveIdentity)]
46 #[derive(Bar)]
47 #[attr2]
48 struct S;
49
50 #[attr1]
51 #[derive(Bar)]
52 #[attr2] struct S;"##]],
53     );
54 }