Move out unqualified_path completion tests

This commit is contained in:
Lukas Wirth 2021-07-23 16:37:19 +02:00
parent ea72a5136c
commit 8de3f7ee53
5 changed files with 251 additions and 324 deletions

View File

@ -47,7 +47,6 @@ pub(crate) fn complete_record(acc: &mut Completions, ctx: &CompletionContext) ->
#[cfg(test)]
mod tests {
use crate::tests::check_edit;
#[test]

View File

@ -86,26 +86,3 @@ fn ${1:feature}() {
let item = snippet(ctx, cap, "macro_rules", "macro_rules! $1 {\n\t($2) => {\n\t\t$0\n\t};\n}");
item.add_to(acc);
}
#[cfg(test)]
mod tests {
use expect_test::{expect, Expect};
use crate::{tests::filtered_completion_list, CompletionKind};
fn check(ra_fixture: &str, expect: Expect) {
let actual = filtered_completion_list(ra_fixture, CompletionKind::Snippet);
expect.assert_eq(&actual)
}
#[test]
fn completes_snippets_in_expressions() {
check(
r#"fn foo(x: i32) { $0 }"#,
expect![[r#"
sn pd
sn ppd
"#]],
);
}
}

View File

@ -87,7 +87,7 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC
if let ScopeDef::GenericParam(hir::GenericParam::LifetimeParam(_)) | ScopeDef::Label(_) =
res
{
cov_mark::hit!(skip_lifetime_completion);
cov_mark::hit!(unqualified_skip_lifetime_completion);
return;
}
let add_resolution = match res {
@ -155,51 +155,6 @@ fn main() {
)
}
#[test]
fn completes_generic_params() {
check(
r#"fn quux<T>() { $0 }"#,
expect![[r#"
tp T
fn quux() fn()
"#]],
);
check(
r#"fn quux<const C: usize>() { $0 }"#,
expect![[r#"
cp C
fn quux() fn()
"#]],
);
}
#[test]
fn does_not_complete_lifetimes() {
cov_mark::check!(skip_lifetime_completion);
check(
r#"fn quux<'a>() { $0 }"#,
expect![[r#"
fn quux() fn()
"#]],
);
}
#[test]
fn completes_module_items() {
check(
r#"
struct S;
enum E {}
fn quux() { $0 }
"#,
expect![[r#"
st S
fn quux() fn()
en E
"#]],
);
}
/// Regression test for issue #6091.
#[test]
fn correctly_completes_module_items_prefixed_with_underscore() {
@ -220,55 +175,6 @@ fn _alpha() {}
)
}
#[test]
fn completes_module_items_in_nested_modules() {
check(
r#"
struct Foo;
mod m {
struct Bar;
fn quux() { $0 }
}
"#,
expect![[r#"
fn quux() fn()
st Bar
"#]],
);
}
#[test]
fn dont_show_both_completions_for_shadowing() {
check(
r#"
fn foo() {
let bar = 92;
{
let bar = 62;
drop($0)
}
}
"#,
// FIXME: should be only one bar here
expect![[r#"
lc bar i32
lc bar i32
fn foo() fn()
"#]],
);
}
#[test]
fn completes_self_in_methods() {
check(
r#"impl S { fn foo(&self) { $0 } }"#,
expect![[r#"
lc self &{unknown}
sp Self
"#]],
);
}
#[test]
fn completes_prelude() {
check(
@ -318,32 +224,6 @@ mod macros {
);
}
#[test]
fn does_not_complete_non_fn_macros() {
check(
r#"
#[rustc_builtin_macro]
pub macro Clone {}
fn f() {$0}
"#,
expect![[r#"
fn f() fn()
"#]],
);
check(
r#"
#[rustc_builtin_macro]
pub macro bench {}
fn f() {$0}
"#,
expect![[r#"
fn f() fn()
"#]],
);
}
#[test]
fn completes_std_prelude_if_core_is_defined() {
check(
@ -372,183 +252,4 @@ pub mod prelude {
"#]],
);
}
#[test]
fn completes_macros_as_value() {
check(
r#"
macro_rules! foo { () => {} }
#[macro_use]
mod m1 {
macro_rules! bar { () => {} }
}
mod m2 {
macro_rules! nope { () => {} }
#[macro_export]
macro_rules! baz { () => {} }
}
fn main() { let v = $0 }
"#,
expect![[r##"
md m1
ma baz!() #[macro_export] macro_rules! baz
fn main() fn()
md m2
ma bar!() macro_rules! bar
ma foo!() macro_rules! foo
"##]],
);
}
#[test]
fn completes_both_macro_and_value() {
check(
r#"
macro_rules! foo { () => {} }
fn foo() { $0 }
"#,
expect![[r#"
fn foo() fn()
ma foo!() macro_rules! foo
"#]],
);
}
#[test]
fn completes_macros_as_stmt() {
check(
r#"
macro_rules! foo { () => {} }
fn main() { $0 }
"#,
expect![[r#"
fn main() fn()
ma foo!() macro_rules! foo
"#]],
);
}
#[test]
fn completes_local_item() {
check(
r#"
fn main() {
return f$0;
fn frobnicate() {}
}
"#,
expect![[r#"
fn frobnicate() fn()
fn main() fn()
"#]],
);
}
#[test]
fn completes_in_simple_macro_1() {
check(
r#"
macro_rules! m { ($e:expr) => { $e } }
fn quux(x: i32) {
let y = 92;
m!($0);
}
"#,
expect![[r#"
lc y i32
lc x i32
fn quux() fn(i32)
ma m!() macro_rules! m
"#]],
);
}
#[test]
fn completes_in_simple_macro_2() {
check(
r"
macro_rules! m { ($e:expr) => { $e } }
fn quux(x: i32) {
let y = 92;
m!(x$0);
}
",
expect![[r#"
lc y i32
lc x i32
fn quux() fn(i32)
ma m!() macro_rules! m
"#]],
);
}
#[test]
fn completes_in_simple_macro_without_closing_parens() {
check(
r#"
macro_rules! m { ($e:expr) => { $e } }
fn quux(x: i32) {
let y = 92;
m!(x$0
}
"#,
expect![[r#"
lc y i32
lc x i32
fn quux() fn(i32)
ma m!() macro_rules! m
"#]],
);
}
#[test]
fn completes_unresolved_uses() {
check(
r#"
use spam::Quux;
fn main() { $0 }
"#,
expect![[r#"
fn main() fn()
?? Quux
"#]],
);
}
#[test]
fn completes_enum_variant_basic_expr() {
check(
r#"
enum Foo { Bar, Baz, Quux }
fn main() { let foo: Foo = Q$0 }
"#,
expect![[r#"
ev Foo::Bar ()
ev Foo::Baz ()
ev Foo::Quux ()
en Foo
fn main() fn()
"#]],
)
}
#[test]
fn completes_enum_variant_from_module() {
check(
r#"
mod m { pub enum E { V } }
fn f() -> m::E { V$0 }
"#,
expect![[r#"
ev m::E::V ()
md m
fn f() fn() -> E
"#]],
)
}
}

View File

@ -8,6 +8,7 @@
//! completed where, not how.
mod attribute;
mod expression;
mod fn_param;
mod item_list;
mod item;

View File

@ -0,0 +1,249 @@
//! Completion tests for expressions.
use expect_test::{expect, Expect};
use crate::tests::{completion_list, BASE_ITEMS_FIXTURE};
fn check(ra_fixture: &str, expect: Expect) {
let actual = completion_list(&format!("{}{}", BASE_ITEMS_FIXTURE, ra_fixture));
expect.assert_eq(&actual)
}
fn check_empty(ra_fixture: &str, expect: Expect) {
let actual = completion_list(ra_fixture);
expect.assert_eq(&actual);
}
#[test]
fn completes_various_bindings() {
check_empty(
r#"
fn func(param0 @ (param1, param2): (i32, i32)) {
let letlocal = 92;
if let ifletlocal = 100 {
match 0 {
matcharm => 1 + $0,
otherwise => (),
}
}
let letlocal2 = 44;
}
"#,
expect![[r#"
kw unsafe
kw match
kw while
kw while let
kw loop
kw if
kw if let
kw for
kw true
kw false
kw return
kw self
kw super
kw crate
lc matcharm i32
lc ifletlocal i32
lc letlocal i32
lc param0 (i32, i32)
lc param1 i32
lc param2 i32
fn func() fn((i32, i32))
bt u32
"#]],
);
}
#[test]
fn completes_all_the_things() {
cov_mark::check!(unqualified_skip_lifetime_completion);
check(
r#"
use non_existant::Unresolved;
mod qualified { pub enum Enum { Variant } }
impl Unit {
fn foo<'lifetime, TypeParam, const CONST_PARAM: usize>(self) {
fn local_func() {}
$0
}
}
"#,
expect![[r##"
kw unsafe
kw fn
kw const
kw type
kw impl
kw extern
kw use
kw trait
kw static
kw mod
kw match
kw while
kw while let
kw loop
kw if
kw if let
kw for
kw true
kw false
kw let
kw return
sn pd
sn ppd
kw self
kw super
kw crate
fn local_func() fn()
bt u32
lc self Unit
tp TypeParam
cp CONST_PARAM
sp Self
tt Trait
en Enum
st Record
st Tuple
md module
st Unit
md qualified
ma makro!() #[macro_export] macro_rules! makro
?? Unresolved
fn function() fn()
sc STATIC
ev TupleV() (u32)
ct CONST
ma makro!() #[macro_export] macro_rules! makro
me self.foo() fn(self)
"##]],
);
}
#[test]
fn shadowing_shows_single_completion() {
check_empty(
r#"
fn foo() {
let bar = 92;
{
let bar = 62;
drop($0)
}
}
"#,
// FIXME: should be only one bar here
expect![[r#"
kw unsafe
kw match
kw while
kw while let
kw loop
kw if
kw if let
kw for
kw true
kw false
kw return
kw self
kw super
kw crate
lc bar i32
lc bar i32
fn foo() fn()
bt u32
"#]],
);
}
#[test]
fn in_macro_expr_frag() {
check_empty(
r#"
macro_rules! m { ($e:expr) => { $e } }
fn quux(x: i32) {
m!($0);
}
"#,
expect![[r#"
kw unsafe
kw match
kw while
kw while let
kw loop
kw if
kw if let
kw for
kw true
kw false
kw return
kw self
kw super
kw crate
bt u32
lc x i32
fn quux() fn(i32)
ma m!() macro_rules! m
"#]],
);
check_empty(
r"
macro_rules! m { ($e:expr) => { $e } }
fn quux(x: i32) {
m!(x$0);
}
",
expect![[r#"
kw unsafe
kw match
kw while
kw while let
kw loop
kw if
kw if let
kw for
kw true
kw false
kw return
kw self
kw super
kw crate
bt u32
lc x i32
fn quux() fn(i32)
ma m!() macro_rules! m
"#]],
);
check_empty(
r#"
macro_rules! m { ($e:expr) => { $e } }
fn quux(x: i32) {
let y = 92;
m!(x$0
}
"#,
expect![[r#"
kw unsafe
kw match
kw while
kw while let
kw loop
kw if
kw if let
kw for
kw true
kw false
kw return
kw self
kw super
kw crate
lc y i32
bt u32
lc x i32
fn quux() fn(i32)
ma m!() macro_rules! m
"#]],
);
}