From fca1422ea34363b6f47da76914022bc60f7f66df Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 1 Jan 2019 22:12:05 +0300 Subject: add tests for macro generated items --- crates/ra_hir/src/module/nameres/tests.rs | 84 ++++++++++++++++++++++++++++++- 1 file changed, 83 insertions(+), 1 deletion(-) (limited to 'crates/ra_hir/src/module/nameres') diff --git a/crates/ra_hir/src/module/nameres/tests.rs b/crates/ra_hir/src/module/nameres/tests.rs index ca20f064f..a6a0bea31 100644 --- a/crates/ra_hir/src/module/nameres/tests.rs +++ b/crates/ra_hir/src/module/nameres/tests.rs @@ -77,6 +77,35 @@ fn item_map_smoke_test() { ); } +#[test] +fn item_map_contains_items_from_expansions() { + let (item_map, module_id) = item_map( + " + //- /lib.rs + mod foo; + + use crate::foo::bar::Baz; + <|> + + //- /foo/mod.rs + pub mod bar; + + //- /foo/bar.rs + salsa::query_group! { + trait Baz {} + } + ", + ); + check_module_item_map( + &item_map, + module_id, + " + Baz: t + foo: t + ", + ); +} + #[test] fn item_map_using_self() { let (item_map, module_id) = item_map( @@ -141,6 +170,59 @@ fn item_map_across_crates() { #[test] fn typing_inside_a_function_should_not_invalidate_item_map() { + let (mut db, pos) = MockDatabase::with_position( + " + //- /lib.rs + mod foo; + + use crate::foo::bar::Baz; + + //- /foo/mod.rs + pub mod bar; + + //- /foo/bar.rs + <|> + salsa::query_group! { + trait Baz { + fn foo() -> i32 { 1 + 1 } + } + } + ", + ); + let source_root = db.file_source_root(pos.file_id); + { + let events = db.log_executed(|| { + db.item_map(source_root).unwrap(); + }); + assert!(format!("{:?}", events).contains("item_map")) + } + + let new_text = " + salsa::query_group! { + trait Baz { + fn foo() -> i32 { 92 } + } + } + " + .to_string(); + + db.query_mut(ra_db::FileTextQuery) + .set(pos.file_id, Arc::new(new_text)); + + { + let events = db.log_executed(|| { + db.item_map(source_root).unwrap(); + }); + assert!( + !format!("{:?}", events).contains("item_map"), + "{:#?}", + events + ) + } +} + +#[test] +fn typing_inside_a_function_inside_a_macro_should_not_invalidate_item_map() { let (mut db, pos) = MockDatabase::with_position( " //- /lib.rs @@ -183,7 +265,7 @@ fn typing_inside_a_function_should_not_invalidate_item_map() { db.item_map(source_root).unwrap(); }); assert!( - !format!("{:?}", events).contains("_item_map"), + !format!("{:?}", events).contains("item_map"), "{:#?}", events ) -- cgit v1.2.3