mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 14:21:44 +00:00
Add functions to base items completion test fixture
This commit is contained in:
parent
b744e3369d
commit
ea72a5136c
7 changed files with 46 additions and 106 deletions
|
@ -135,61 +135,6 @@ mod tests {
|
||||||
expect.assert_eq(&actual)
|
expect.assert_eq(&actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn completes_bindings_from_let() {
|
|
||||||
check(
|
|
||||||
r#"
|
|
||||||
fn quux(x: i32) {
|
|
||||||
let y = 92;
|
|
||||||
1 + $0;
|
|
||||||
let z = ();
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
expect![[r#"
|
|
||||||
lc y i32
|
|
||||||
lc x i32
|
|
||||||
fn quux(…) fn(i32)
|
|
||||||
"#]],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn completes_bindings_from_if_let() {
|
|
||||||
check(
|
|
||||||
r#"
|
|
||||||
fn quux() {
|
|
||||||
if let Some(x) = foo() {
|
|
||||||
let y = 92;
|
|
||||||
};
|
|
||||||
if let Some(a) = bar() {
|
|
||||||
let b = 62;
|
|
||||||
1 + $0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
expect![[r#"
|
|
||||||
lc b i32
|
|
||||||
lc a
|
|
||||||
fn quux() fn()
|
|
||||||
"#]],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn completes_bindings_from_for() {
|
|
||||||
check(
|
|
||||||
r#"
|
|
||||||
fn quux() {
|
|
||||||
for x in &[1, 2, 3] { $0 }
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
expect![[r#"
|
|
||||||
lc x
|
|
||||||
fn quux() fn()
|
|
||||||
"#]],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn completes_if_prefix_is_keyword() {
|
fn completes_if_prefix_is_keyword() {
|
||||||
cov_mark::check!(completes_if_prefix_is_keyword);
|
cov_mark::check!(completes_if_prefix_is_keyword);
|
||||||
|
|
|
@ -38,7 +38,7 @@ use test_utils::assert_eq_text;
|
||||||
use crate::{item::CompletionKind, CompletionConfig, CompletionItem};
|
use crate::{item::CompletionKind, CompletionConfig, CompletionItem};
|
||||||
|
|
||||||
/// Lots of basic item definitions
|
/// Lots of basic item definitions
|
||||||
const BASE_FIXTURE: &str = r#"
|
const BASE_ITEMS_FIXTURE: &str = r#"
|
||||||
enum Enum { TupleV(u32), RecordV { field: u32 }, UnitV }
|
enum Enum { TupleV(u32), RecordV { field: u32 }, UnitV }
|
||||||
use self::Enum::TupleV;
|
use self::Enum::TupleV;
|
||||||
mod module {}
|
mod module {}
|
||||||
|
@ -53,6 +53,7 @@ struct Unit;
|
||||||
macro_rules! makro {}
|
macro_rules! makro {}
|
||||||
#[rustc_builtin_macro]
|
#[rustc_builtin_macro]
|
||||||
pub macro Clone {}
|
pub macro Clone {}
|
||||||
|
fn function() {}
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
pub(crate) const TEST_CONFIG: CompletionConfig = CompletionConfig {
|
pub(crate) const TEST_CONFIG: CompletionConfig = CompletionConfig {
|
||||||
|
|
|
@ -4,10 +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, BASE_FIXTURE};
|
use crate::tests::{completion_list, BASE_ITEMS_FIXTURE};
|
||||||
|
|
||||||
fn check(ra_fixture: &str, expect: Expect) {
|
fn check(ra_fixture: &str, expect: Expect) {
|
||||||
let actual = completion_list(&format!("{}{}", BASE_FIXTURE, ra_fixture));
|
let actual = completion_list(&format!("{}{}", BASE_ITEMS_FIXTURE, ra_fixture));
|
||||||
expect.assert_eq(&actual)
|
expect.assert_eq(&actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,10 +25,10 @@ impl Tra$0
|
||||||
en Enum
|
en Enum
|
||||||
st Record
|
st Record
|
||||||
st Tuple
|
st Tuple
|
||||||
ma makro!(…) #[macro_export] macro_rules! makro
|
|
||||||
md module
|
md module
|
||||||
st Unit
|
st Unit
|
||||||
ma makro!(…) #[macro_export] macro_rules! makro
|
ma makro!(…) #[macro_export] macro_rules! makro
|
||||||
|
ma makro!(…) #[macro_export] macro_rules! makro
|
||||||
bt u32
|
bt u32
|
||||||
"##]],
|
"##]],
|
||||||
)
|
)
|
||||||
|
@ -48,10 +48,10 @@ impl Trait for Str$0
|
||||||
en Enum
|
en Enum
|
||||||
st Record
|
st Record
|
||||||
st Tuple
|
st Tuple
|
||||||
ma makro!(…) #[macro_export] macro_rules! makro
|
|
||||||
md module
|
md module
|
||||||
st Unit
|
st Unit
|
||||||
ma makro!(…) #[macro_export] macro_rules! makro
|
ma makro!(…) #[macro_export] macro_rules! makro
|
||||||
|
ma makro!(…) #[macro_export] macro_rules! makro
|
||||||
bt u32
|
bt u32
|
||||||
"##]],
|
"##]],
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
//! Completion tests for item list position.
|
//! Completion tests for item list position.
|
||||||
use expect_test::{expect, Expect};
|
use expect_test::{expect, Expect};
|
||||||
|
|
||||||
use crate::tests::{completion_list, BASE_FIXTURE};
|
use crate::tests::{completion_list, BASE_ITEMS_FIXTURE};
|
||||||
|
|
||||||
fn check(ra_fixture: &str, expect: Expect) {
|
fn check(ra_fixture: &str, expect: Expect) {
|
||||||
let actual = completion_list(&format!("{}{}", BASE_FIXTURE, ra_fixture));
|
let actual = completion_list(&format!("{}{}", BASE_ITEMS_FIXTURE, ra_fixture));
|
||||||
expect.assert_eq(&actual)
|
expect.assert_eq(&actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,9 +65,9 @@ fn in_source_file_item_list() {
|
||||||
kw self
|
kw self
|
||||||
kw super
|
kw super
|
||||||
kw crate
|
kw crate
|
||||||
ma makro!(…) #[macro_export] macro_rules! makro
|
|
||||||
md module
|
md module
|
||||||
ma makro!(…) #[macro_export] macro_rules! makro
|
ma makro!(…) #[macro_export] macro_rules! makro
|
||||||
|
ma makro!(…) #[macro_export] macro_rules! makro
|
||||||
"##]],
|
"##]],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -105,8 +105,8 @@ fn in_qualified_path() {
|
||||||
check(
|
check(
|
||||||
r#"crate::$0"#,
|
r#"crate::$0"#,
|
||||||
expect![[r##"
|
expect![[r##"
|
||||||
ma makro!(…) #[macro_export] macro_rules! makro
|
|
||||||
md module
|
md module
|
||||||
|
ma makro!(…) #[macro_export] macro_rules! makro
|
||||||
"##]],
|
"##]],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -170,9 +170,9 @@ fn in_impl_assoc_item_list() {
|
||||||
kw self
|
kw self
|
||||||
kw super
|
kw super
|
||||||
kw crate
|
kw crate
|
||||||
ma makro!(…) #[macro_export] macro_rules! makro
|
|
||||||
md module
|
md module
|
||||||
ma makro!(…) #[macro_export] macro_rules! makro
|
ma makro!(…) #[macro_export] macro_rules! makro
|
||||||
|
ma makro!(…) #[macro_export] macro_rules! makro
|
||||||
"##]],
|
"##]],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//! Completion tests for pattern position.
|
//! Completion tests for pattern position.
|
||||||
use expect_test::{expect, Expect};
|
use expect_test::{expect, Expect};
|
||||||
|
|
||||||
use crate::tests::{completion_list, BASE_FIXTURE};
|
use crate::tests::{completion_list, BASE_ITEMS_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,7 +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 actual = completion_list(&format!("{}\n{}", BASE_FIXTURE, ra_fixture));
|
let actual = completion_list(&format!("{}\n{}", BASE_ITEMS_FIXTURE, ra_fixture));
|
||||||
expect.assert_eq(&actual)
|
expect.assert_eq(&actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
//! Completion tests for predicates and bounds.
|
//! Completion tests for predicates and bounds.
|
||||||
use expect_test::{expect, Expect};
|
use expect_test::{expect, Expect};
|
||||||
|
|
||||||
use crate::tests::{completion_list, BASE_FIXTURE};
|
use crate::tests::{completion_list, BASE_ITEMS_FIXTURE};
|
||||||
|
|
||||||
fn check(ra_fixture: &str, expect: Expect) {
|
fn check(ra_fixture: &str, expect: Expect) {
|
||||||
let actual = completion_list(&format!("{}\n{}", BASE_FIXTURE, ra_fixture));
|
let actual = completion_list(&format!("{}\n{}", BASE_ITEMS_FIXTURE, ra_fixture));
|
||||||
expect.assert_eq(&actual)
|
expect.assert_eq(&actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,10 +130,10 @@ impl Record {
|
||||||
en Enum
|
en Enum
|
||||||
st Record
|
st Record
|
||||||
st Tuple
|
st Tuple
|
||||||
ma makro!(…) #[macro_export] macro_rules! makro
|
|
||||||
md module
|
md module
|
||||||
st Unit
|
st Unit
|
||||||
ma makro!(…) #[macro_export] macro_rules! makro
|
ma makro!(…) #[macro_export] macro_rules! makro
|
||||||
|
ma makro!(…) #[macro_export] macro_rules! makro
|
||||||
bt u32
|
bt u32
|
||||||
"##]],
|
"##]],
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,23 +1,10 @@
|
||||||
//! Completion tests for type position.
|
//! Completion tests for type position.
|
||||||
use expect_test::{expect, Expect};
|
use expect_test::{expect, Expect};
|
||||||
|
|
||||||
use crate::tests::completion_list;
|
use crate::tests::{completion_list, BASE_ITEMS_FIXTURE};
|
||||||
|
|
||||||
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_ITEMS_FIXTURE, ra_fixture));
|
||||||
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 {}
|
|
||||||
"#;
|
|
||||||
let actual = completion_list(&format!("{}\n{}", base, ra_fixture));
|
|
||||||
expect.assert_eq(&actual)
|
expect.assert_eq(&actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +16,7 @@ struct Foo<'lt, T, const C: usize> {
|
||||||
f: $0
|
f: $0
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r##"
|
||||||
kw self
|
kw self
|
||||||
kw super
|
kw super
|
||||||
kw crate
|
kw crate
|
||||||
|
@ -42,9 +29,10 @@ struct Foo<'lt, T, const C: usize> {
|
||||||
md module
|
md module
|
||||||
st Foo<…>
|
st Foo<…>
|
||||||
st Unit
|
st Unit
|
||||||
ma makro!(…) macro_rules! makro
|
ma makro!(…) #[macro_export] macro_rules! makro
|
||||||
|
ma makro!(…) #[macro_export] macro_rules! makro
|
||||||
bt u32
|
bt u32
|
||||||
"#]],
|
"##]],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +42,7 @@ fn tuple_struct_field() {
|
||||||
r#"
|
r#"
|
||||||
struct Foo<'lt, T, const C: usize>(f$0);
|
struct Foo<'lt, T, const C: usize>(f$0);
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r##"
|
||||||
kw pub(crate)
|
kw pub(crate)
|
||||||
kw pub
|
kw pub
|
||||||
kw self
|
kw self
|
||||||
|
@ -69,9 +57,10 @@ struct Foo<'lt, T, const C: usize>(f$0);
|
||||||
md module
|
md module
|
||||||
st Foo<…>
|
st Foo<…>
|
||||||
st Unit
|
st Unit
|
||||||
ma makro!(…) macro_rules! makro
|
ma makro!(…) #[macro_export] macro_rules! makro
|
||||||
|
ma makro!(…) #[macro_export] macro_rules! makro
|
||||||
bt u32
|
bt u32
|
||||||
"#]],
|
"##]],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +70,7 @@ fn fn_return_type() {
|
||||||
r#"
|
r#"
|
||||||
fn x<'lt, T, const C: usize>() -> $0
|
fn x<'lt, T, const C: usize>() -> $0
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r##"
|
||||||
kw self
|
kw self
|
||||||
kw super
|
kw super
|
||||||
kw crate
|
kw crate
|
||||||
|
@ -92,9 +81,10 @@ fn x<'lt, T, const C: usize>() -> $0
|
||||||
st Tuple
|
st Tuple
|
||||||
md module
|
md module
|
||||||
st Unit
|
st Unit
|
||||||
ma makro!(…) macro_rules! makro
|
ma makro!(…) #[macro_export] macro_rules! makro
|
||||||
|
ma makro!(…) #[macro_export] macro_rules! makro
|
||||||
bt u32
|
bt u32
|
||||||
"#]],
|
"##]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,7 +97,7 @@ fn foo<'lt, T, const C: usize>() {
|
||||||
let _: $0;
|
let _: $0;
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r##"
|
||||||
kw self
|
kw self
|
||||||
kw super
|
kw super
|
||||||
kw crate
|
kw crate
|
||||||
|
@ -118,9 +108,10 @@ fn foo<'lt, T, const C: usize>() {
|
||||||
st Tuple
|
st Tuple
|
||||||
md module
|
md module
|
||||||
st Unit
|
st Unit
|
||||||
ma makro!(…) macro_rules! makro
|
ma makro!(…) #[macro_export] macro_rules! makro
|
||||||
|
ma makro!(…) #[macro_export] macro_rules! makro
|
||||||
bt u32
|
bt u32
|
||||||
"#]],
|
"##]],
|
||||||
);
|
);
|
||||||
check_with(
|
check_with(
|
||||||
r#"
|
r#"
|
||||||
|
@ -129,14 +120,15 @@ fn foo<'lt, T, const C: usize>() {
|
||||||
let _: self::$0;
|
let _: self::$0;
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r##"
|
||||||
tt Trait
|
tt Trait
|
||||||
en Enum
|
en Enum
|
||||||
st Record
|
st Record
|
||||||
st Tuple
|
st Tuple
|
||||||
md module
|
md module
|
||||||
st Unit
|
st Unit
|
||||||
"#]],
|
ma makro!(…) #[macro_export] macro_rules! makro
|
||||||
|
"##]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,7 +142,7 @@ trait Trait2 {
|
||||||
|
|
||||||
fn foo<'lt, T: Trait2<$0>, const CONST_PARAM: usize>(_: T) {}
|
fn foo<'lt, T: Trait2<$0>, const CONST_PARAM: usize>(_: T) {}
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r##"
|
||||||
kw self
|
kw self
|
||||||
kw super
|
kw super
|
||||||
kw crate
|
kw crate
|
||||||
|
@ -161,13 +153,14 @@ fn foo<'lt, T: Trait2<$0>, const CONST_PARAM: usize>(_: T) {}
|
||||||
en Enum
|
en Enum
|
||||||
st Record
|
st Record
|
||||||
st Tuple
|
st Tuple
|
||||||
tt Trait2
|
|
||||||
md module
|
md module
|
||||||
st Unit
|
st Unit
|
||||||
|
ma makro!(…) #[macro_export] macro_rules! makro
|
||||||
|
tt Trait2
|
||||||
ct CONST
|
ct CONST
|
||||||
ma makro!(…) macro_rules! makro
|
ma makro!(…) #[macro_export] macro_rules! makro
|
||||||
bt u32
|
bt u32
|
||||||
"#]],
|
"##]],
|
||||||
);
|
);
|
||||||
check_with(
|
check_with(
|
||||||
r#"
|
r#"
|
||||||
|
@ -177,15 +170,16 @@ trait Trait2 {
|
||||||
|
|
||||||
fn foo<'lt, T: Trait2<self::$0>, const CONST_PARAM: usize>(_: T) {}
|
fn foo<'lt, T: Trait2<self::$0>, const CONST_PARAM: usize>(_: T) {}
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r##"
|
||||||
tt Trait
|
tt Trait
|
||||||
en Enum
|
en Enum
|
||||||
st Record
|
st Record
|
||||||
st Tuple
|
st Tuple
|
||||||
tt Trait2
|
|
||||||
md module
|
md module
|
||||||
st Unit
|
st Unit
|
||||||
|
ma makro!(…) #[macro_export] macro_rules! makro
|
||||||
|
tt Trait2
|
||||||
ct CONST
|
ct CONST
|
||||||
"#]],
|
"##]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue