Lift out base item fixture for ide_completion tests

This commit is contained in:
Lukas Wirth 2021-06-23 18:37:47 +02:00
parent 9239943b84
commit dc4876d33d
6 changed files with 68 additions and 73 deletions

View file

@ -9,6 +9,7 @@ mod use_tree;
mod items;
mod pattern;
mod type_pos;
mod where_clause;
use std::mem;
@ -28,6 +29,21 @@ use test_utils::assert_eq_text;
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 {
enable_postfix_completions: true,
enable_imports_on_the_fly: true,

View file

@ -1,19 +1,9 @@
use expect_test::{expect, Expect};
use crate::tests::completion_list;
use crate::tests::{completion_list, BASE_FIXTURE};
fn check(ra_fixture: &str, expect: Expect) {
let base = r#"#[rustc_builtin_macro]
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));
let actual = completion_list(&format!("{}{}", BASE_FIXTURE, ra_fixture));
expect.assert_eq(&actual)
}
@ -21,7 +11,7 @@ trait Trait {}
fn in_mod_item_list() {
check(
r#"mod tests { $0 }"#,
expect![[r##"
expect![[r#"
kw pub(crate)
kw pub
kw unsafe
@ -40,8 +30,8 @@ fn in_mod_item_list() {
sn tmod (Test module)
sn tfn (Test function)
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() {
check(
r#"$0"#,
expect![[r##"
expect![[r#"
kw pub(crate)
kw pub
kw unsafe
@ -68,10 +58,9 @@ fn in_source_file_item_list() {
sn tmod (Test module)
sn tfn (Test function)
sn macro_rules
md bar
ma foo!() #[macro_export] macro_rules! foo
ma foo!() #[macro_export] macro_rules! foo
"##]],
md module
ma makro!() macro_rules! makro
"#]],
)
}
@ -106,7 +95,7 @@ fn in_item_list_after_attr() {
fn in_qualified_path() {
check(
r#"crate::$0"#,
expect![[r##"
expect![[r#"
kw pub(crate)
kw pub
kw unsafe
@ -122,9 +111,8 @@ fn in_qualified_path() {
kw enum
kw struct
kw union
md bar
ma foo!() #[macro_export] macro_rules! foo
"##]],
md module
"#]],
)
}
@ -177,17 +165,16 @@ fn after_visibility_unsafe() {
fn in_impl_assoc_item_list() {
check(
r#"impl Struct { $0 }"#,
expect![[r##"
expect![[r#"
kw pub(crate)
kw pub
kw unsafe
kw fn
kw const
kw type
md bar
ma foo!() #[macro_export] macro_rules! foo
ma foo!() #[macro_export] macro_rules! foo
"##]],
md module
ma makro!() macro_rules! makro
"#]],
)
}
@ -210,14 +197,13 @@ fn in_impl_assoc_item_list_after_attr() {
fn in_trait_assoc_item_list() {
check(
r"trait Foo { $0 }",
expect![[r##"
expect![[r#"
kw unsafe
kw fn
kw const
kw type
md bar
ma foo!() #[macro_export] macro_rules! foo
ma foo!() #[macro_export] macro_rules! foo
"##]],
md module
ma makro!() macro_rules! makro
"#]],
);
}

View file

@ -4,20 +4,10 @@
//! in [crate::completions::mod_].
use expect_test::{expect, Expect};
use crate::tests::completion_list;
use crate::tests::{completion_list, BASE_FIXTURE};
fn check(ra_fixture: &str, expect: Expect) {
let base = r#"#[rustc_builtin_macro]
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));
let actual = completion_list(&format!("{}{}", BASE_FIXTURE, ra_fixture));
expect.assert_eq(&actual)
}
@ -27,15 +17,16 @@ fn target_type_or_trait_in_impl_block() {
r#"
impl Tra$0
"#,
expect![[r##"
expect![[r#"
tt Trait
en Enum
st Struct
md bar
ma foo!() #[macro_export] macro_rules! foo
ma foo!() #[macro_export] macro_rules! foo
st Record
st Tuple
md module
st Unit
ma makro!() macro_rules! makro
bt u32
"##]],
"#]],
)
}
@ -45,15 +36,16 @@ fn target_type_in_trait_impl_block() {
r#"
impl Trait for Str$0
"#,
expect![[r##"
expect![[r#"
tt Trait
en Enum
st Struct
md bar
ma foo!() #[macro_export] macro_rules! foo
ma foo!() #[macro_export] macro_rules! foo
st Record
st Tuple
md module
st Unit
ma makro!() macro_rules! makro
bt u32
"##]],
"#]],
)
}

View file

@ -1,7 +1,7 @@
//! Completions tests for pattern position.
use expect_test::{expect, Expect};
use crate::tests::completion_list;
use crate::tests::{completion_list, BASE_FIXTURE};
fn check(ra_fixture: &str, expect: Expect) {
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) {
let base = r#"
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));
let actual = completion_list(&format!("{}\n{}", BASE_FIXTURE, ra_fixture));
expect.assert_eq(&actual)
}
@ -123,9 +111,9 @@ fn foo() {
"#,
expect![[r#"
kw mut
en Enum
bn Record Record { field$1 }$0
st Record
en Enum
bn Tuple Tuple($1)$0
st Tuple
md module

View file

@ -1,3 +1,4 @@
//! Completions tests for use trees.
use expect_test::{expect, Expect};
use crate::tests::completion_list;

View 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)
}