diff options
Diffstat (limited to 'crates/hir_def/src/nameres/tests/macros.rs')
-rw-r--r-- | crates/hir_def/src/nameres/tests/macros.rs | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/crates/hir_def/src/nameres/tests/macros.rs b/crates/hir_def/src/nameres/tests/macros.rs index f65a655bf..6d3cb8d7a 100644 --- a/crates/hir_def/src/nameres/tests/macros.rs +++ b/crates/hir_def/src/nameres/tests/macros.rs | |||
@@ -1,4 +1,5 @@ | |||
1 | use super::*; | 1 | use super::*; |
2 | use crate::nameres::proc_macro::{ProcMacroDef, ProcMacroKind}; | ||
2 | 3 | ||
3 | #[test] | 4 | #[test] |
4 | fn macro_rules_are_globally_visible() { | 5 | fn macro_rules_are_globally_visible() { |
@@ -712,6 +713,27 @@ b! { static = #[] ();} | |||
712 | } | 713 | } |
713 | 714 | ||
714 | #[test] | 715 | #[test] |
716 | fn macros_defining_macros() { | ||
717 | check( | ||
718 | r#" | ||
719 | macro_rules! item { | ||
720 | ($item:item) => { $item } | ||
721 | } | ||
722 | |||
723 | item! { | ||
724 | macro_rules! indirect_macro { () => { struct S {} } } | ||
725 | } | ||
726 | |||
727 | indirect_macro!(); | ||
728 | "#, | ||
729 | expect![[r#" | ||
730 | crate | ||
731 | S: t | ||
732 | "#]], | ||
733 | ); | ||
734 | } | ||
735 | |||
736 | #[test] | ||
715 | fn resolves_proc_macros() { | 737 | fn resolves_proc_macros() { |
716 | check( | 738 | check( |
717 | r" | 739 | r" |
@@ -790,3 +812,28 @@ fn proc_macro_censoring() { | |||
790 | "#]], | 812 | "#]], |
791 | ); | 813 | ); |
792 | } | 814 | } |
815 | |||
816 | #[test] | ||
817 | fn collects_derive_helpers() { | ||
818 | let def_map = compute_crate_def_map( | ||
819 | r" | ||
820 | struct TokenStream; | ||
821 | |||
822 | #[proc_macro_derive(AnotherTrait, attributes(helper_attr))] | ||
823 | pub fn derive_macro_2(_item: TokenStream) -> TokenStream { | ||
824 | TokenStream | ||
825 | } | ||
826 | ", | ||
827 | ); | ||
828 | |||
829 | assert_eq!(def_map.exported_proc_macros.len(), 1); | ||
830 | match def_map.exported_proc_macros.values().next() { | ||
831 | Some(ProcMacroDef { kind: ProcMacroKind::CustomDerive { helpers }, .. }) => { | ||
832 | match &**helpers { | ||
833 | [attr] => assert_eq!(attr.to_string(), "helper_attr"), | ||
834 | _ => unreachable!(), | ||
835 | } | ||
836 | } | ||
837 | _ => unreachable!(), | ||
838 | } | ||
839 | } | ||