mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-22 12:43:36 +00:00
Merge #9320
9320: internal: retire famous_defs_fixture r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
c387ab6de1
@ -568,8 +568,6 @@ mod tests {
|
||||
|
||||
use crate::fixture;
|
||||
|
||||
use super::*;
|
||||
|
||||
fn check_hover_no_result(ra_fixture: &str) {
|
||||
let (analysis, position) = fixture::position(ra_fixture);
|
||||
assert!(analysis.hover(position, true, true).unwrap().is_none());
|
||||
@ -3813,11 +3811,14 @@ use foo::bar::{self$0};
|
||||
|
||||
#[test]
|
||||
fn hover_keyword() {
|
||||
let ra_fixture = r#"//- /main.rs crate:main deps:std
|
||||
fn f() { retur$0n; }"#;
|
||||
let fixture = format!("{}\n{}", ra_fixture, FamousDefs::FIXTURE);
|
||||
check(
|
||||
&fixture,
|
||||
r#"
|
||||
//- /main.rs crate:main deps:std
|
||||
fn f() { retur$0n; }
|
||||
//- /libstd.rs crate:std
|
||||
/// Docs for return_keyword
|
||||
mod return_keyword {}
|
||||
"#,
|
||||
expect![[r#"
|
||||
*return*
|
||||
|
||||
@ -3834,11 +3835,15 @@ fn f() { retur$0n; }"#;
|
||||
|
||||
#[test]
|
||||
fn hover_builtin() {
|
||||
let ra_fixture = r#"//- /main.rs crate:main deps:std
|
||||
cosnt _: &str$0 = ""; }"#;
|
||||
let fixture = format!("{}\n{}", ra_fixture, FamousDefs::FIXTURE);
|
||||
check(
|
||||
&fixture,
|
||||
r#"
|
||||
//- /main.rs crate:main deps:std
|
||||
cosnt _: &str$0 = ""; }
|
||||
|
||||
//- /libstd.rs crate:std
|
||||
/// Docs for prim_str
|
||||
mod prim_str {}
|
||||
"#,
|
||||
expect![[r#"
|
||||
*str*
|
||||
|
||||
|
@ -48,6 +48,7 @@ pub(crate) fn extract_struct_from_enum_variant(
|
||||
let variant_name = variant.name()?;
|
||||
let variant_hir = ctx.sema.to_def(&variant)?;
|
||||
if existing_definition(ctx.db(), &variant_name, &variant_hir) {
|
||||
cov_mark::hit!(test_extract_enum_not_applicable_if_struct_exists);
|
||||
return None;
|
||||
}
|
||||
|
||||
@ -300,18 +301,10 @@ fn reference_to_node(
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use ide_db::helpers::FamousDefs;
|
||||
|
||||
use crate::tests::{check_assist, check_assist_not_applicable};
|
||||
|
||||
use super::*;
|
||||
|
||||
fn check_not_applicable(ra_fixture: &str) {
|
||||
let fixture =
|
||||
format!("//- /main.rs crate:main deps:core\n{}\n{}", ra_fixture, FamousDefs::FIXTURE);
|
||||
check_assist_not_applicable(extract_struct_from_enum_variant, &fixture)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_struct_several_fields_tuple() {
|
||||
check_assist(
|
||||
@ -699,29 +692,33 @@ fn foo() {
|
||||
|
||||
#[test]
|
||||
fn test_extract_enum_not_applicable_for_element_with_no_fields() {
|
||||
check_not_applicable("enum A { $0One }");
|
||||
check_assist_not_applicable(extract_struct_from_enum_variant, r#"enum A { $0One }"#);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_enum_not_applicable_if_struct_exists() {
|
||||
check_not_applicable(
|
||||
r#"struct One;
|
||||
enum A { $0One(u8, u32) }"#,
|
||||
cov_mark::check!(test_extract_enum_not_applicable_if_struct_exists);
|
||||
check_assist_not_applicable(
|
||||
extract_struct_from_enum_variant,
|
||||
r#"
|
||||
struct One;
|
||||
enum A { $0One(u8, u32) }
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_not_applicable_one_field() {
|
||||
check_not_applicable(r"enum A { $0One(u32) }");
|
||||
check_assist_not_applicable(extract_struct_from_enum_variant, r"enum A { $0One(u32) }");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_not_applicable_no_field_tuple() {
|
||||
check_not_applicable(r"enum A { $0None() }");
|
||||
check_assist_not_applicable(extract_struct_from_enum_variant, r"enum A { $0None() }");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_not_applicable_no_field_named() {
|
||||
check_not_applicable(r"enum A { $0None {} }");
|
||||
check_assist_not_applicable(extract_struct_from_enum_variant, r"enum A { $0None {} }");
|
||||
}
|
||||
}
|
||||
|
@ -74,12 +74,19 @@ pub fn visit_file_defs(
|
||||
/// somewhat similar to the known paths infra inside hir, but it different; We
|
||||
/// want to make sure that IDE specific paths don't become interesting inside
|
||||
/// the compiler itself as well.
|
||||
///
|
||||
/// Note that, by default, rust-analyzer tests **do not** include core or std
|
||||
/// libraries. If you are writing tests for functionality using [`FamousDefs`],
|
||||
/// you'd want to include [minicore](test_utils::MiniCore) declaration at the
|
||||
/// start of your tests:
|
||||
///
|
||||
/// ```
|
||||
/// //- minicore: iterator, ord, derive
|
||||
/// ```
|
||||
pub struct FamousDefs<'a, 'b>(pub &'a Semantics<'b, RootDatabase>, pub Option<Crate>);
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
impl FamousDefs<'_, '_> {
|
||||
pub const FIXTURE: &'static str = include_str!("helpers/famous_defs_fixture.rs");
|
||||
|
||||
pub fn std(&self) -> Option<Crate> {
|
||||
self.find_crate("std")
|
||||
}
|
||||
|
@ -1,26 +0,0 @@
|
||||
//- /libcore.rs crate:core
|
||||
//! Signatures of traits, types and functions from the core lib for use in tests.
|
||||
pub mod prelude {
|
||||
pub mod rust_2018 {
|
||||
pub use crate::{
|
||||
cmp::Ord,
|
||||
convert::{From, Into},
|
||||
default::Default,
|
||||
iter::{IntoIterator, Iterator},
|
||||
ops::{Fn, FnMut, FnOnce},
|
||||
option::Option::{self, *},
|
||||
};
|
||||
}
|
||||
}
|
||||
#[prelude_import]
|
||||
pub use prelude::rust_2018::*;
|
||||
//- /libstd.rs crate:std deps:core
|
||||
//! Signatures of traits, types and functions from the std lib for use in tests.
|
||||
|
||||
/// Docs for return_keyword
|
||||
mod return_keyword {}
|
||||
|
||||
/// Docs for prim_str
|
||||
mod prim_str {}
|
||||
|
||||
pub use core::ops;
|
Loading…
Reference in New Issue
Block a user