Add a Union to the base item completion test fixture

This commit is contained in:
Lukas Wirth 2021-07-23 17:02:39 +02:00
parent 8de3f7ee53
commit 189440c7b5
7 changed files with 134 additions and 142 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

@ -1,11 +1,12 @@
//! 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;
@ -55,6 +56,7 @@ macro_rules! makro {}
#[rustc_builtin_macro]
pub macro Clone {}
fn function() {}
union Union { field: i32 }
"#;
pub(crate) const TEST_CONFIG: CompletionConfig = CompletionConfig {

View File

@ -70,6 +70,7 @@ impl Unit {
}
}
"#,
// `self` is in here twice, once as the module, once as the local
expect![[r##"
kw unsafe
kw fn
@ -114,12 +115,42 @@ impl Unit {
?? 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]
@ -247,3 +278,27 @@ fn quux(x: i32) {
"#]],
);
}
#[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

@ -28,6 +28,7 @@ impl Tra$0
md module
st Unit
ma makro!() #[macro_export] macro_rules! makro
un Union
ma makro!() #[macro_export] macro_rules! makro
bt u32
"##]],
@ -51,6 +52,7 @@ impl Trait for Str$0
md module
st Unit
ma makro!() #[macro_export] macro_rules! makro
un Union
ma makro!() #[macro_export] macro_rules! makro
bt u32
"##]],

View File

@ -3,19 +3,19 @@ use expect_test::{expect, Expect};
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) {
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

@ -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
"##]],
@ -133,6 +135,7 @@ impl Record {
md module
st Unit
ma makro!() #[macro_export] macro_rules! makro
un Union
ma makro!() #[macro_export] macro_rules! makro
bt u32
"##]],

View File

@ -3,14 +3,14 @@ use expect_test::{expect, Expect};
use crate::tests::{completion_list, BASE_ITEMS_FIXTURE};
fn check_with(ra_fixture: &str, expect: Expect) {
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
@ -30,6 +30,7 @@ struct Foo<'lt, T, const C: usize> {
st Foo<>
st Unit
ma makro!() #[macro_export] macro_rules! makro
un Union
ma makro!() #[macro_export] macro_rules! makro
bt u32
"##]],
@ -38,7 +39,7 @@ struct Foo<'lt, T, const C: usize> {
#[test]
fn tuple_struct_field() {
check_with(
check(
r#"
struct Foo<'lt, T, const C: usize>(f$0);
"#,
@ -58,6 +59,7 @@ struct Foo<'lt, T, const C: usize>(f$0);
st Foo<>
st Unit
ma makro!() #[macro_export] macro_rules! makro
un Union
ma makro!() #[macro_export] macro_rules! makro
bt u32
"##]],
@ -66,7 +68,7 @@ struct Foo<'lt, T, const C: usize>(f$0);
#[test]
fn fn_return_type() {
check_with(
check(
r#"
fn x<'lt, T, const C: usize>() -> $0
"#,
@ -82,6 +84,7 @@ fn x<'lt, T, const C: usize>() -> $0
md module
st Unit
ma makro!() #[macro_export] macro_rules! makro
un Union
ma makro!() #[macro_export] macro_rules! makro
bt u32
"##]],
@ -90,7 +93,7 @@ fn x<'lt, T, const C: usize>() -> $0
#[test]
fn body_type_pos() {
check_with(
check(
r#"
fn foo<'lt, T, const C: usize>() {
let local = ();
@ -109,11 +112,12 @@ fn foo<'lt, T, const C: usize>() {
md module
st Unit
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 = ();
@ -128,13 +132,14 @@ fn foo<'lt, T, const C: usize>() {
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;
@ -157,12 +162,13 @@ fn foo<'lt, T: Trait2<$0>, const CONST_PARAM: usize>(_: T) {}
st Unit
ma makro!() #[macro_export] macro_rules! makro
tt Trait2
un Union
ct CONST
ma makro!() #[macro_export] macro_rules! makro
bt u32
"##]],
);
check_with(
check(
r#"
trait Trait2 {
type Foo;
@ -179,7 +185,25 @@ fn foo<'lt, T: Trait2<self::$0>, const CONST_PARAM: usize>(_: T) {}
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 = ();
"#]],
);
}