diff options
author | Aleksey Kladov <[email protected]> | 2019-01-01 19:12:05 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-01 19:15:35 +0000 |
commit | fca1422ea34363b6f47da76914022bc60f7f66df (patch) | |
tree | e46abefded22f84565a84985a6fc054cd05faf14 /crates/ra_hir/src/module/nameres | |
parent | 756e8781584fb28af208218615bafbbd9164dfbc (diff) |
add tests for macro generated items
Diffstat (limited to 'crates/ra_hir/src/module/nameres')
-rw-r--r-- | crates/ra_hir/src/module/nameres/tests.rs | 84 |
1 files changed, 83 insertions, 1 deletions
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 | |||
@@ -78,6 +78,35 @@ fn item_map_smoke_test() { | |||
78 | } | 78 | } |
79 | 79 | ||
80 | #[test] | 80 | #[test] |
81 | fn item_map_contains_items_from_expansions() { | ||
82 | let (item_map, module_id) = item_map( | ||
83 | " | ||
84 | //- /lib.rs | ||
85 | mod foo; | ||
86 | |||
87 | use crate::foo::bar::Baz; | ||
88 | <|> | ||
89 | |||
90 | //- /foo/mod.rs | ||
91 | pub mod bar; | ||
92 | |||
93 | //- /foo/bar.rs | ||
94 | salsa::query_group! { | ||
95 | trait Baz {} | ||
96 | } | ||
97 | ", | ||
98 | ); | ||
99 | check_module_item_map( | ||
100 | &item_map, | ||
101 | module_id, | ||
102 | " | ||
103 | Baz: t | ||
104 | foo: t | ||
105 | ", | ||
106 | ); | ||
107 | } | ||
108 | |||
109 | #[test] | ||
81 | fn item_map_using_self() { | 110 | fn item_map_using_self() { |
82 | let (item_map, module_id) = item_map( | 111 | let (item_map, module_id) = item_map( |
83 | " | 112 | " |
@@ -144,6 +173,59 @@ fn typing_inside_a_function_should_not_invalidate_item_map() { | |||
144 | let (mut db, pos) = MockDatabase::with_position( | 173 | let (mut db, pos) = MockDatabase::with_position( |
145 | " | 174 | " |
146 | //- /lib.rs | 175 | //- /lib.rs |
176 | mod foo; | ||
177 | |||
178 | use crate::foo::bar::Baz; | ||
179 | |||
180 | //- /foo/mod.rs | ||
181 | pub mod bar; | ||
182 | |||
183 | //- /foo/bar.rs | ||
184 | <|> | ||
185 | salsa::query_group! { | ||
186 | trait Baz { | ||
187 | fn foo() -> i32 { 1 + 1 } | ||
188 | } | ||
189 | } | ||
190 | ", | ||
191 | ); | ||
192 | let source_root = db.file_source_root(pos.file_id); | ||
193 | { | ||
194 | let events = db.log_executed(|| { | ||
195 | db.item_map(source_root).unwrap(); | ||
196 | }); | ||
197 | assert!(format!("{:?}", events).contains("item_map")) | ||
198 | } | ||
199 | |||
200 | let new_text = " | ||
201 | salsa::query_group! { | ||
202 | trait Baz { | ||
203 | fn foo() -> i32 { 92 } | ||
204 | } | ||
205 | } | ||
206 | " | ||
207 | .to_string(); | ||
208 | |||
209 | db.query_mut(ra_db::FileTextQuery) | ||
210 | .set(pos.file_id, Arc::new(new_text)); | ||
211 | |||
212 | { | ||
213 | let events = db.log_executed(|| { | ||
214 | db.item_map(source_root).unwrap(); | ||
215 | }); | ||
216 | assert!( | ||
217 | !format!("{:?}", events).contains("item_map"), | ||
218 | "{:#?}", | ||
219 | events | ||
220 | ) | ||
221 | } | ||
222 | } | ||
223 | |||
224 | #[test] | ||
225 | fn typing_inside_a_function_inside_a_macro_should_not_invalidate_item_map() { | ||
226 | let (mut db, pos) = MockDatabase::with_position( | ||
227 | " | ||
228 | //- /lib.rs | ||
147 | mod foo;<|> | 229 | mod foo;<|> |
148 | 230 | ||
149 | use crate::foo::bar::Baz; | 231 | use crate::foo::bar::Baz; |
@@ -183,7 +265,7 @@ fn typing_inside_a_function_should_not_invalidate_item_map() { | |||
183 | db.item_map(source_root).unwrap(); | 265 | db.item_map(source_root).unwrap(); |
184 | }); | 266 | }); |
185 | assert!( | 267 | assert!( |
186 | !format!("{:?}", events).contains("_item_map"), | 268 | !format!("{:?}", events).contains("item_map"), |
187 | "{:#?}", | 269 | "{:#?}", |
188 | events | 270 | events |
189 | ) | 271 | ) |