aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_mbe/src/lib.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-04-18 13:00:16 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-04-18 13:00:16 +0100
commit403cd78baee7e9c2410d04ca0304575e7bbab16d (patch)
tree9e7ff9215e3490169c63c12e03c2eb03ca59ba20 /crates/ra_mbe/src/lib.rs
parent112fd0ec7d65b5f23865410fd3e188e761d97110 (diff)
parente944fd059de93f305d6a8c40cfac5ebe84548771 (diff)
Merge #1161
1161: Add mbe 'item' matcher r=matklad a=edwin0cheng Add `item` matcher in `ra_mbe` , and added corresponding `item()` parser in `ra_syntax`. This PR also help PR #1148 for `Items` parsing. And hopefully fix #1149 ?! Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates/ra_mbe/src/lib.rs')
-rw-r--r--crates/ra_mbe/src/lib.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/crates/ra_mbe/src/lib.rs b/crates/ra_mbe/src/lib.rs
index a1f438906..2f47e32d3 100644
--- a/crates/ra_mbe/src/lib.rs
+++ b/crates/ra_mbe/src/lib.rs
@@ -597,4 +597,48 @@ SOURCE_FILE@[0; 40)
597 assert_expansion(&rules, "foo! { 2 }", "fn bar () {2 ;}"); 597 assert_expansion(&rules, "foo! { 2 }", "fn bar () {2 ;}");
598 assert_expansion(&rules, "foo! { let a = 0 }", "fn bar () {let a = 0 ;}"); 598 assert_expansion(&rules, "foo! { let a = 0 }", "fn bar () {let a = 0 ;}");
599 } 599 }
600
601 #[test]
602 fn test_single_item() {
603 let rules = create_rules(
604 r#"
605 macro_rules! foo {
606 ($ i:item) => (
607 $ i
608 )
609 }
610"#,
611 );
612 assert_expansion(&rules, "foo! {mod c {}}", "mod c {}");
613 }
614
615 #[test]
616 fn test_all_items() {
617 let rules = create_rules(
618 r#"
619 macro_rules! foo {
620 ($ ($ i:item)*) => ($ (
621 $ i
622 )*)
623 }
624"#,
625 );
626 assert_expansion(&rules, r#"
627 foo! {
628 extern crate a;
629 mod b;
630 mod c {}
631 use d;
632 const E: i32 = 0;
633 static F: i32 = 0;
634 impl G {}
635 struct H;
636 enum I { Foo }
637 trait J {}
638 fn h() {}
639 extern {}
640 type T = u8;
641 }
642"#, 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 ;"#);
643 }
600} 644}