Skip to content

Commit c387ab6

Browse files
bors[bot]matklad
andauthored
9320: internal: retire famous_defs_fixture r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2 parents 916384a + 66673ea commit c387ab6

File tree

4 files changed

+36
-53
lines changed

4 files changed

+36
-53
lines changed

crates/ide/src/hover.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,6 @@ mod tests {
568568

569569
use crate::fixture;
570570

571-
use super::*;
572-
573571
fn check_hover_no_result(ra_fixture: &str) {
574572
let (analysis, position) = fixture::position(ra_fixture);
575573
assert!(analysis.hover(position, true, true).unwrap().is_none());
@@ -3813,11 +3811,14 @@ use foo::bar::{self$0};
38133811

38143812
#[test]
38153813
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);
38193814
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+
"#,
38213822
expect![[r#"
38223823
*return*
38233824
@@ -3834,11 +3835,15 @@ fn f() { retur$0n; }"#;
38343835

38353836
#[test]
38363837
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);
38403838
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+
"#,
38423847
expect![[r#"
38433848
*str*
38443849

crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub(crate) fn extract_struct_from_enum_variant(
4848
let variant_name = variant.name()?;
4949
let variant_hir = ctx.sema.to_def(&variant)?;
5050
if existing_definition(ctx.db(), &variant_name, &variant_hir) {
51+
cov_mark::hit!(test_extract_enum_not_applicable_if_struct_exists);
5152
return None;
5253
}
5354

@@ -300,18 +301,10 @@ fn reference_to_node(
300301

301302
#[cfg(test)]
302303
mod tests {
303-
use ide_db::helpers::FamousDefs;
304-
305304
use crate::tests::{check_assist, check_assist_not_applicable};
306305

307306
use super::*;
308307

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-
315308
#[test]
316309
fn test_extract_struct_several_fields_tuple() {
317310
check_assist(
@@ -699,29 +692,33 @@ fn foo() {
699692

700693
#[test]
701694
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 }"#);
703696
}
704697

705698
#[test]
706699
fn test_extract_enum_not_applicable_if_struct_exists() {
707-
check_not_applicable(
708-
r#"struct One;
709-
enum A { $0One(u8, u32) }"#,
700+
cov_mark::check!(test_extract_enum_not_applicable_if_struct_exists);
701+
check_assist_not_applicable(
702+
extract_struct_from_enum_variant,
703+
r#"
704+
struct One;
705+
enum A { $0One(u8, u32) }
706+
"#,
710707
);
711708
}
712709

713710
#[test]
714711
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) }");
716713
}
717714

718715
#[test]
719716
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() }");
721718
}
722719

723720
#[test]
724721
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 {} }");
726723
}
727724
}

crates/ide_db/src/helpers.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,19 @@ pub fn visit_file_defs(
7474
/// somewhat similar to the known paths infra inside hir, but it different; We
7575
/// want to make sure that IDE specific paths don't become interesting inside
7676
/// 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+
/// ```
7786
pub struct FamousDefs<'a, 'b>(pub &'a Semantics<'b, RootDatabase>, pub Option<Crate>);
7887

7988
#[allow(non_snake_case)]
8089
impl FamousDefs<'_, '_> {
81-
pub const FIXTURE: &'static str = include_str!("helpers/famous_defs_fixture.rs");
82-
8390
pub fn std(&self) -> Option<Crate> {
8491
self.find_crate("std")
8592
}

crates/ide_db/src/helpers/famous_defs_fixture.rs

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)