diff options
Diffstat (limited to 'crates/ra_hir/src/nameres')
-rw-r--r-- | crates/ra_hir/src/nameres/tests.rs | 286 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres/tests/globs.rs | 76 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres/tests/macros.rs | 54 |
3 files changed, 204 insertions, 212 deletions
diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs index 572bd1bf7..14c8ee50b 100644 --- a/crates/ra_hir/src/nameres/tests.rs +++ b/crates/ra_hir/src/nameres/tests.rs | |||
@@ -8,7 +8,11 @@ use ra_db::SourceDatabase; | |||
8 | use test_utils::covers; | 8 | use test_utils::covers; |
9 | use insta::assert_snapshot_matches; | 9 | use insta::assert_snapshot_matches; |
10 | 10 | ||
11 | use crate::{Crate, mock::{MockDatabase, CrateGraphFixture}, nameres::Resolution}; | 11 | use crate::{ |
12 | Crate, | ||
13 | mock::{MockDatabase, CrateGraphFixture}, | ||
14 | nameres::Resolution, | ||
15 | }; | ||
12 | 16 | ||
13 | use super::*; | 17 | use super::*; |
14 | 18 | ||
@@ -25,12 +29,15 @@ fn compute_crate_def_map(fixture: &str, graph: Option<CrateGraphFixture>) -> Arc | |||
25 | fn render_crate_def_map(map: &CrateDefMap) -> String { | 29 | fn render_crate_def_map(map: &CrateDefMap) -> String { |
26 | let mut buf = String::new(); | 30 | let mut buf = String::new(); |
27 | go(&mut buf, map, "\ncrate", map.root); | 31 | go(&mut buf, map, "\ncrate", map.root); |
28 | return buf; | 32 | return buf.trim().to_string(); |
29 | 33 | ||
30 | fn go(buf: &mut String, map: &CrateDefMap, path: &str, module: CrateModuleId) { | 34 | fn go(buf: &mut String, map: &CrateDefMap, path: &str, module: CrateModuleId) { |
31 | *buf += path; | 35 | *buf += path; |
32 | *buf += "\n"; | 36 | *buf += "\n"; |
33 | for (name, res) in map.modules[module].scope.items.iter() { | 37 | |
38 | let mut entries = map.modules[module].scope.items.iter().collect::<Vec<_>>(); | ||
39 | entries.sort_by_key(|(name, _)| *name); | ||
40 | for (name, res) in entries { | ||
34 | *buf += &format!("{}: {}\n", name, dump_resolution(res)) | 41 | *buf += &format!("{}: {}\n", name, dump_resolution(res)) |
35 | } | 42 | } |
36 | for (name, child) in map.modules[module].children.iter() { | 43 | for (name, child) in map.modules[module].children.iter() { |
@@ -54,8 +61,8 @@ fn def_map(fixtute: &str) -> String { | |||
54 | render_crate_def_map(&dm) | 61 | render_crate_def_map(&dm) |
55 | } | 62 | } |
56 | 63 | ||
57 | fn def_map_with_crate_graph(fixtute: &str, graph: CrateGraphFixture) -> String { | 64 | fn def_map_with_crate_graph(fixture: &str, graph: CrateGraphFixture) -> String { |
58 | let dm = compute_crate_def_map(fixtute, Some(graph)); | 65 | let dm = compute_crate_def_map(fixture, Some(graph)); |
59 | render_crate_def_map(&dm) | 66 | render_crate_def_map(&dm) |
60 | } | 67 | } |
61 | 68 | ||
@@ -79,21 +86,20 @@ fn crate_def_map_smoke_test() { | |||
79 | ", | 86 | ", |
80 | ); | 87 | ); |
81 | assert_snapshot_matches!(map, @r###" | 88 | assert_snapshot_matches!(map, @r###" |
82 | crate | 89 | ⋮crate |
83 | V: t v | 90 | ⋮E: t |
84 | E: t | 91 | ⋮S: t v |
85 | foo: t | 92 | ⋮V: t v |
86 | S: t v | 93 | ⋮foo: t |
87 | 94 | ⋮ | |
88 | crate::foo | 95 | ⋮crate::foo |
89 | bar: t | 96 | ⋮bar: t |
90 | f: v | 97 | ⋮f: v |
91 | 98 | ⋮ | |
92 | crate::foo::bar | 99 | ⋮crate::foo::bar |
93 | Baz: t v | 100 | ⋮Baz: t v |
94 | E: t | 101 | ⋮E: t |
95 | "### | 102 | "###) |
96 | ) | ||
97 | } | 103 | } |
98 | 104 | ||
99 | #[test] | 105 | #[test] |
@@ -113,12 +119,12 @@ fn bogus_paths() { | |||
113 | ", | 119 | ", |
114 | ); | 120 | ); |
115 | assert_snapshot_matches!(map, @r###" | 121 | assert_snapshot_matches!(map, @r###" |
116 | crate | 122 | ⋮crate |
117 | foo: t | 123 | ⋮S: t v |
118 | S: t v | 124 | ⋮foo: t |
119 | 125 | ⋮ | |
120 | crate::foo | 126 | ⋮crate::foo |
121 | "### | 127 | "### |
122 | ) | 128 | ) |
123 | } | 129 | } |
124 | 130 | ||
@@ -137,13 +143,13 @@ fn use_as() { | |||
137 | ); | 143 | ); |
138 | assert_snapshot_matches!(map, | 144 | assert_snapshot_matches!(map, |
139 | @r###" | 145 | @r###" |
140 | crate | 146 | ⋮crate |
141 | Foo: t v | 147 | ⋮Foo: t v |
142 | foo: t | 148 | ⋮foo: t |
143 | 149 | ⋮ | |
144 | crate::foo | 150 | ⋮crate::foo |
145 | Baz: t v | 151 | ⋮Baz: t v |
146 | "### | 152 | "### |
147 | ); | 153 | ); |
148 | } | 154 | } |
149 | 155 | ||
@@ -164,21 +170,19 @@ fn use_trees() { | |||
164 | pub enum Quux {}; | 170 | pub enum Quux {}; |
165 | ", | 171 | ", |
166 | ); | 172 | ); |
167 | assert_snapshot_matches!(map, | 173 | assert_snapshot_matches!(map, @r###" |
168 | @r###" | 174 | ⋮crate |
169 | crate | 175 | ⋮Baz: t v |
170 | Quux: t | 176 | ⋮Quux: t |
171 | Baz: t v | 177 | ⋮foo: t |
172 | foo: t | 178 | ⋮ |
173 | 179 | ⋮crate::foo | |
174 | crate::foo | 180 | ⋮bar: t |
175 | bar: t | 181 | ⋮ |
176 | 182 | ⋮crate::foo::bar | |
177 | crate::foo::bar | 183 | ⋮Baz: t v |
178 | Quux: t | 184 | ⋮Quux: t |
179 | Baz: t v | 185 | "###); |
180 | "### | ||
181 | ); | ||
182 | } | 186 | } |
183 | 187 | ||
184 | #[test] | 188 | #[test] |
@@ -199,20 +203,18 @@ fn re_exports() { | |||
199 | pub struct Baz; | 203 | pub struct Baz; |
200 | ", | 204 | ", |
201 | ); | 205 | ); |
202 | assert_snapshot_matches!(map, | 206 | assert_snapshot_matches!(map, @r###" |
203 | @r###" | 207 | ⋮crate |
204 | crate | 208 | ⋮Baz: t v |
205 | Baz: t v | 209 | ⋮foo: t |
206 | foo: t | 210 | ⋮ |
207 | 211 | ⋮crate::foo | |
208 | crate::foo | 212 | ⋮Baz: t v |
209 | bar: t | 213 | ⋮bar: t |
210 | Baz: t v | 214 | ⋮ |
211 | 215 | ⋮crate::foo::bar | |
212 | crate::foo::bar | 216 | ⋮Baz: t v |
213 | Baz: t v | 217 | "###); |
214 | "### | ||
215 | ); | ||
216 | } | 218 | } |
217 | 219 | ||
218 | #[test] | 220 | #[test] |
@@ -237,10 +239,10 @@ fn std_prelude() { | |||
237 | }, | 239 | }, |
238 | ); | 240 | ); |
239 | assert_snapshot_matches!(map, @r###" | 241 | assert_snapshot_matches!(map, @r###" |
240 | crate | 242 | ⋮crate |
241 | Bar: t v | 243 | ⋮Bar: t v |
242 | Baz: t v | 244 | ⋮Baz: t v |
243 | "###); | 245 | "###); |
244 | } | 246 | } |
245 | 247 | ||
246 | #[test] | 248 | #[test] |
@@ -254,10 +256,10 @@ fn can_import_enum_variant() { | |||
254 | ", | 256 | ", |
255 | ); | 257 | ); |
256 | assert_snapshot_matches!(map, @r###" | 258 | assert_snapshot_matches!(map, @r###" |
257 | crate | 259 | ⋮crate |
258 | V: t v | 260 | ⋮E: t |
259 | E: t | 261 | ⋮V: t v |
260 | "### | 262 | "### |
261 | ); | 263 | ); |
262 | } | 264 | } |
263 | 265 | ||
@@ -285,20 +287,18 @@ fn edition_2015_imports() { | |||
285 | }, | 287 | }, |
286 | ); | 288 | ); |
287 | 289 | ||
288 | assert_snapshot_matches!(map, | 290 | assert_snapshot_matches!(map, @r###" |
289 | @r###" | 291 | ⋮crate |
290 | crate | 292 | ⋮bar: t |
291 | bar: t | 293 | ⋮foo: t |
292 | foo: t | 294 | ⋮ |
293 | 295 | ⋮crate::bar | |
294 | crate::bar | 296 | ⋮Bar: t v |
295 | Bar: t v | 297 | ⋮ |
296 | 298 | ⋮crate::foo | |
297 | crate::foo | 299 | ⋮Bar: t v |
298 | FromLib: t v | 300 | ⋮FromLib: t v |
299 | Bar: t v | 301 | "###); |
300 | "### | ||
301 | ); | ||
302 | } | 302 | } |
303 | 303 | ||
304 | #[test] | 304 | #[test] |
@@ -317,16 +317,14 @@ fn module_resolution_works_for_non_standard_filenames() { | |||
317 | }, | 317 | }, |
318 | ); | 318 | ); |
319 | 319 | ||
320 | assert_snapshot_matches!(map, | 320 | assert_snapshot_matches!(map, @r###" |
321 | @r###" | 321 | ⋮crate |
322 | crate | 322 | ⋮Bar: t v |
323 | Bar: t v | 323 | ⋮foo: t |
324 | foo: t | 324 | ⋮ |
325 | 325 | ⋮crate::foo | |
326 | crate::foo | 326 | ⋮Bar: t v |
327 | Bar: t v | 327 | "###); |
328 | "### | ||
329 | ); | ||
330 | } | 328 | } |
331 | 329 | ||
332 | #[test] | 330 | #[test] |
@@ -348,12 +346,10 @@ fn name_res_works_for_broken_modules() { | |||
348 | pub struct Baz; | 346 | pub struct Baz; |
349 | ", | 347 | ", |
350 | ); | 348 | ); |
351 | assert_snapshot_matches!(map, | 349 | assert_snapshot_matches!(map, @r###" |
352 | @r###" | 350 | ⋮crate |
353 | crate | 351 | ⋮Baz: _ |
354 | Baz: _ | 352 | "###); |
355 | "### | ||
356 | ); | ||
357 | } | 353 | } |
358 | 354 | ||
359 | #[test] | 355 | #[test] |
@@ -369,19 +365,17 @@ fn item_map_using_self() { | |||
369 | pub struct Baz; | 365 | pub struct Baz; |
370 | ", | 366 | ", |
371 | ); | 367 | ); |
372 | assert_snapshot_matches!(map, | 368 | assert_snapshot_matches!(map, @r###" |
373 | @r###" | 369 | ⋮crate |
374 | crate | 370 | ⋮Baz: t v |
375 | Baz: t v | 371 | ⋮foo: t |
376 | foo: t | 372 | ⋮ |
377 | 373 | ⋮crate::foo | |
378 | crate::foo | 374 | ⋮bar: t |
379 | bar: t | 375 | ⋮ |
380 | 376 | ⋮crate::foo::bar | |
381 | crate::foo::bar | 377 | ⋮Baz: t v |
382 | Baz: t v | 378 | "###); |
383 | "### | ||
384 | ); | ||
385 | } | 379 | } |
386 | 380 | ||
387 | #[test] | 381 | #[test] |
@@ -400,12 +394,10 @@ fn item_map_across_crates() { | |||
400 | }, | 394 | }, |
401 | ); | 395 | ); |
402 | 396 | ||
403 | assert_snapshot_matches!(map, | 397 | assert_snapshot_matches!(map, @r###" |
404 | @r###" | 398 | ⋮crate |
405 | crate | 399 | ⋮Baz: t v |
406 | Baz: t v | 400 | "###); |
407 | "### | ||
408 | ); | ||
409 | } | 401 | } |
410 | 402 | ||
411 | #[test] | 403 | #[test] |
@@ -430,12 +422,14 @@ fn extern_crate_rename() { | |||
430 | }, | 422 | }, |
431 | ); | 423 | ); |
432 | 424 | ||
433 | assert_snapshot_matches!(map, | 425 | assert_snapshot_matches!(map, @r###" |
434 | @r###" | 426 | ⋮crate |
435 | crate | 427 | ⋮alloc_crate: t |
436 | Arc: t v | 428 | ⋮sync: t |
437 | "### | 429 | ⋮ |
438 | ); | 430 | ⋮crate::sync |
431 | ⋮Arc: t v | ||
432 | "###); | ||
439 | } | 433 | } |
440 | 434 | ||
441 | #[test] | 435 | #[test] |
@@ -462,9 +456,13 @@ fn extern_crate_rename_2015_edition() { | |||
462 | 456 | ||
463 | assert_snapshot_matches!(map, | 457 | assert_snapshot_matches!(map, |
464 | @r###" | 458 | @r###" |
465 | crate | 459 | ⋮crate |
466 | Arc: t v | 460 | ⋮alloc_crate: t |
467 | "### | 461 | ⋮sync: t |
462 | ⋮ | ||
463 | ⋮crate::sync | ||
464 | ⋮Arc: t v | ||
465 | "### | ||
468 | ); | 466 | ); |
469 | } | 467 | } |
470 | 468 | ||
@@ -490,12 +488,10 @@ fn import_across_source_roots() { | |||
490 | }, | 488 | }, |
491 | ); | 489 | ); |
492 | 490 | ||
493 | assert_snapshot_matches!(map, | 491 | assert_snapshot_matches!(map, @r###" |
494 | @r###" | 492 | ⋮crate |
495 | crate | 493 | ⋮C: t v |
496 | C: t v | 494 | "###); |
497 | "### | ||
498 | ); | ||
499 | } | 495 | } |
500 | 496 | ||
501 | #[test] | 497 | #[test] |
@@ -519,12 +515,10 @@ fn reexport_across_crates() { | |||
519 | }, | 515 | }, |
520 | ); | 516 | ); |
521 | 517 | ||
522 | assert_snapshot_matches!(map, | 518 | assert_snapshot_matches!(map, @r###" |
523 | @r###" | 519 | ⋮crate |
524 | crate | 520 | ⋮Baz: t v |
525 | Baz: t v | 521 | "###); |
526 | "### | ||
527 | ); | ||
528 | } | 522 | } |
529 | 523 | ||
530 | #[test] | 524 | #[test] |
@@ -544,13 +538,11 @@ fn values_dont_shadow_extern_crates() { | |||
544 | }, | 538 | }, |
545 | ); | 539 | ); |
546 | 540 | ||
547 | assert_snapshot_matches!(map, | 541 | assert_snapshot_matches!(map, @r###" |
548 | @r###" | 542 | ⋮crate |
549 | crate | 543 | ⋮Bar: t v |
550 | Bar: t v | 544 | ⋮foo: v |
551 | foo: v | 545 | "###); |
552 | "### | ||
553 | ); | ||
554 | } | 546 | } |
555 | 547 | ||
556 | #[test] | 548 | #[test] |
diff --git a/crates/ra_hir/src/nameres/tests/globs.rs b/crates/ra_hir/src/nameres/tests/globs.rs index 6e50c7ff6..e1519ca6b 100644 --- a/crates/ra_hir/src/nameres/tests/globs.rs +++ b/crates/ra_hir/src/nameres/tests/globs.rs | |||
@@ -18,20 +18,20 @@ fn glob_1() { | |||
18 | ", | 18 | ", |
19 | ); | 19 | ); |
20 | assert_snapshot_matches!(map, @r###" | 20 | assert_snapshot_matches!(map, @r###" |
21 | crate | 21 | ⋮crate |
22 | bar: t | 22 | ⋮Baz: t v |
23 | Foo: t v | 23 | ⋮Foo: t v |
24 | Baz: t v | 24 | ⋮bar: t |
25 | foo: t | 25 | ⋮foo: t |
26 | 26 | ⋮ | |
27 | crate::foo | 27 | ⋮crate::foo |
28 | bar: t | 28 | ⋮Baz: t v |
29 | Foo: t v | 29 | ⋮Foo: t v |
30 | Baz: t v | 30 | ⋮bar: t |
31 | 31 | ⋮ | |
32 | crate::foo::bar | 32 | ⋮crate::foo::bar |
33 | Baz: t v | 33 | ⋮Baz: t v |
34 | "### | 34 | "### |
35 | ); | 35 | ); |
36 | } | 36 | } |
37 | 37 | ||
@@ -54,22 +54,22 @@ fn glob_2() { | |||
54 | ", | 54 | ", |
55 | ); | 55 | ); |
56 | assert_snapshot_matches!(map, @r###" | 56 | assert_snapshot_matches!(map, @r###" |
57 | crate | 57 | ⋮crate |
58 | bar: t | 58 | ⋮Baz: t v |
59 | Foo: t v | 59 | ⋮Foo: t v |
60 | Baz: t v | 60 | ⋮bar: t |
61 | foo: t | 61 | ⋮foo: t |
62 | 62 | ⋮ | |
63 | crate::foo | 63 | ⋮crate::foo |
64 | bar: t | 64 | ⋮Baz: t v |
65 | Foo: t v | 65 | ⋮Foo: t v |
66 | Baz: t v | 66 | ⋮bar: t |
67 | 67 | ⋮ | |
68 | crate::foo::bar | 68 | ⋮crate::foo::bar |
69 | bar: t | 69 | ⋮Baz: t v |
70 | Foo: t v | 70 | ⋮Foo: t v |
71 | Baz: t v | 71 | ⋮bar: t |
72 | "### | 72 | "### |
73 | ); | 73 | ); |
74 | } | 74 | } |
75 | 75 | ||
@@ -90,9 +90,9 @@ fn glob_across_crates() { | |||
90 | }, | 90 | }, |
91 | ); | 91 | ); |
92 | assert_snapshot_matches!(map, @r###" | 92 | assert_snapshot_matches!(map, @r###" |
93 | crate | 93 | ⋮crate |
94 | Baz: t v | 94 | ⋮Baz: t v |
95 | "### | 95 | "### |
96 | ); | 96 | ); |
97 | } | 97 | } |
98 | 98 | ||
@@ -109,10 +109,10 @@ fn glob_enum() { | |||
109 | ", | 109 | ", |
110 | ); | 110 | ); |
111 | assert_snapshot_matches!(map, @r###" | 111 | assert_snapshot_matches!(map, @r###" |
112 | crate | 112 | ⋮crate |
113 | Foo: t | 113 | ⋮Bar: t v |
114 | Bar: t v | 114 | ⋮Baz: t v |
115 | Baz: t v | 115 | ⋮Foo: t |
116 | "### | 116 | "### |
117 | ); | 117 | ); |
118 | } | 118 | } |
diff --git a/crates/ra_hir/src/nameres/tests/macros.rs b/crates/ra_hir/src/nameres/tests/macros.rs index 8781b026b..f7ca380ad 100644 --- a/crates/ra_hir/src/nameres/tests/macros.rs +++ b/crates/ra_hir/src/nameres/tests/macros.rs | |||
@@ -18,14 +18,14 @@ fn macro_rules_are_globally_visible() { | |||
18 | ", | 18 | ", |
19 | ); | 19 | ); |
20 | assert_snapshot_matches!(map, @r###" | 20 | assert_snapshot_matches!(map, @r###" |
21 | crate | 21 | ⋮crate |
22 | nested: t | 22 | ⋮Foo: t v |
23 | Foo: t v | 23 | ⋮nested: t |
24 | 24 | ⋮ | |
25 | crate::nested | 25 | ⋮crate::nested |
26 | Bar: t v | 26 | ⋮Bar: t v |
27 | Baz: t v | 27 | ⋮Baz: t v |
28 | "###); | 28 | "###); |
29 | } | 29 | } |
30 | 30 | ||
31 | #[test] | 31 | #[test] |
@@ -45,15 +45,15 @@ fn macro_rules_can_define_modules() { | |||
45 | ", | 45 | ", |
46 | ); | 46 | ); |
47 | assert_snapshot_matches!(map, @r###" | 47 | assert_snapshot_matches!(map, @r###" |
48 | crate | 48 | ⋮crate |
49 | n1: t | 49 | ⋮n1: t |
50 | 50 | ⋮ | |
51 | crate::n1 | 51 | ⋮crate::n1 |
52 | n2: t | 52 | ⋮n2: t |
53 | 53 | ⋮ | |
54 | crate::n1::n2 | 54 | ⋮crate::n1::n2 |
55 | X: t v | 55 | ⋮X: t v |
56 | "###); | 56 | "###); |
57 | } | 57 | } |
58 | 58 | ||
59 | #[test] | 59 | #[test] |
@@ -81,14 +81,14 @@ fn macro_rules_from_other_crates_are_visible() { | |||
81 | }, | 81 | }, |
82 | ); | 82 | ); |
83 | assert_snapshot_matches!(map, @r###" | 83 | assert_snapshot_matches!(map, @r###" |
84 | crate | 84 | ⋮crate |
85 | bar: t | 85 | ⋮Bar: t v |
86 | Foo: t v | 86 | ⋮Foo: t v |
87 | Bar: t v | 87 | ⋮bar: t |
88 | 88 | ⋮ | |
89 | crate::bar | 89 | ⋮crate::bar |
90 | bar: t | 90 | ⋮Bar: t v |
91 | Foo: t v | 91 | ⋮Foo: t v |
92 | Bar: t v | 92 | ⋮bar: t |
93 | "###); | 93 | "###); |
94 | } | 94 | } |