Add predicate tests for ide_completions

This commit is contained in:
Lukas Wirth 2021-06-23 18:58:19 +02:00
parent dc4876d33d
commit d4877ae992
4 changed files with 144 additions and 14 deletions

View file

@ -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| {

View file

@ -9,7 +9,7 @@ mod use_tree;
mod items;
mod pattern;
mod type_pos;
mod where_clause;
mod predicate;
use std::mem;

View 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
"#]],
);
}

View file

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