mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 22:31:43 +00:00
Add predicate tests for ide_completions
This commit is contained in:
parent
dc4876d33d
commit
d4877ae992
4 changed files with 144 additions and 14 deletions
|
@ -33,7 +33,7 @@ fn complete_undotted_self(acc: &mut Completions, ctx: &CompletionContext) {
|
|||
if !ctx.config.enable_self_on_the_fly {
|
||||
return;
|
||||
}
|
||||
if !ctx.is_trivial_path() || ctx.is_path_disallowed() {
|
||||
if !ctx.is_trivial_path() || ctx.is_path_disallowed() || !ctx.expects_expression() {
|
||||
return;
|
||||
}
|
||||
ctx.scope.process_all_names(&mut |name, def| {
|
||||
|
|
|
@ -9,7 +9,7 @@ mod use_tree;
|
|||
mod items;
|
||||
mod pattern;
|
||||
mod type_pos;
|
||||
mod where_clause;
|
||||
mod predicate;
|
||||
|
||||
use std::mem;
|
||||
|
||||
|
|
142
crates/ide_completion/src/tests/predicate.rs
Normal file
142
crates/ide_completion/src/tests/predicate.rs
Normal file
|
@ -0,0 +1,142 @@
|
|||
//! Completion tests for predicates and bounds.
|
||||
use expect_test::{expect, Expect};
|
||||
|
||||
use crate::tests::{completion_list, BASE_FIXTURE};
|
||||
|
||||
fn check(ra_fixture: &str, expect: Expect) {
|
||||
let actual = completion_list(&format!("{}\n{}", BASE_FIXTURE, ra_fixture));
|
||||
expect.assert_eq(&actual)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn predicate_start() {
|
||||
// FIXME: `for` kw
|
||||
check(
|
||||
r#"
|
||||
struct Foo<'lt, T, const C: usize> where $0 {}
|
||||
"#,
|
||||
expect![[r#"
|
||||
tt Trait
|
||||
en Enum
|
||||
st Record
|
||||
st Tuple
|
||||
md module
|
||||
st Foo<…>
|
||||
st Unit
|
||||
ma makro!(…) macro_rules! makro
|
||||
bt u32
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bound_for_type_pred() {
|
||||
// FIXME: only show traits, macros and modules
|
||||
check(
|
||||
r#"
|
||||
struct Foo<'lt, T, const C: usize> where T: $0 {}
|
||||
"#,
|
||||
expect![[r#"
|
||||
sp Self
|
||||
tp T
|
||||
tt Trait
|
||||
en Enum
|
||||
st Record
|
||||
st Tuple
|
||||
md module
|
||||
st Foo<…>
|
||||
st Unit
|
||||
ma makro!(…) macro_rules! makro
|
||||
bt u32
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bound_for_lifetime_pred() {
|
||||
// FIXME: should only show lifetimes here
|
||||
check(
|
||||
r#"
|
||||
struct Foo<'lt, T, const C: usize> where 'lt: $0 {}
|
||||
"#,
|
||||
expect![[r#"
|
||||
sp Self
|
||||
tp T
|
||||
tt Trait
|
||||
en Enum
|
||||
st Record
|
||||
st Tuple
|
||||
md module
|
||||
st Foo<…>
|
||||
st Unit
|
||||
ma makro!(…) macro_rules! makro
|
||||
bt u32
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bound_for_for_pred() {
|
||||
// FIXME: only show traits, macros and modules
|
||||
check(
|
||||
r#"
|
||||
struct Foo<'lt, T, const C: usize> where for<'a> T: $0 {}
|
||||
"#,
|
||||
expect![[r#"
|
||||
sp Self
|
||||
tp T
|
||||
tt Trait
|
||||
en Enum
|
||||
st Record
|
||||
st Tuple
|
||||
md module
|
||||
st Foo<…>
|
||||
st Unit
|
||||
ma makro!(…) macro_rules! makro
|
||||
bt u32
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn param_list_for_for_pred() {
|
||||
check(
|
||||
r#"
|
||||
struct Foo<'lt, T, const C: usize> where for<'a> $0 {}
|
||||
"#,
|
||||
expect![[r#"
|
||||
tt Trait
|
||||
en Enum
|
||||
st Record
|
||||
st Tuple
|
||||
md module
|
||||
st Foo<…>
|
||||
st Unit
|
||||
ma makro!(…) macro_rules! makro
|
||||
bt u32
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pred_on_fn_in_impl() {
|
||||
// FIXME: only show traits, macros and modules
|
||||
check(
|
||||
r#"
|
||||
impl Record {
|
||||
fn method(self) where $0 {}
|
||||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
sp Self
|
||||
tt Trait
|
||||
en Enum
|
||||
st Record
|
||||
st Tuple
|
||||
md module
|
||||
st Unit
|
||||
ma makro!(…) macro_rules! makro
|
||||
bt u32
|
||||
"#]],
|
||||
);
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
//! 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