9683: internal: Move out expression based `unqualified_path` completion tests r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
bors[bot] 2021-07-23 15:07:10 +00:00 committed by GitHub
commit 75d7da196f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 430 additions and 571 deletions

View File

@ -255,60 +255,6 @@ mod tests {
expect.assert_eq(&actual);
}
fn check_builtin(ra_fixture: &str, expect: Expect) {
let actual = filtered_completion_list(ra_fixture, CompletionKind::BuiltinType);
expect.assert_eq(&actual);
}
#[test]
fn dont_complete_primitive_in_use() {
check_builtin(r#"use self::$0;"#, expect![[""]]);
}
#[test]
fn dont_complete_primitive_in_module_scope() {
check_builtin(r#"fn foo() { self::$0 }"#, expect![[""]]);
}
#[test]
fn completes_enum_variant() {
check(
r#"
enum E { Foo, Bar(i32) }
fn foo() { let _ = E::$0 }
"#,
expect![[r#"
ev Foo ()
ev Bar() (i32)
"#]],
);
}
#[test]
fn completes_struct_associated_items() {
check(
r#"
//- /lib.rs
struct S;
impl S {
fn a() {}
fn b(&self) {}
const C: i32 = 42;
type T = i32;
}
fn foo() { let _ = S::$0 }
"#,
expect![[r#"
fn a() fn()
me b() fn(&self)
ct C const C: i32 = 42;
ta T type T = i32;
"#]],
);
}
#[test]
fn associated_item_visibility() {
check(
@ -336,21 +282,6 @@ fn foo() { let _ = S::$0 }
);
}
#[test]
fn completes_enum_associated_method() {
check(
r#"
enum E {};
impl E { fn m() { } }
fn foo() { let _ = E::$0 }
"#,
expect![[r#"
fn m() fn()
"#]],
);
}
#[test]
fn completes_union_associated_method() {
check(

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 {
@ -135,61 +135,6 @@ mod tests {
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]
fn completes_if_prefix_is_keyword() {
cov_mark::check!(completes_if_prefix_is_keyword);
@ -210,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() {
@ -275,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(
@ -373,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(
@ -427,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

@ -1,13 +1,15 @@
//! Tests and test utilities for completions.
//!
//! Most tests live in this module or its submodules unless for very specific completions like
//! `attributes` or `lifetimes` where the completed concept is a distinct thing.
//! Notable examples for completions that are being tested in this module's submodule are paths.
//! Another exception are `check_edit` tests which usually live in the completion modules themselves,
//! as the main purpose of this test module here is to give the developer an overview of whats being
//! completed where, not how.
//! Most tests live in this module or its submodules. The tests in these submodules are "location"
//! oriented, that is they try to check completions for something like type position, param position
//! etc.
//! Tests that are more orientated towards specific completion types like visibility checks of path
//! completions or `check_edit` tests usually live in their respective completion modules instead.
//! This gives this test module and its submodules here the main purpose of giving the developer an
//! overview of whats being completed where, not how.
mod attribute;
mod expression;
mod fn_param;
mod item_list;
mod item;
@ -38,7 +40,7 @@ use test_utils::assert_eq_text;
use crate::{item::CompletionKind, CompletionConfig, CompletionItem};
/// Lots of basic item definitions
const BASE_FIXTURE: &str = r#"
const BASE_ITEMS_FIXTURE: &str = r#"
enum Enum { TupleV(u32), RecordV { field: u32 }, UnitV }
use self::Enum::TupleV;
mod module {}
@ -53,6 +55,8 @@ struct Unit;
macro_rules! makro {}
#[rustc_builtin_macro]
pub macro Clone {}
fn function() {}
union Union { field: i32 }
"#;
pub(crate) const TEST_CONFIG: CompletionConfig = CompletionConfig {

View File

@ -0,0 +1,304 @@
//! 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
}
}
"#,
// `self` is in here twice, once as the module, once as the local
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
un Union
ev TupleV() (u32)
ct CONST
ma makro!() #[macro_export] macro_rules! makro
me self.foo() fn(self)
"##]],
);
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() {}
self::$0
}
}
"#,
expect![[r##"
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
un Union
ev TupleV() (u32)
ct CONST
"##]],
);
}
#[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
"#]],
);
}
#[test]
fn enum_qualified() {
check(
r#"
impl Enum {
type AssocType = ();
const ASSOC_CONST: () = ();
fn assoc_fn() {}
}
fn func() {
Enum::$0
}
"#,
expect![[r#"
ev TupleV() (u32)
ev RecordV { field: u32 }
ev UnitV ()
ct ASSOC_CONST const ASSOC_CONST: () = ();
fn assoc_fn() fn()
ta AssocType type AssocType = ();
"#]],
);
}

View File

@ -4,10 +4,10 @@
//! in [crate::completions::mod_].
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) {
let actual = completion_list(&format!("{}{}", BASE_FIXTURE, ra_fixture));
let actual = completion_list(&format!("{}{}", BASE_ITEMS_FIXTURE, ra_fixture));
expect.assert_eq(&actual)
}
@ -25,10 +25,11 @@ impl Tra$0
en Enum
st Record
st Tuple
ma makro!() #[macro_export] macro_rules! makro
md module
st Unit
ma makro!() #[macro_export] macro_rules! makro
un Union
ma makro!() #[macro_export] macro_rules! makro
bt u32
"##]],
)
@ -48,10 +49,11 @@ impl Trait for Str$0
en Enum
st Record
st Tuple
ma makro!() #[macro_export] macro_rules! makro
md module
st Unit
ma makro!() #[macro_export] macro_rules! makro
un Union
ma makro!() #[macro_export] macro_rules! makro
bt u32
"##]],
)

View File

@ -1,10 +1,10 @@
//! Completion tests for item list position.
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) {
let actual = completion_list(&format!("{}{}", BASE_FIXTURE, ra_fixture));
let actual = completion_list(&format!("{}{}", BASE_ITEMS_FIXTURE, ra_fixture));
expect.assert_eq(&actual)
}
@ -65,9 +65,9 @@ fn in_source_file_item_list() {
kw self
kw super
kw crate
ma makro!() #[macro_export] macro_rules! makro
md module
ma makro!() #[macro_export] macro_rules! makro
ma makro!() #[macro_export] macro_rules! makro
"##]],
)
}
@ -105,8 +105,8 @@ fn in_qualified_path() {
check(
r#"crate::$0"#,
expect![[r##"
ma makro!() #[macro_export] macro_rules! makro
md module
ma makro!() #[macro_export] macro_rules! makro
"##]],
)
}
@ -170,9 +170,9 @@ fn in_impl_assoc_item_list() {
kw self
kw super
kw crate
ma makro!() #[macro_export] macro_rules! makro
md module
ma makro!() #[macro_export] macro_rules! makro
ma makro!() #[macro_export] macro_rules! makro
"##]],
)
}

View File

@ -1,21 +1,21 @@
//! Completion tests for pattern position.
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_empty(ra_fixture: &str, expect: Expect) {
let actual = completion_list(ra_fixture);
expect.assert_eq(&actual)
}
fn check_with(ra_fixture: &str, expect: Expect) {
let actual = completion_list(&format!("{}\n{}", BASE_FIXTURE, ra_fixture));
fn check(ra_fixture: &str, expect: Expect) {
let actual = completion_list(&format!("{}\n{}", BASE_ITEMS_FIXTURE, ra_fixture));
expect.assert_eq(&actual)
}
#[test]
fn ident_rebind_pat() {
check(
check_empty(
r#"
fn quux() {
let en$0 @ x
@ -29,7 +29,7 @@ fn quux() {
#[test]
fn ident_ref_pat() {
check(
check_empty(
r#"
fn quux() {
let ref en$0
@ -39,7 +39,7 @@ fn quux() {
kw mut
"#]],
);
check(
check_empty(
r#"
fn quux() {
let ref en$0 @ x
@ -54,7 +54,7 @@ fn quux() {
#[test]
fn ident_ref_mut_pat() {
// FIXME mut is already here, don't complete it again
check(
check_empty(
r#"
fn quux() {
let ref mut en$0
@ -64,7 +64,7 @@ fn quux() {
kw mut
"#]],
);
check(
check_empty(
r#"
fn quux() {
let ref mut en$0 @ x
@ -78,7 +78,7 @@ fn quux() {
#[test]
fn ref_pat() {
check(
check_empty(
r#"
fn quux() {
let &en$0
@ -89,7 +89,7 @@ fn quux() {
"#]],
);
// FIXME mut is already here, don't complete it again
check(
check_empty(
r#"
fn quux() {
let &mut en$0
@ -103,7 +103,7 @@ fn quux() {
#[test]
fn refutable() {
check_with(
check(
r#"
fn foo() {
if let a$0
@ -129,7 +129,7 @@ fn foo() {
#[test]
fn irrefutable() {
check_with(
check(
r#"
fn foo() {
let a$0
@ -150,7 +150,7 @@ fn foo() {
#[test]
fn in_param() {
check_with(
check(
r#"
fn foo(a$0) {
}
@ -170,7 +170,7 @@ fn foo(a$0) {
#[test]
fn only_fn_like_macros() {
check(
check_empty(
r#"
macro_rules! m { ($e:expr) => { $e } }
@ -190,7 +190,7 @@ fn foo() {
#[test]
fn in_simple_macro_call() {
check(
check_empty(
r#"
macro_rules! m { ($e:expr) => { $e } }
enum E { X }
@ -210,7 +210,7 @@ fn foo() {
#[test]
fn omits_private_fields_pat() {
check(
check_empty(
r#"
mod foo {
pub struct Record { pub field: i32, _field: i32 }
@ -235,32 +235,9 @@ fn outer() {
)
}
// #[test]
// fn only_shows_ident_completion() {
// check_edit(
// "Foo",
// r#"
// struct Foo(i32);
// fn main() {
// match Foo(92) {
// a$0(92) => (),
// }
// }
// "#,
// r#"
// struct Foo(i32);
// fn main() {
// match Foo(92) {
// Foo(92) => (),
// }
// }
// "#,
// );
// }
#[test]
fn completes_self_pats() {
check(
check_empty(
r#"
struct Foo(i32);
impl Foo {
@ -282,35 +259,33 @@ impl Foo {
}
#[test]
fn completes_qualified_variant() {
fn enum_qualified() {
// FIXME: Don't show functions, they aren't patterns
check(
r#"
enum Foo {
Bar { baz: i32 }
impl Enum {
type AssocType = ();
const ASSOC_CONST: () = ();
fn assoc_fn() {}
}
impl Foo {
fn foo() {
match {Foo::Bar { baz: 0 }} {
B$0
}
}
fn func() {
if let Enum::$0 = unknown {}
}
"#,
"#,
expect![[r#"
kw mut
bn Self::Bar Self::Bar { baz$1 }$0
ev Self::Bar { baz: i32 }
bn Foo::Bar Foo::Bar { baz$1 }$0
ev Foo::Bar { baz: i32 }
sp Self
en Foo
ev TupleV() (u32)
ev RecordV { field: u32 }
ev UnitV ()
ct ASSOC_CONST const ASSOC_CONST: () = ();
fn assoc_fn() fn()
ta AssocType type AssocType = ();
"#]],
)
);
}
#[test]
fn completes_in_record_field_pat() {
check(
check_empty(
r#"
struct Foo { bar: Bar }
struct Bar(u32);
@ -328,7 +303,7 @@ fn outer(Foo { bar: $0 }: Foo) {}
#[test]
fn skips_in_record_field_pat_name() {
check(
check_empty(
r#"
struct Foo { bar: Bar }
struct Bar(u32);

View File

@ -1,10 +1,10 @@
//! Completion tests for predicates and bounds.
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) {
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)
}
@ -27,6 +27,7 @@ struct Foo<'lt, T, const C: usize> where $0 {}
st Foo<>
st Unit
ma makro!() #[macro_export] macro_rules! makro
un Union
ma makro!() #[macro_export] macro_rules! makro
bt u32
"##]],
@ -107,6 +108,7 @@ struct Foo<'lt, T, const C: usize> where for<'a> $0 {}
st Foo<>
st Unit
ma makro!() #[macro_export] macro_rules! makro
un Union
ma makro!() #[macro_export] macro_rules! makro
bt u32
"##]],
@ -130,10 +132,11 @@ impl Record {
en Enum
st Record
st Tuple
ma makro!() #[macro_export] macro_rules! makro
md module
st Unit
ma makro!() #[macro_export] macro_rules! makro
un Union
ma makro!() #[macro_export] macro_rules! makro
bt u32
"##]],
);

View File

@ -1,35 +1,22 @@
//! Completion tests for type position.
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) {
let base = 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 {}
"#;
let actual = completion_list(&format!("{}\n{}", base, ra_fixture));
fn check(ra_fixture: &str, expect: Expect) {
let actual = completion_list(&format!("{}\n{}", BASE_ITEMS_FIXTURE, ra_fixture));
expect.assert_eq(&actual)
}
#[test]
fn record_field_ty() {
check_with(
check(
r#"
struct Foo<'lt, T, const C: usize> {
f: $0
}
"#,
expect![[r#"
expect![[r##"
kw self
kw super
kw crate
@ -42,19 +29,21 @@ struct Foo<'lt, T, const C: usize> {
md module
st Foo<>
st Unit
ma makro!() macro_rules! makro
ma makro!() #[macro_export] macro_rules! makro
un Union
ma makro!() #[macro_export] macro_rules! makro
bt u32
"#]],
"##]],
)
}
#[test]
fn tuple_struct_field() {
check_with(
check(
r#"
struct Foo<'lt, T, const C: usize>(f$0);
"#,
expect![[r#"
expect![[r##"
kw pub(crate)
kw pub
kw self
@ -69,19 +58,21 @@ struct Foo<'lt, T, const C: usize>(f$0);
md module
st Foo<>
st Unit
ma makro!() macro_rules! makro
ma makro!() #[macro_export] macro_rules! makro
un Union
ma makro!() #[macro_export] macro_rules! makro
bt u32
"#]],
"##]],
)
}
#[test]
fn fn_return_type() {
check_with(
check(
r#"
fn x<'lt, T, const C: usize>() -> $0
"#,
expect![[r#"
expect![[r##"
kw self
kw super
kw crate
@ -92,22 +83,24 @@ fn x<'lt, T, const C: usize>() -> $0
st Tuple
md module
st Unit
ma makro!() macro_rules! makro
ma makro!() #[macro_export] macro_rules! makro
un Union
ma makro!() #[macro_export] macro_rules! makro
bt u32
"#]],
"##]],
);
}
#[test]
fn body_type_pos() {
check_with(
check(
r#"
fn foo<'lt, T, const C: usize>() {
let local = ();
let _: $0;
}
"#,
expect![[r#"
expect![[r##"
kw self
kw super
kw crate
@ -118,31 +111,35 @@ fn foo<'lt, T, const C: usize>() {
st Tuple
md module
st Unit
ma makro!() macro_rules! makro
ma makro!() #[macro_export] macro_rules! makro
un Union
ma makro!() #[macro_export] macro_rules! makro
bt u32
"#]],
"##]],
);
check_with(
check(
r#"
fn foo<'lt, T, const C: usize>() {
let local = ();
let _: self::$0;
}
"#,
expect![[r#"
expect![[r##"
tt Trait
en Enum
st Record
st Tuple
md module
st Unit
"#]],
ma makro!() #[macro_export] macro_rules! makro
un Union
"##]],
);
}
#[test]
fn completes_types_and_const_in_arg_list() {
check_with(
check(
r#"
trait Trait2 {
type Foo;
@ -150,7 +147,7 @@ trait Trait2 {
fn foo<'lt, T: Trait2<$0>, const CONST_PARAM: usize>(_: T) {}
"#,
expect![[r#"
expect![[r##"
kw self
kw super
kw crate
@ -161,15 +158,17 @@ fn foo<'lt, T: Trait2<$0>, const CONST_PARAM: usize>(_: T) {}
en Enum
st Record
st Tuple
tt Trait2
md module
st Unit
ma makro!() #[macro_export] macro_rules! makro
tt Trait2
un Union
ct CONST
ma makro!() macro_rules! makro
ma makro!() #[macro_export] macro_rules! makro
bt u32
"#]],
"##]],
);
check_with(
check(
r#"
trait Trait2 {
type Foo;
@ -177,15 +176,34 @@ trait Trait2 {
fn foo<'lt, T: Trait2<self::$0>, const CONST_PARAM: usize>(_: T) {}
"#,
expect![[r#"
expect![[r##"
tt Trait
en Enum
st Record
st Tuple
tt Trait2
md module
st Unit
ma makro!() #[macro_export] macro_rules! makro
tt Trait2
un Union
ct CONST
"##]],
);
}
#[test]
fn enum_qualified() {
check(
r#"
impl Enum {
type AssocType = ();
const ASSOC_CONST: () = ();
fn assoc_fn() {}
}
fn func(_: Enum::$0) {}
"#,
expect![[r#"
ta AssocType type AssocType = ();
"#]],
);
}