diff options
Diffstat (limited to 'crates/ra_mbe/src/lib.rs')
-rw-r--r-- | crates/ra_mbe/src/lib.rs | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/crates/ra_mbe/src/lib.rs b/crates/ra_mbe/src/lib.rs index 9d4744838..814586fd6 100644 --- a/crates/ra_mbe/src/lib.rs +++ b/crates/ra_mbe/src/lib.rs | |||
@@ -731,4 +731,95 @@ MACRO_ITEMS@[0; 40) | |||
731 | } | 731 | } |
732 | "#, r#"extern crate a ; mod b ; mod c {} use d ; const E : i32 = 0 ; static F : i32 = 0 ; impl G {} struct H ; enum I {Foo} trait J {} fn h () {} extern {} type T = u8 ;"#); | 732 | "#, r#"extern crate a ; mod b ; mod c {} use d ; const E : i32 = 0 ; static F : i32 = 0 ; impl G {} struct H ; enum I {Foo} trait J {} fn h () {} extern {} type T = u8 ;"#); |
733 | } | 733 | } |
734 | |||
735 | #[test] | ||
736 | fn test_block() { | ||
737 | let rules = create_rules( | ||
738 | r#" | ||
739 | macro_rules! foo { | ||
740 | ($ i:block) => { fn foo() $ i } | ||
741 | } | ||
742 | "#, | ||
743 | ); | ||
744 | assert_expansion(&rules, "foo! { { 1; } }", "fn foo () {1 ;}"); | ||
745 | } | ||
746 | |||
747 | #[test] | ||
748 | fn test_meta() { | ||
749 | let rules = create_rules( | ||
750 | r#" | ||
751 | macro_rules! foo { | ||
752 | ($ i:meta) => ( | ||
753 | #[$ i] | ||
754 | fn bar() {} | ||
755 | ) | ||
756 | } | ||
757 | "#, | ||
758 | ); | ||
759 | assert_expansion( | ||
760 | &rules, | ||
761 | r#"foo! { cfg(target_os = "windows") }"#, | ||
762 | r#"# [cfg (target_os = "windows")] fn bar () {}"#, | ||
763 | ); | ||
764 | } | ||
765 | |||
766 | #[test] | ||
767 | fn test_tt_block() { | ||
768 | let rules = create_rules( | ||
769 | r#" | ||
770 | macro_rules! foo { | ||
771 | ($ i:tt) => { fn foo() $ i } | ||
772 | } | ||
773 | "#, | ||
774 | ); | ||
775 | assert_expansion(&rules, r#"foo! { { 1; } }"#, r#"fn foo () {1 ;}"#); | ||
776 | } | ||
777 | |||
778 | #[test] | ||
779 | fn test_tt_group() { | ||
780 | let rules = create_rules( | ||
781 | r#" | ||
782 | macro_rules! foo { | ||
783 | ($($ i:tt)*) => { $($ i)* } | ||
784 | } | ||
785 | "#, | ||
786 | ); | ||
787 | assert_expansion(&rules, r#"foo! { fn foo() {} }"#, r#"fn foo () {}"#); | ||
788 | } | ||
789 | |||
790 | #[test] | ||
791 | fn test_lifetime() { | ||
792 | let rules = create_rules( | ||
793 | r#" | ||
794 | macro_rules! foo { | ||
795 | ($ lt:lifetime) => { struct Ref<$ lt>{ s: &$ lt str } } | ||
796 | } | ||
797 | "#, | ||
798 | ); | ||
799 | assert_expansion(&rules, r#"foo!{'a}"#, r#"struct Ref < 'a > {s : & 'a str}"#); | ||
800 | } | ||
801 | |||
802 | #[test] | ||
803 | fn test_literal() { | ||
804 | let rules = create_rules( | ||
805 | r#" | ||
806 | macro_rules! foo { | ||
807 | ($ type:ty $ lit:literal) => { const VALUE: $ type = $ lit;}; | ||
808 | } | ||
809 | "#, | ||
810 | ); | ||
811 | assert_expansion(&rules, r#"foo!(u8 0)"#, r#"const VALUE : u8 = 0 ;"#); | ||
812 | } | ||
813 | |||
814 | #[test] | ||
815 | fn test_vis() { | ||
816 | let rules = create_rules( | ||
817 | r#" | ||
818 | macro_rules! foo { | ||
819 | ($ vis:vis $ name:ident) => { $ vis fn $ name() {}}; | ||
820 | } | ||
821 | "#, | ||
822 | ); | ||
823 | assert_expansion(&rules, r#"foo!(pub foo);"#, r#"pub fn foo () {}"#); | ||
824 | } | ||
734 | } | 825 | } |