aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/body/tests.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_def/src/body/tests.rs')
-rw-r--r--crates/hir_def/src/body/tests.rs56
1 files changed, 48 insertions, 8 deletions
diff --git a/crates/hir_def/src/body/tests.rs b/crates/hir_def/src/body/tests.rs
index de77d5fc9..bb43569d7 100644
--- a/crates/hir_def/src/body/tests.rs
+++ b/crates/hir_def/src/body/tests.rs
@@ -1,4 +1,7 @@
1mod block;
2
1use base_db::{fixture::WithFixture, SourceDatabase}; 3use base_db::{fixture::WithFixture, SourceDatabase};
4use expect_test::Expect;
2use test_utils::mark; 5use test_utils::mark;
3 6
4use crate::{test_db::TestDB, ModuleDefId}; 7use crate::{test_db::TestDB, ModuleDefId};
@@ -6,18 +9,24 @@ use crate::{test_db::TestDB, ModuleDefId};
6use super::*; 9use super::*;
7 10
8fn lower(ra_fixture: &str) -> Arc<Body> { 11fn lower(ra_fixture: &str) -> Arc<Body> {
9 let (db, file_id) = crate::test_db::TestDB::with_single_file(ra_fixture); 12 let db = crate::test_db::TestDB::with_files(ra_fixture);
10 13
11 let krate = db.crate_graph().iter().next().unwrap(); 14 let krate = db.crate_graph().iter().next().unwrap();
12 let def_map = db.crate_def_map(krate); 15 let def_map = db.crate_def_map(krate);
13 let module = def_map.modules_for_file(file_id).next().unwrap(); 16 let mut fn_def = None;
14 let module = &def_map[module]; 17 'outer: for (_, module) in def_map.modules() {
15 let fn_def = match module.scope.declarations().next().unwrap() { 18 for decl in module.scope.declarations() {
16 ModuleDefId::FunctionId(it) => it, 19 match decl {
17 _ => panic!(), 20 ModuleDefId::FunctionId(it) => {
18 }; 21 fn_def = Some(it);
22 break 'outer;
23 }
24 _ => {}
25 }
26 }
27 }
19 28
20 db.body(fn_def.into()) 29 db.body(fn_def.unwrap().into())
21} 30}
22 31
23fn check_diagnostics(ra_fixture: &str) { 32fn check_diagnostics(ra_fixture: &str) {
@@ -25,6 +34,18 @@ fn check_diagnostics(ra_fixture: &str) {
25 db.check_diagnostics(); 34 db.check_diagnostics();
26} 35}
27 36
37fn block_def_map_at(ra_fixture: &str) -> String {
38 let (db, position) = crate::test_db::TestDB::with_position(ra_fixture);
39
40 let module = db.module_at_position(position);
41 module.def_map(&db).dump(&db)
42}
43
44fn check_at(ra_fixture: &str, expect: Expect) {
45 let actual = block_def_map_at(ra_fixture);
46 expect.assert_eq(&actual);
47}
48
28#[test] 49#[test]
29fn your_stack_belongs_to_me() { 50fn your_stack_belongs_to_me() {
30 mark::check!(your_stack_belongs_to_me); 51 mark::check!(your_stack_belongs_to_me);
@@ -42,6 +63,25 @@ fn main() { n_nuple!(1,2,3); }
42} 63}
43 64
44#[test] 65#[test]
66fn macro_resolve() {
67 // Regression test for a path resolution bug introduced with inner item handling.
68 lower(
69 r"
70macro_rules! vec {
71 () => { () };
72 ($elem:expr; $n:expr) => { () };
73 ($($x:expr),+ $(,)?) => { () };
74}
75mod m {
76 fn outer() {
77 let _ = vec![FileSet::default(); self.len()];
78 }
79}
80 ",
81 );
82}
83
84#[test]
45fn cfg_diagnostics() { 85fn cfg_diagnostics() {
46 check_diagnostics( 86 check_diagnostics(
47 r" 87 r"