2021-07-15 14:27:01 +00:00
|
|
|
//! Completion tests for pattern position.
|
2021-06-21 11:48:25 +00:00
|
|
|
use expect_test::{expect, Expect};
|
|
|
|
|
2021-07-23 14:09:30 +00:00
|
|
|
use crate::tests::{completion_list, BASE_ITEMS_FIXTURE};
|
2021-06-21 11:48:25 +00:00
|
|
|
|
2021-07-23 15:02:39 +00:00
|
|
|
fn check_empty(ra_fixture: &str, expect: Expect) {
|
2021-06-21 11:48:25 +00:00
|
|
|
let actual = completion_list(ra_fixture);
|
|
|
|
expect.assert_eq(&actual)
|
|
|
|
}
|
|
|
|
|
2021-07-23 15:02:39 +00:00
|
|
|
fn check(ra_fixture: &str, expect: Expect) {
|
2021-07-23 14:09:30 +00:00
|
|
|
let actual = completion_list(&format!("{}\n{}", BASE_ITEMS_FIXTURE, ra_fixture));
|
2021-06-21 11:48:25 +00:00
|
|
|
expect.assert_eq(&actual)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn ident_rebind_pat() {
|
2021-07-23 15:02:39 +00:00
|
|
|
check_empty(
|
2021-06-21 11:48:25 +00:00
|
|
|
r#"
|
|
|
|
fn quux() {
|
|
|
|
let en$0 @ x
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
kw mut
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn ident_ref_pat() {
|
2021-07-23 15:02:39 +00:00
|
|
|
check_empty(
|
2021-06-21 11:48:25 +00:00
|
|
|
r#"
|
|
|
|
fn quux() {
|
|
|
|
let ref en$0
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
kw mut
|
|
|
|
"#]],
|
|
|
|
);
|
2021-07-23 15:02:39 +00:00
|
|
|
check_empty(
|
2021-06-21 11:48:25 +00:00
|
|
|
r#"
|
|
|
|
fn quux() {
|
|
|
|
let ref en$0 @ x
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
kw mut
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn ident_ref_mut_pat() {
|
|
|
|
// FIXME mut is already here, don't complete it again
|
2021-07-23 15:02:39 +00:00
|
|
|
check_empty(
|
2021-06-21 11:48:25 +00:00
|
|
|
r#"
|
|
|
|
fn quux() {
|
|
|
|
let ref mut en$0
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
kw mut
|
|
|
|
"#]],
|
|
|
|
);
|
2021-07-23 15:02:39 +00:00
|
|
|
check_empty(
|
2021-06-21 11:48:25 +00:00
|
|
|
r#"
|
|
|
|
fn quux() {
|
|
|
|
let ref mut en$0 @ x
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
kw mut
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn ref_pat() {
|
2021-07-23 15:02:39 +00:00
|
|
|
check_empty(
|
2021-06-21 11:48:25 +00:00
|
|
|
r#"
|
|
|
|
fn quux() {
|
|
|
|
let &en$0
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
kw mut
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
// FIXME mut is already here, don't complete it again
|
2021-07-23 15:02:39 +00:00
|
|
|
check_empty(
|
2021-06-21 11:48:25 +00:00
|
|
|
r#"
|
|
|
|
fn quux() {
|
|
|
|
let &mut en$0
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
kw mut
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn refutable() {
|
2021-07-23 15:02:39 +00:00
|
|
|
check(
|
2021-06-21 11:48:25 +00:00
|
|
|
r#"
|
|
|
|
fn foo() {
|
|
|
|
if let a$0
|
|
|
|
}
|
|
|
|
"#,
|
2021-06-23 17:13:24 +00:00
|
|
|
expect![[r##"
|
2021-06-21 11:48:25 +00:00
|
|
|
kw mut
|
2021-06-23 16:37:47 +00:00
|
|
|
en Enum
|
2021-06-21 11:48:25 +00:00
|
|
|
bn Record Record { field$1 }$0
|
|
|
|
st Record
|
|
|
|
bn Tuple Tuple($1)$0
|
|
|
|
st Tuple
|
|
|
|
md module
|
2021-06-23 17:13:24 +00:00
|
|
|
st Unit
|
|
|
|
ma makro!(…) #[macro_export] macro_rules! makro
|
2021-06-21 11:48:25 +00:00
|
|
|
bn TupleV TupleV($1)$0
|
|
|
|
ev TupleV
|
|
|
|
ct CONST
|
2021-06-23 17:13:24 +00:00
|
|
|
"##]],
|
2021-06-21 11:48:25 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn irrefutable() {
|
2021-07-23 15:02:39 +00:00
|
|
|
check(
|
2021-06-21 11:48:25 +00:00
|
|
|
r#"
|
|
|
|
fn foo() {
|
|
|
|
let a$0
|
|
|
|
}
|
|
|
|
"#,
|
2021-06-23 17:13:24 +00:00
|
|
|
expect![[r##"
|
2021-06-21 11:48:25 +00:00
|
|
|
kw mut
|
|
|
|
bn Record Record { field$1 }$0
|
|
|
|
st Record
|
|
|
|
bn Tuple Tuple($1)$0
|
|
|
|
st Tuple
|
|
|
|
st Unit
|
2021-06-23 17:13:24 +00:00
|
|
|
ma makro!(…) #[macro_export] macro_rules! makro
|
|
|
|
"##]],
|
2021-06-21 11:48:25 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn in_param() {
|
2021-07-23 15:02:39 +00:00
|
|
|
check(
|
2021-06-21 11:48:25 +00:00
|
|
|
r#"
|
|
|
|
fn foo(a$0) {
|
|
|
|
}
|
|
|
|
"#,
|
2021-06-23 17:13:24 +00:00
|
|
|
expect![[r##"
|
2021-06-21 11:48:25 +00:00
|
|
|
kw mut
|
|
|
|
bn Record Record { field$1 }: Record$0
|
|
|
|
st Record
|
|
|
|
bn Tuple Tuple($1): Tuple$0
|
|
|
|
st Tuple
|
|
|
|
st Unit
|
2021-06-23 17:13:24 +00:00
|
|
|
ma makro!(…) #[macro_export] macro_rules! makro
|
|
|
|
"##]],
|
2021-11-05 17:39:36 +00:00
|
|
|
);
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
fn foo(a$0: Tuple) {
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r##"
|
|
|
|
kw mut
|
|
|
|
bn Record Record { field$1 }$0
|
|
|
|
st Record
|
|
|
|
bn Tuple Tuple($1)$0
|
|
|
|
st Tuple
|
|
|
|
st Unit
|
|
|
|
ma makro!(…) #[macro_export] macro_rules! makro
|
|
|
|
"##]],
|
2021-06-21 11:48:25 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn only_fn_like_macros() {
|
2021-07-23 15:02:39 +00:00
|
|
|
check_empty(
|
2021-06-21 11:48:25 +00:00
|
|
|
r#"
|
|
|
|
macro_rules! m { ($e:expr) => { $e } }
|
|
|
|
|
|
|
|
#[rustc_builtin_macro]
|
|
|
|
macro Clone {}
|
|
|
|
|
|
|
|
fn foo() {
|
|
|
|
let x$0
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
kw mut
|
|
|
|
ma m!(…) macro_rules! m
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn in_simple_macro_call() {
|
2021-07-23 15:02:39 +00:00
|
|
|
check_empty(
|
2021-06-21 11:48:25 +00:00
|
|
|
r#"
|
|
|
|
macro_rules! m { ($e:expr) => { $e } }
|
|
|
|
enum E { X }
|
|
|
|
|
|
|
|
fn foo() {
|
|
|
|
m!(match E::X { a$0 })
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
kw mut
|
|
|
|
ev E::X ()
|
|
|
|
en E
|
|
|
|
ma m!(…) macro_rules! m
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn omits_private_fields_pat() {
|
2021-07-23 15:02:39 +00:00
|
|
|
check_empty(
|
2021-06-21 11:48:25 +00:00
|
|
|
r#"
|
|
|
|
mod foo {
|
|
|
|
pub struct Record { pub field: i32, _field: i32 }
|
|
|
|
pub struct Tuple(pub u32, u32);
|
|
|
|
pub struct Invisible(u32, u32);
|
|
|
|
}
|
|
|
|
use foo::*;
|
|
|
|
|
|
|
|
fn outer() {
|
|
|
|
if let a$0
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
kw mut
|
|
|
|
bn Record Record { field$1, .. }$0
|
|
|
|
st Record
|
|
|
|
bn Tuple Tuple($1, ..)$0
|
|
|
|
st Tuple
|
|
|
|
st Invisible
|
|
|
|
md foo
|
|
|
|
"#]],
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn completes_self_pats() {
|
2021-07-23 15:02:39 +00:00
|
|
|
check_empty(
|
2021-06-21 11:48:25 +00:00
|
|
|
r#"
|
|
|
|
struct Foo(i32);
|
|
|
|
impl Foo {
|
|
|
|
fn foo() {
|
|
|
|
match Foo(0) {
|
|
|
|
a$0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
kw mut
|
|
|
|
bn Self Self($1)$0
|
|
|
|
sp Self
|
|
|
|
bn Foo Foo($1)$0
|
|
|
|
st Foo
|
|
|
|
"#]],
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-07-23 15:02:39 +00:00
|
|
|
fn enum_qualified() {
|
|
|
|
// FIXME: Don't show functions, they aren't patterns
|
2021-06-21 11:48:25 +00:00
|
|
|
check(
|
|
|
|
r#"
|
2021-07-23 15:02:39 +00:00
|
|
|
impl Enum {
|
|
|
|
type AssocType = ();
|
|
|
|
const ASSOC_CONST: () = ();
|
|
|
|
fn assoc_fn() {}
|
2021-06-21 11:48:25 +00:00
|
|
|
}
|
2021-07-23 15:02:39 +00:00
|
|
|
fn func() {
|
|
|
|
if let Enum::$0 = unknown {}
|
2021-06-21 11:48:25 +00:00
|
|
|
}
|
2021-07-23 15:02:39 +00:00
|
|
|
"#,
|
2021-06-21 11:48:25 +00:00
|
|
|
expect![[r#"
|
2021-07-23 15:02:39 +00:00
|
|
|
ev TupleV(…) (u32)
|
2021-11-24 15:01:33 +00:00
|
|
|
ev RecordV {field: u32}
|
2021-07-23 15:02:39 +00:00
|
|
|
ev UnitV ()
|
2021-11-24 15:01:33 +00:00
|
|
|
ct ASSOC_CONST const ASSOC_CONST: ();
|
2021-07-23 15:02:39 +00:00
|
|
|
fn assoc_fn() fn()
|
2021-11-24 15:01:33 +00:00
|
|
|
ta AssocType type AssocType;
|
2021-06-21 11:48:25 +00:00
|
|
|
"#]],
|
2021-07-23 15:02:39 +00:00
|
|
|
);
|
2021-06-21 11:48:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn completes_in_record_field_pat() {
|
2021-07-23 15:02:39 +00:00
|
|
|
check_empty(
|
2021-06-21 11:48:25 +00:00
|
|
|
r#"
|
|
|
|
struct Foo { bar: Bar }
|
|
|
|
struct Bar(u32);
|
|
|
|
fn outer(Foo { bar: $0 }: Foo) {}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
kw mut
|
|
|
|
bn Foo Foo { bar$1 }$0
|
|
|
|
st Foo
|
|
|
|
bn Bar Bar($1)$0
|
|
|
|
st Bar
|
|
|
|
"#]],
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn skips_in_record_field_pat_name() {
|
2021-07-23 15:02:39 +00:00
|
|
|
check_empty(
|
2021-06-21 11:48:25 +00:00
|
|
|
r#"
|
|
|
|
struct Foo { bar: Bar }
|
|
|
|
struct Bar(u32);
|
|
|
|
fn outer(Foo { bar$0 }: Foo) {}
|
|
|
|
"#,
|
|
|
|
expect![[r#""#]],
|
|
|
|
)
|
|
|
|
}
|
2021-08-14 16:18:18 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn completes_in_fn_param() {
|
|
|
|
check_empty(
|
|
|
|
r#"
|
|
|
|
struct Foo { bar: Bar }
|
|
|
|
struct Bar(u32);
|
|
|
|
fn foo($0) {}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
kw mut
|
|
|
|
bn Foo Foo { bar$1 }: Foo$0
|
|
|
|
st Foo
|
|
|
|
bn Bar Bar($1): Bar$0
|
|
|
|
st Bar
|
|
|
|
"#]],
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn completes_in_closure_param() {
|
|
|
|
check_empty(
|
|
|
|
r#"
|
|
|
|
struct Foo { bar: Bar }
|
|
|
|
struct Bar(u32);
|
|
|
|
fn foo() {
|
|
|
|
|$0| {};
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
kw mut
|
|
|
|
bn Foo Foo { bar$1 }$0
|
|
|
|
st Foo
|
|
|
|
bn Bar Bar($1)$0
|
|
|
|
st Bar
|
|
|
|
"#]],
|
|
|
|
)
|
|
|
|
}
|