diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ide/src/hover.rs | 25 | ||||
-rw-r--r-- | crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs | 27 | ||||
-rw-r--r-- | crates/ide_db/src/helpers.rs | 11 | ||||
-rw-r--r-- | crates/ide_db/src/helpers/famous_defs_fixture.rs | 26 |
4 files changed, 36 insertions, 53 deletions
diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index e81bcf73e..409f81ca0 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs | |||
@@ -568,8 +568,6 @@ mod tests { | |||
568 | 568 | ||
569 | use crate::fixture; | 569 | use crate::fixture; |
570 | 570 | ||
571 | use super::*; | ||
572 | |||
573 | fn check_hover_no_result(ra_fixture: &str) { | 571 | fn check_hover_no_result(ra_fixture: &str) { |
574 | let (analysis, position) = fixture::position(ra_fixture); | 572 | let (analysis, position) = fixture::position(ra_fixture); |
575 | assert!(analysis.hover(position, true, true).unwrap().is_none()); | 573 | assert!(analysis.hover(position, true, true).unwrap().is_none()); |
@@ -3813,11 +3811,14 @@ use foo::bar::{self$0}; | |||
3813 | 3811 | ||
3814 | #[test] | 3812 | #[test] |
3815 | fn hover_keyword() { | 3813 | fn hover_keyword() { |
3816 | let ra_fixture = r#"//- /main.rs crate:main deps:std | ||
3817 | fn f() { retur$0n; }"#; | ||
3818 | let fixture = format!("{}\n{}", ra_fixture, FamousDefs::FIXTURE); | ||
3819 | check( | 3814 | check( |
3820 | &fixture, | 3815 | r#" |
3816 | //- /main.rs crate:main deps:std | ||
3817 | fn f() { retur$0n; } | ||
3818 | //- /libstd.rs crate:std | ||
3819 | /// Docs for return_keyword | ||
3820 | mod return_keyword {} | ||
3821 | "#, | ||
3821 | expect![[r#" | 3822 | expect![[r#" |
3822 | *return* | 3823 | *return* |
3823 | 3824 | ||
@@ -3834,11 +3835,15 @@ fn f() { retur$0n; }"#; | |||
3834 | 3835 | ||
3835 | #[test] | 3836 | #[test] |
3836 | fn hover_builtin() { | 3837 | fn hover_builtin() { |
3837 | let ra_fixture = r#"//- /main.rs crate:main deps:std | ||
3838 | cosnt _: &str$0 = ""; }"#; | ||
3839 | let fixture = format!("{}\n{}", ra_fixture, FamousDefs::FIXTURE); | ||
3840 | check( | 3838 | check( |
3841 | &fixture, | 3839 | r#" |
3840 | //- /main.rs crate:main deps:std | ||
3841 | cosnt _: &str$0 = ""; } | ||
3842 | |||
3843 | //- /libstd.rs crate:std | ||
3844 | /// Docs for prim_str | ||
3845 | mod prim_str {} | ||
3846 | "#, | ||
3842 | expect![[r#" | 3847 | expect![[r#" |
3843 | *str* | 3848 | *str* |
3844 | 3849 | ||
diff --git a/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs index d3ff7b65c..6c6ff16c2 100644 --- a/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs +++ b/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs | |||
@@ -48,6 +48,7 @@ pub(crate) fn extract_struct_from_enum_variant( | |||
48 | let variant_name = variant.name()?; | 48 | let variant_name = variant.name()?; |
49 | let variant_hir = ctx.sema.to_def(&variant)?; | 49 | let variant_hir = ctx.sema.to_def(&variant)?; |
50 | if existing_definition(ctx.db(), &variant_name, &variant_hir) { | 50 | if existing_definition(ctx.db(), &variant_name, &variant_hir) { |
51 | cov_mark::hit!(test_extract_enum_not_applicable_if_struct_exists); | ||
51 | return None; | 52 | return None; |
52 | } | 53 | } |
53 | 54 | ||
@@ -300,18 +301,10 @@ fn reference_to_node( | |||
300 | 301 | ||
301 | #[cfg(test)] | 302 | #[cfg(test)] |
302 | mod tests { | 303 | mod tests { |
303 | use ide_db::helpers::FamousDefs; | ||
304 | |||
305 | use crate::tests::{check_assist, check_assist_not_applicable}; | 304 | use crate::tests::{check_assist, check_assist_not_applicable}; |
306 | 305 | ||
307 | use super::*; | 306 | use super::*; |
308 | 307 | ||
309 | fn check_not_applicable(ra_fixture: &str) { | ||
310 | let fixture = | ||
311 | format!("//- /main.rs crate:main deps:core\n{}\n{}", ra_fixture, FamousDefs::FIXTURE); | ||
312 | check_assist_not_applicable(extract_struct_from_enum_variant, &fixture) | ||
313 | } | ||
314 | |||
315 | #[test] | 308 | #[test] |
316 | fn test_extract_struct_several_fields_tuple() { | 309 | fn test_extract_struct_several_fields_tuple() { |
317 | check_assist( | 310 | check_assist( |
@@ -699,29 +692,33 @@ fn foo() { | |||
699 | 692 | ||
700 | #[test] | 693 | #[test] |
701 | fn test_extract_enum_not_applicable_for_element_with_no_fields() { | 694 | fn test_extract_enum_not_applicable_for_element_with_no_fields() { |
702 | check_not_applicable("enum A { $0One }"); | 695 | check_assist_not_applicable(extract_struct_from_enum_variant, r#"enum A { $0One }"#); |
703 | } | 696 | } |
704 | 697 | ||
705 | #[test] | 698 | #[test] |
706 | fn test_extract_enum_not_applicable_if_struct_exists() { | 699 | fn test_extract_enum_not_applicable_if_struct_exists() { |
707 | check_not_applicable( | 700 | cov_mark::check!(test_extract_enum_not_applicable_if_struct_exists); |
708 | r#"struct One; | 701 | check_assist_not_applicable( |
709 | enum A { $0One(u8, u32) }"#, | 702 | extract_struct_from_enum_variant, |
703 | r#" | ||
704 | struct One; | ||
705 | enum A { $0One(u8, u32) } | ||
706 | "#, | ||
710 | ); | 707 | ); |
711 | } | 708 | } |
712 | 709 | ||
713 | #[test] | 710 | #[test] |
714 | fn test_extract_not_applicable_one_field() { | 711 | fn test_extract_not_applicable_one_field() { |
715 | check_not_applicable(r"enum A { $0One(u32) }"); | 712 | check_assist_not_applicable(extract_struct_from_enum_variant, r"enum A { $0One(u32) }"); |
716 | } | 713 | } |
717 | 714 | ||
718 | #[test] | 715 | #[test] |
719 | fn test_extract_not_applicable_no_field_tuple() { | 716 | fn test_extract_not_applicable_no_field_tuple() { |
720 | check_not_applicable(r"enum A { $0None() }"); | 717 | check_assist_not_applicable(extract_struct_from_enum_variant, r"enum A { $0None() }"); |
721 | } | 718 | } |
722 | 719 | ||
723 | #[test] | 720 | #[test] |
724 | fn test_extract_not_applicable_no_field_named() { | 721 | fn test_extract_not_applicable_no_field_named() { |
725 | check_not_applicable(r"enum A { $0None {} }"); | 722 | check_assist_not_applicable(extract_struct_from_enum_variant, r"enum A { $0None {} }"); |
726 | } | 723 | } |
727 | } | 724 | } |
diff --git a/crates/ide_db/src/helpers.rs b/crates/ide_db/src/helpers.rs index 00900cdc2..d96028cbc 100644 --- a/crates/ide_db/src/helpers.rs +++ b/crates/ide_db/src/helpers.rs | |||
@@ -74,12 +74,19 @@ pub fn visit_file_defs( | |||
74 | /// somewhat similar to the known paths infra inside hir, but it different; We | 74 | /// somewhat similar to the known paths infra inside hir, but it different; We |
75 | /// want to make sure that IDE specific paths don't become interesting inside | 75 | /// want to make sure that IDE specific paths don't become interesting inside |
76 | /// the compiler itself as well. | 76 | /// the compiler itself as well. |
77 | /// | ||
78 | /// Note that, by default, rust-analyzer tests **do not** include core or std | ||
79 | /// libraries. If you are writing tests for functionality using [`FamousDefs`], | ||
80 | /// you'd want to include [minicore](test_utils::MiniCore) declaration at the | ||
81 | /// start of your tests: | ||
82 | /// | ||
83 | /// ``` | ||
84 | /// //- minicore: iterator, ord, derive | ||
85 | /// ``` | ||
77 | pub struct FamousDefs<'a, 'b>(pub &'a Semantics<'b, RootDatabase>, pub Option<Crate>); | 86 | pub struct FamousDefs<'a, 'b>(pub &'a Semantics<'b, RootDatabase>, pub Option<Crate>); |
78 | 87 | ||
79 | #[allow(non_snake_case)] | 88 | #[allow(non_snake_case)] |
80 | impl FamousDefs<'_, '_> { | 89 | impl FamousDefs<'_, '_> { |
81 | pub const FIXTURE: &'static str = include_str!("helpers/famous_defs_fixture.rs"); | ||
82 | |||
83 | pub fn std(&self) -> Option<Crate> { | 90 | pub fn std(&self) -> Option<Crate> { |
84 | self.find_crate("std") | 91 | self.find_crate("std") |
85 | } | 92 | } |
diff --git a/crates/ide_db/src/helpers/famous_defs_fixture.rs b/crates/ide_db/src/helpers/famous_defs_fixture.rs deleted file mode 100644 index 6310fc0e1..000000000 --- a/crates/ide_db/src/helpers/famous_defs_fixture.rs +++ /dev/null | |||
@@ -1,26 +0,0 @@ | |||
1 | //- /libcore.rs crate:core | ||
2 | //! Signatures of traits, types and functions from the core lib for use in tests. | ||
3 | pub mod prelude { | ||
4 | pub mod rust_2018 { | ||
5 | pub use crate::{ | ||
6 | cmp::Ord, | ||
7 | convert::{From, Into}, | ||
8 | default::Default, | ||
9 | iter::{IntoIterator, Iterator}, | ||
10 | ops::{Fn, FnMut, FnOnce}, | ||
11 | option::Option::{self, *}, | ||
12 | }; | ||
13 | } | ||
14 | } | ||
15 | #[prelude_import] | ||
16 | pub use prelude::rust_2018::*; | ||
17 | //- /libstd.rs crate:std deps:core | ||
18 | //! Signatures of traits, types and functions from the std lib for use in tests. | ||
19 | |||
20 | /// Docs for return_keyword | ||
21 | mod return_keyword {} | ||
22 | |||
23 | /// Docs for prim_str | ||
24 | mod prim_str {} | ||
25 | |||
26 | pub use core::ops; | ||