diff options
author | Kirill Bulatov <[email protected]> | 2020-02-09 22:30:00 +0000 |
---|---|---|
committer | Kirill Bulatov <[email protected]> | 2020-02-12 15:18:41 +0000 |
commit | 2b9b16cb45c97424ea97a4959363cab4003f36e2 (patch) | |
tree | ae03ad13f9d051c7ab7ef1cd5db860ca3de271eb /crates/ra_assists/src/handlers | |
parent | 24ab3e80ca258a3db21bf263225c52d9995a2ea0 (diff) |
Add method tests
Diffstat (limited to 'crates/ra_assists/src/handlers')
-rw-r--r-- | crates/ra_assists/src/handlers/auto_import.rs | 119 |
1 files changed, 116 insertions, 3 deletions
diff --git a/crates/ra_assists/src/handlers/auto_import.rs b/crates/ra_assists/src/handlers/auto_import.rs index 10984d8ad..27d96b941 100644 --- a/crates/ra_assists/src/handlers/auto_import.rs +++ b/crates/ra_assists/src/handlers/auto_import.rs | |||
@@ -46,9 +46,9 @@ pub(crate) fn auto_import(ctx: AssistCtx) -> Option<Assist> { | |||
46 | 46 | ||
47 | let name_ref_to_import = | 47 | let name_ref_to_import = |
48 | path_under_caret.syntax().descendants().find_map(ast::NameRef::cast)?; | 48 | path_under_caret.syntax().descendants().find_map(ast::NameRef::cast)?; |
49 | if dbg!(source_analyzer | 49 | if source_analyzer |
50 | .resolve_path(ctx.db, &name_ref_to_import.syntax().ancestors().find_map(ast::Path::cast)?)) | 50 | .resolve_path(ctx.db, &name_ref_to_import.syntax().ancestors().find_map(ast::Path::cast)?) |
51 | .is_some() | 51 | .is_some() |
52 | { | 52 | { |
53 | return None; | 53 | return None; |
54 | } | 54 | } |
@@ -307,4 +307,117 @@ mod tests { | |||
307 | ", | 307 | ", |
308 | ); | 308 | ); |
309 | } | 309 | } |
310 | |||
311 | #[test] | ||
312 | fn associated_struct_function() { | ||
313 | check_assist( | ||
314 | auto_import, | ||
315 | r" | ||
316 | mod test_mod { | ||
317 | pub struct TestStruct {} | ||
318 | impl TestStruct { | ||
319 | pub fn test_function() {} | ||
320 | } | ||
321 | } | ||
322 | |||
323 | fn main() { | ||
324 | TestStruct::test_function<|> | ||
325 | } | ||
326 | ", | ||
327 | r" | ||
328 | use test_mod::TestStruct; | ||
329 | |||
330 | mod test_mod { | ||
331 | pub struct TestStruct {} | ||
332 | impl TestStruct { | ||
333 | pub fn test_function() {} | ||
334 | } | ||
335 | } | ||
336 | |||
337 | fn main() { | ||
338 | TestStruct::test_function<|> | ||
339 | } | ||
340 | ", | ||
341 | ); | ||
342 | } | ||
343 | |||
344 | #[test] | ||
345 | fn associated_trait_function() { | ||
346 | check_assist( | ||
347 | auto_import, | ||
348 | r" | ||
349 | mod test_mod { | ||
350 | pub trait TestTrait { | ||
351 | fn test_function(); | ||
352 | } | ||
353 | pub struct TestStruct {} | ||
354 | impl TestTrait for TestStruct { | ||
355 | fn test_function() {} | ||
356 | } | ||
357 | } | ||
358 | |||
359 | fn main() { | ||
360 | test_mod::TestStruct::test_function<|> | ||
361 | } | ||
362 | ", | ||
363 | r" | ||
364 | use test_mod::TestTrait; | ||
365 | |||
366 | mod test_mod { | ||
367 | pub trait TestTrait { | ||
368 | fn test_function(); | ||
369 | } | ||
370 | pub struct TestStruct {} | ||
371 | impl TestTrait for TestStruct { | ||
372 | fn test_function() {} | ||
373 | } | ||
374 | } | ||
375 | |||
376 | fn main() { | ||
377 | test_mod::TestStruct::test_function<|> | ||
378 | } | ||
379 | ", | ||
380 | ); | ||
381 | } | ||
382 | |||
383 | #[test] | ||
384 | fn trait_method() { | ||
385 | check_assist( | ||
386 | auto_import, | ||
387 | r" | ||
388 | mod test_mod { | ||
389 | pub trait TestTrait { | ||
390 | fn test_method(&self); | ||
391 | } | ||
392 | pub struct TestStruct {} | ||
393 | impl TestTrait for TestStruct { | ||
394 | fn test_method(&self) {} | ||
395 | } | ||
396 | } | ||
397 | |||
398 | fn main() { | ||
399 | let test_struct = test_mod::TestStruct {}; | ||
400 | test_struct.test_method<|> | ||
401 | } | ||
402 | ", | ||
403 | r" | ||
404 | use test_mod::TestTrait; | ||
405 | |||
406 | mod test_mod { | ||
407 | pub trait TestTrait { | ||
408 | fn test_method(&self); | ||
409 | } | ||
410 | pub struct TestStruct {} | ||
411 | impl TestTrait for TestStruct { | ||
412 | fn test_method(&self) {} | ||
413 | } | ||
414 | } | ||
415 | |||
416 | fn main() { | ||
417 | let test_struct = test_mod::TestStruct {}; | ||
418 | test_struct.test_method<|> | ||
419 | } | ||
420 | ", | ||
421 | ); | ||
422 | } | ||
310 | } | 423 | } |