1 mod block;
2 
3 use base_db::{fixture::WithFixture, SourceDatabase};
4 use expect_test::Expect;
5 
6 use crate::ModuleDefId;
7 
8 use super::*;
9 
lower(ra_fixture: &str) -> Arc<Body>10 fn lower(ra_fixture: &str) -> Arc<Body> {
11     let db = crate::test_db::TestDB::with_files(ra_fixture);
12 
13     let krate = db.crate_graph().iter().next().unwrap();
14     let def_map = db.crate_def_map(krate);
15     let mut fn_def = None;
16     'outer: for (_, module) in def_map.modules() {
17         for decl in module.scope.declarations() {
18             if let ModuleDefId::FunctionId(it) = decl {
19                 fn_def = Some(it);
20                 break 'outer;
21             }
22         }
23     }
24 
25     db.body(fn_def.unwrap().into())
26 }
27 
block_def_map_at(ra_fixture: &str) -> String28 fn block_def_map_at(ra_fixture: &str) -> String {
29     let (db, position) = crate::test_db::TestDB::with_position(ra_fixture);
30 
31     let module = db.module_at_position(position);
32     module.def_map(&db).dump(&db)
33 }
34 
check_block_scopes_at(ra_fixture: &str, expect: Expect)35 fn check_block_scopes_at(ra_fixture: &str, expect: Expect) {
36     let (db, position) = crate::test_db::TestDB::with_position(ra_fixture);
37 
38     let module = db.module_at_position(position);
39     let actual = module.def_map(&db).dump_block_scopes(&db);
40     expect.assert_eq(&actual);
41 }
42 
check_at(ra_fixture: &str, expect: Expect)43 fn check_at(ra_fixture: &str, expect: Expect) {
44     let actual = block_def_map_at(ra_fixture);
45     expect.assert_eq(&actual);
46 }
47 
48 #[test]
your_stack_belongs_to_me()49 fn your_stack_belongs_to_me() {
50     cov_mark::check!(your_stack_belongs_to_me);
51     lower(
52         r#"
53 macro_rules! n_nuple {
54     ($e:tt) => ();
55     ($($rest:tt)*) => {{
56         (n_nuple!($($rest)*)None,)
57     }};
58 }
59 fn main() { n_nuple!(1,2,3); }
60 "#,
61     );
62 }
63 
64 #[test]
macro_resolve()65 fn macro_resolve() {
66     // Regression test for a path resolution bug introduced with inner item handling.
67     lower(
68         r#"
69 macro_rules! vec {
70     () => { () };
71     ($elem:expr; $n:expr) => { () };
72     ($($x:expr),+ $(,)?) => { () };
73 }
74 mod m {
75     fn outer() {
76         let _ = vec![FileSet::default(); self.len()];
77     }
78 }
79 "#,
80     );
81 }
82