mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
Lift out base item fixture for ide_completion tests
This commit is contained in:
parent
9239943b84
commit
dc4876d33d
6 changed files with 68 additions and 73 deletions
|
@ -9,6 +9,7 @@ mod use_tree;
|
||||||
mod items;
|
mod items;
|
||||||
mod pattern;
|
mod pattern;
|
||||||
mod type_pos;
|
mod type_pos;
|
||||||
|
mod where_clause;
|
||||||
|
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
|
@ -28,6 +29,21 @@ use test_utils::assert_eq_text;
|
||||||
|
|
||||||
use crate::{item::CompletionKind, CompletionConfig, CompletionItem};
|
use crate::{item::CompletionKind, CompletionConfig, CompletionItem};
|
||||||
|
|
||||||
|
/// Lots of basic item definitions
|
||||||
|
const BASE_FIXTURE: &str = r#"
|
||||||
|
enum Enum { TupleV(u32), RecordV { field: u32 }, UnitV }
|
||||||
|
use self::Enum::TupleV;
|
||||||
|
mod module {}
|
||||||
|
|
||||||
|
trait Trait {}
|
||||||
|
static STATIC: Unit = Unit;
|
||||||
|
const CONST: Unit = Unit;
|
||||||
|
struct Record { field: u32 }
|
||||||
|
struct Tuple(u32);
|
||||||
|
struct Unit
|
||||||
|
macro_rules! makro {}
|
||||||
|
"#;
|
||||||
|
|
||||||
pub(crate) const TEST_CONFIG: CompletionConfig = CompletionConfig {
|
pub(crate) const TEST_CONFIG: CompletionConfig = CompletionConfig {
|
||||||
enable_postfix_completions: true,
|
enable_postfix_completions: true,
|
||||||
enable_imports_on_the_fly: true,
|
enable_imports_on_the_fly: true,
|
||||||
|
|
|
@ -1,19 +1,9 @@
|
||||||
use expect_test::{expect, Expect};
|
use expect_test::{expect, Expect};
|
||||||
|
|
||||||
use crate::tests::completion_list;
|
use crate::tests::{completion_list, BASE_FIXTURE};
|
||||||
|
|
||||||
fn check(ra_fixture: &str, expect: Expect) {
|
fn check(ra_fixture: &str, expect: Expect) {
|
||||||
let base = r#"#[rustc_builtin_macro]
|
let actual = completion_list(&format!("{}{}", BASE_FIXTURE, ra_fixture));
|
||||||
pub macro Clone {}
|
|
||||||
enum Enum { Variant }
|
|
||||||
struct Struct {}
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! foo {}
|
|
||||||
mod bar {}
|
|
||||||
const CONST: () = ();
|
|
||||||
trait Trait {}
|
|
||||||
"#;
|
|
||||||
let actual = completion_list(&format!("{}{}", base, ra_fixture));
|
|
||||||
expect.assert_eq(&actual)
|
expect.assert_eq(&actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +11,7 @@ trait Trait {}
|
||||||
fn in_mod_item_list() {
|
fn in_mod_item_list() {
|
||||||
check(
|
check(
|
||||||
r#"mod tests { $0 }"#,
|
r#"mod tests { $0 }"#,
|
||||||
expect![[r##"
|
expect![[r#"
|
||||||
kw pub(crate)
|
kw pub(crate)
|
||||||
kw pub
|
kw pub
|
||||||
kw unsafe
|
kw unsafe
|
||||||
|
@ -40,8 +30,8 @@ fn in_mod_item_list() {
|
||||||
sn tmod (Test module)
|
sn tmod (Test module)
|
||||||
sn tfn (Test function)
|
sn tfn (Test function)
|
||||||
sn macro_rules
|
sn macro_rules
|
||||||
ma foo!(…) #[macro_export] macro_rules! foo
|
ma makro!(…) macro_rules! makro
|
||||||
"##]],
|
"#]],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +39,7 @@ fn in_mod_item_list() {
|
||||||
fn in_source_file_item_list() {
|
fn in_source_file_item_list() {
|
||||||
check(
|
check(
|
||||||
r#"$0"#,
|
r#"$0"#,
|
||||||
expect![[r##"
|
expect![[r#"
|
||||||
kw pub(crate)
|
kw pub(crate)
|
||||||
kw pub
|
kw pub
|
||||||
kw unsafe
|
kw unsafe
|
||||||
|
@ -68,10 +58,9 @@ fn in_source_file_item_list() {
|
||||||
sn tmod (Test module)
|
sn tmod (Test module)
|
||||||
sn tfn (Test function)
|
sn tfn (Test function)
|
||||||
sn macro_rules
|
sn macro_rules
|
||||||
md bar
|
md module
|
||||||
ma foo!(…) #[macro_export] macro_rules! foo
|
ma makro!(…) macro_rules! makro
|
||||||
ma foo!(…) #[macro_export] macro_rules! foo
|
"#]],
|
||||||
"##]],
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +95,7 @@ fn in_item_list_after_attr() {
|
||||||
fn in_qualified_path() {
|
fn in_qualified_path() {
|
||||||
check(
|
check(
|
||||||
r#"crate::$0"#,
|
r#"crate::$0"#,
|
||||||
expect![[r##"
|
expect![[r#"
|
||||||
kw pub(crate)
|
kw pub(crate)
|
||||||
kw pub
|
kw pub
|
||||||
kw unsafe
|
kw unsafe
|
||||||
|
@ -122,9 +111,8 @@ fn in_qualified_path() {
|
||||||
kw enum
|
kw enum
|
||||||
kw struct
|
kw struct
|
||||||
kw union
|
kw union
|
||||||
md bar
|
md module
|
||||||
ma foo!(…) #[macro_export] macro_rules! foo
|
"#]],
|
||||||
"##]],
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,17 +165,16 @@ fn after_visibility_unsafe() {
|
||||||
fn in_impl_assoc_item_list() {
|
fn in_impl_assoc_item_list() {
|
||||||
check(
|
check(
|
||||||
r#"impl Struct { $0 }"#,
|
r#"impl Struct { $0 }"#,
|
||||||
expect![[r##"
|
expect![[r#"
|
||||||
kw pub(crate)
|
kw pub(crate)
|
||||||
kw pub
|
kw pub
|
||||||
kw unsafe
|
kw unsafe
|
||||||
kw fn
|
kw fn
|
||||||
kw const
|
kw const
|
||||||
kw type
|
kw type
|
||||||
md bar
|
md module
|
||||||
ma foo!(…) #[macro_export] macro_rules! foo
|
ma makro!(…) macro_rules! makro
|
||||||
ma foo!(…) #[macro_export] macro_rules! foo
|
"#]],
|
||||||
"##]],
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,14 +197,13 @@ fn in_impl_assoc_item_list_after_attr() {
|
||||||
fn in_trait_assoc_item_list() {
|
fn in_trait_assoc_item_list() {
|
||||||
check(
|
check(
|
||||||
r"trait Foo { $0 }",
|
r"trait Foo { $0 }",
|
||||||
expect![[r##"
|
expect![[r#"
|
||||||
kw unsafe
|
kw unsafe
|
||||||
kw fn
|
kw fn
|
||||||
kw const
|
kw const
|
||||||
kw type
|
kw type
|
||||||
md bar
|
md module
|
||||||
ma foo!(…) #[macro_export] macro_rules! foo
|
ma makro!(…) macro_rules! makro
|
||||||
ma foo!(…) #[macro_export] macro_rules! foo
|
"#]],
|
||||||
"##]],
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,20 +4,10 @@
|
||||||
//! in [crate::completions::mod_].
|
//! in [crate::completions::mod_].
|
||||||
use expect_test::{expect, Expect};
|
use expect_test::{expect, Expect};
|
||||||
|
|
||||||
use crate::tests::completion_list;
|
use crate::tests::{completion_list, BASE_FIXTURE};
|
||||||
|
|
||||||
fn check(ra_fixture: &str, expect: Expect) {
|
fn check(ra_fixture: &str, expect: Expect) {
|
||||||
let base = r#"#[rustc_builtin_macro]
|
let actual = completion_list(&format!("{}{}", BASE_FIXTURE, ra_fixture));
|
||||||
pub macro Clone {}
|
|
||||||
enum Enum { Variant }
|
|
||||||
struct Struct {}
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! foo {}
|
|
||||||
mod bar {}
|
|
||||||
const CONST: () = ();
|
|
||||||
trait Trait {}
|
|
||||||
"#;
|
|
||||||
let actual = completion_list(&format!("{}{}", base, ra_fixture));
|
|
||||||
expect.assert_eq(&actual)
|
expect.assert_eq(&actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,15 +17,16 @@ fn target_type_or_trait_in_impl_block() {
|
||||||
r#"
|
r#"
|
||||||
impl Tra$0
|
impl Tra$0
|
||||||
"#,
|
"#,
|
||||||
expect![[r##"
|
expect![[r#"
|
||||||
tt Trait
|
tt Trait
|
||||||
en Enum
|
en Enum
|
||||||
st Struct
|
st Record
|
||||||
md bar
|
st Tuple
|
||||||
ma foo!(…) #[macro_export] macro_rules! foo
|
md module
|
||||||
ma foo!(…) #[macro_export] macro_rules! foo
|
st Unit
|
||||||
|
ma makro!(…) macro_rules! makro
|
||||||
bt u32
|
bt u32
|
||||||
"##]],
|
"#]],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,15 +36,16 @@ fn target_type_in_trait_impl_block() {
|
||||||
r#"
|
r#"
|
||||||
impl Trait for Str$0
|
impl Trait for Str$0
|
||||||
"#,
|
"#,
|
||||||
expect![[r##"
|
expect![[r#"
|
||||||
tt Trait
|
tt Trait
|
||||||
en Enum
|
en Enum
|
||||||
st Struct
|
st Record
|
||||||
md bar
|
st Tuple
|
||||||
ma foo!(…) #[macro_export] macro_rules! foo
|
md module
|
||||||
ma foo!(…) #[macro_export] macro_rules! foo
|
st Unit
|
||||||
|
ma makro!(…) macro_rules! makro
|
||||||
bt u32
|
bt u32
|
||||||
"##]],
|
"#]],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//! Completions tests for pattern position.
|
//! Completions tests for pattern position.
|
||||||
use expect_test::{expect, Expect};
|
use expect_test::{expect, Expect};
|
||||||
|
|
||||||
use crate::tests::completion_list;
|
use crate::tests::{completion_list, BASE_FIXTURE};
|
||||||
|
|
||||||
fn check(ra_fixture: &str, expect: Expect) {
|
fn check(ra_fixture: &str, expect: Expect) {
|
||||||
let actual = completion_list(ra_fixture);
|
let actual = completion_list(ra_fixture);
|
||||||
|
@ -9,19 +9,7 @@ fn check(ra_fixture: &str, expect: Expect) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_with(ra_fixture: &str, expect: Expect) {
|
fn check_with(ra_fixture: &str, expect: Expect) {
|
||||||
let base = r#"
|
let actual = completion_list(&format!("{}\n{}", BASE_FIXTURE, ra_fixture));
|
||||||
enum Enum { TupleV(u32), RecordV { field: u32 }, UnitV }
|
|
||||||
use self::Enum::TupleV;
|
|
||||||
mod module {}
|
|
||||||
|
|
||||||
static STATIC: Unit = Unit;
|
|
||||||
const CONST: Unit = Unit;
|
|
||||||
struct Record { field: u32 }
|
|
||||||
struct Tuple(u32);
|
|
||||||
struct Unit
|
|
||||||
macro_rules! makro {}
|
|
||||||
"#;
|
|
||||||
let actual = completion_list(&format!("{}\n{}", base, ra_fixture));
|
|
||||||
expect.assert_eq(&actual)
|
expect.assert_eq(&actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,9 +111,9 @@ fn foo() {
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
kw mut
|
kw mut
|
||||||
|
en Enum
|
||||||
bn Record Record { field$1 }$0
|
bn Record Record { field$1 }$0
|
||||||
st Record
|
st Record
|
||||||
en Enum
|
|
||||||
bn Tuple Tuple($1)$0
|
bn Tuple Tuple($1)$0
|
||||||
st Tuple
|
st Tuple
|
||||||
md module
|
md module
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
//! Completions tests for use trees.
|
||||||
use expect_test::{expect, Expect};
|
use expect_test::{expect, Expect};
|
||||||
|
|
||||||
use crate::tests::completion_list;
|
use crate::tests::completion_list;
|
||||||
|
|
12
crates/ide_completion/src/tests/where_clause.rs
Normal file
12
crates/ide_completion/src/tests/where_clause.rs
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
//! Completion tests for inside of where clauses.
|
||||||
|
//!
|
||||||
|
//! The parent of the where clause tends to bleed completions of itself into the where clause so this
|
||||||
|
//! has to be thoroughly tested.
|
||||||
|
use expect_test::{expect, Expect};
|
||||||
|
|
||||||
|
use crate::tests::completion_list;
|
||||||
|
|
||||||
|
fn check(ra_fixture: &str, expect: Expect) {
|
||||||
|
let actual = completion_list(ra_fixture);
|
||||||
|
expect.assert_eq(&actual)
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue