mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 13:25:09 +00:00
Move out completion pattern tests
This commit is contained in:
parent
c2aa7782d6
commit
f835279b3a
5 changed files with 349 additions and 467 deletions
|
@ -372,28 +372,6 @@ fn quux() -> i32 {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_mut_in_ref_and_in_fn_parameters_list() {
|
|
||||||
check(
|
|
||||||
r"fn my_fn(&$0) {}",
|
|
||||||
expect![[r#"
|
|
||||||
kw mut
|
|
||||||
"#]],
|
|
||||||
);
|
|
||||||
check(
|
|
||||||
r"fn my_fn($0) {}",
|
|
||||||
expect![[r#"
|
|
||||||
kw mut
|
|
||||||
"#]],
|
|
||||||
);
|
|
||||||
check(
|
|
||||||
r"fn my_fn() { let &$0 }",
|
|
||||||
expect![[r#"
|
|
||||||
kw mut
|
|
||||||
"#]],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn no_keyword_completion_in_comments() {
|
fn no_keyword_completion_in_comments() {
|
||||||
cov_mark::check!(no_keyword_completion_in_comments);
|
cov_mark::check!(no_keyword_completion_in_comments);
|
||||||
|
|
|
@ -55,398 +55,3 @@ pub(crate) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use expect_test::{expect, Expect};
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
tests::{check_edit, filtered_completion_list},
|
|
||||||
CompletionKind,
|
|
||||||
};
|
|
||||||
|
|
||||||
fn check(ra_fixture: &str, expect: Expect) {
|
|
||||||
let actual = filtered_completion_list(ra_fixture, CompletionKind::Reference);
|
|
||||||
expect.assert_eq(&actual)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn check_snippet(ra_fixture: &str, expect: Expect) {
|
|
||||||
let actual = filtered_completion_list(ra_fixture, CompletionKind::Snippet);
|
|
||||||
expect.assert_eq(&actual)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn completes_enum_variants_and_modules() {
|
|
||||||
check(
|
|
||||||
r#"
|
|
||||||
enum E { X }
|
|
||||||
use self::E::X;
|
|
||||||
const Z: E = E::X;
|
|
||||||
mod m {}
|
|
||||||
|
|
||||||
static FOO: E = E::X;
|
|
||||||
struct Bar { f: u32 }
|
|
||||||
|
|
||||||
fn foo() {
|
|
||||||
match E::X { a$0 }
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
expect![[r#"
|
|
||||||
en E
|
|
||||||
ct Z
|
|
||||||
st Bar
|
|
||||||
ev X
|
|
||||||
md m
|
|
||||||
"#]],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn does_not_complete_non_fn_macros() {
|
|
||||||
check(
|
|
||||||
r#"
|
|
||||||
macro_rules! m { ($e:expr) => { $e } }
|
|
||||||
enum E { X }
|
|
||||||
|
|
||||||
#[rustc_builtin_macro]
|
|
||||||
macro Clone {}
|
|
||||||
|
|
||||||
fn foo() {
|
|
||||||
match E::X { $0 }
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
expect![[r#"
|
|
||||||
ev E::X ()
|
|
||||||
en E
|
|
||||||
ma m!(…) macro_rules! m
|
|
||||||
"#]],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn completes_in_simple_macro_call() {
|
|
||||||
check(
|
|
||||||
r#"
|
|
||||||
macro_rules! m { ($e:expr) => { $e } }
|
|
||||||
enum E { X }
|
|
||||||
|
|
||||||
fn foo() {
|
|
||||||
m!(match E::X { a$0 })
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
expect![[r#"
|
|
||||||
ev E::X ()
|
|
||||||
en E
|
|
||||||
ma m!(…) macro_rules! m
|
|
||||||
"#]],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn completes_in_irrefutable_let() {
|
|
||||||
check(
|
|
||||||
r#"
|
|
||||||
enum E { X }
|
|
||||||
use self::E::X;
|
|
||||||
const Z: E = E::X;
|
|
||||||
mod m {}
|
|
||||||
|
|
||||||
static FOO: E = E::X;
|
|
||||||
struct Bar { f: u32 }
|
|
||||||
|
|
||||||
fn foo() {
|
|
||||||
let a$0
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
expect![[r#"
|
|
||||||
st Bar
|
|
||||||
"#]],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn completes_in_param() {
|
|
||||||
check(
|
|
||||||
r#"
|
|
||||||
enum E { X }
|
|
||||||
|
|
||||||
static FOO: E = E::X;
|
|
||||||
struct Bar { f: u32 }
|
|
||||||
|
|
||||||
fn foo(a$0) {
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
expect![[r#"
|
|
||||||
st Bar
|
|
||||||
"#]],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn completes_pat_in_let() {
|
|
||||||
check_snippet(
|
|
||||||
r#"
|
|
||||||
struct Bar { f: u32 }
|
|
||||||
|
|
||||||
fn foo() {
|
|
||||||
let a$0
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
expect![[r#"
|
|
||||||
bn Bar Bar { f$1 }$0
|
|
||||||
"#]],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn completes_param_pattern() {
|
|
||||||
check_snippet(
|
|
||||||
r#"
|
|
||||||
struct Foo { bar: String, baz: String }
|
|
||||||
struct Bar(String, String);
|
|
||||||
struct Baz;
|
|
||||||
fn outer(a$0) {}
|
|
||||||
"#,
|
|
||||||
expect![[r#"
|
|
||||||
bn Foo Foo { bar$1, baz$2 }: Foo$0
|
|
||||||
bn Bar Bar($1, $2): Bar$0
|
|
||||||
"#]],
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn completes_let_pattern() {
|
|
||||||
check_snippet(
|
|
||||||
r#"
|
|
||||||
struct Foo { bar: String, baz: String }
|
|
||||||
struct Bar(String, String);
|
|
||||||
struct Baz;
|
|
||||||
fn outer() {
|
|
||||||
let a$0
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
expect![[r#"
|
|
||||||
bn Foo Foo { bar$1, baz$2 }$0
|
|
||||||
bn Bar Bar($1, $2)$0
|
|
||||||
"#]],
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn completes_refutable_pattern() {
|
|
||||||
check_snippet(
|
|
||||||
r#"
|
|
||||||
struct Foo { bar: i32, baz: i32 }
|
|
||||||
struct Bar(String, String);
|
|
||||||
struct Baz;
|
|
||||||
fn outer() {
|
|
||||||
match () {
|
|
||||||
a$0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
expect![[r#"
|
|
||||||
bn Foo Foo { bar$1, baz$2 }$0
|
|
||||||
bn Bar Bar($1, $2)$0
|
|
||||||
"#]],
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn omits_private_fields_pat() {
|
|
||||||
check_snippet(
|
|
||||||
r#"
|
|
||||||
mod foo {
|
|
||||||
pub struct Foo { pub bar: i32, baz: i32 }
|
|
||||||
pub struct Bar(pub String, String);
|
|
||||||
pub struct Invisible(String, String);
|
|
||||||
}
|
|
||||||
use foo::*;
|
|
||||||
|
|
||||||
fn outer() {
|
|
||||||
match () {
|
|
||||||
a$0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
expect![[r#"
|
|
||||||
bn Foo Foo { bar$1, .. }$0
|
|
||||||
bn Bar Bar($1, ..)$0
|
|
||||||
"#]],
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[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_snippet(
|
|
||||||
r#"
|
|
||||||
struct Foo(i32);
|
|
||||||
impl Foo {
|
|
||||||
fn foo() {
|
|
||||||
match () {
|
|
||||||
a$0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
expect![[r#"
|
|
||||||
bn Self Self($1)$0
|
|
||||||
bn Foo Foo($1)$0
|
|
||||||
"#]],
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn completes_qualified_variant() {
|
|
||||||
check_snippet(
|
|
||||||
r#"
|
|
||||||
enum Foo {
|
|
||||||
Bar { baz: i32 }
|
|
||||||
}
|
|
||||||
impl Foo {
|
|
||||||
fn foo() {
|
|
||||||
match {Foo::Bar { baz: 0 }} {
|
|
||||||
B$0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
expect![[r#"
|
|
||||||
bn Self::Bar Self::Bar { baz$1 }$0
|
|
||||||
bn Foo::Bar Foo::Bar { baz$1 }$0
|
|
||||||
"#]],
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn completes_enum_variant_matcharm() {
|
|
||||||
check(
|
|
||||||
r#"
|
|
||||||
enum Foo { Bar, Baz, Quux }
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let foo = Foo::Quux;
|
|
||||||
match foo { Qu$0 }
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
expect![[r#"
|
|
||||||
ev Foo::Bar ()
|
|
||||||
ev Foo::Baz ()
|
|
||||||
ev Foo::Quux ()
|
|
||||||
en Foo
|
|
||||||
"#]],
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn completes_enum_variant_matcharm_ref() {
|
|
||||||
check(
|
|
||||||
r#"
|
|
||||||
enum Foo { Bar, Baz, Quux }
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let foo = Foo::Quux;
|
|
||||||
match &foo { Qu$0 }
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
expect![[r#"
|
|
||||||
ev Foo::Bar ()
|
|
||||||
ev Foo::Baz ()
|
|
||||||
ev Foo::Quux ()
|
|
||||||
en Foo
|
|
||||||
"#]],
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn completes_enum_variant_iflet() {
|
|
||||||
check(
|
|
||||||
r#"
|
|
||||||
enum Foo { Bar, Baz, Quux }
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let foo = Foo::Quux;
|
|
||||||
if let Qu$0 = foo { }
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
expect![[r#"
|
|
||||||
ev Foo::Bar ()
|
|
||||||
ev Foo::Baz ()
|
|
||||||
ev Foo::Quux ()
|
|
||||||
en Foo
|
|
||||||
"#]],
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn completes_enum_variant_impl() {
|
|
||||||
check(
|
|
||||||
r#"
|
|
||||||
enum Foo { Bar, Baz, Quux }
|
|
||||||
impl Foo {
|
|
||||||
fn foo() { match Foo::Bar { Q$0 } }
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
expect![[r#"
|
|
||||||
ev Self::Bar ()
|
|
||||||
ev Self::Baz ()
|
|
||||||
ev Self::Quux ()
|
|
||||||
ev Foo::Bar ()
|
|
||||||
ev Foo::Baz ()
|
|
||||||
ev Foo::Quux ()
|
|
||||||
sp Self
|
|
||||||
en Foo
|
|
||||||
"#]],
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn completes_in_record_field_pat() {
|
|
||||||
check_snippet(
|
|
||||||
r#"
|
|
||||||
struct Foo { bar: Bar }
|
|
||||||
struct Bar(u32);
|
|
||||||
fn outer(Foo { bar: $0 }: Foo) {}
|
|
||||||
"#,
|
|
||||||
expect![[r#"
|
|
||||||
bn Foo Foo { bar$1 }$0
|
|
||||||
bn Bar Bar($1)$0
|
|
||||||
"#]],
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn skips_in_record_field_pat_name() {
|
|
||||||
check_snippet(
|
|
||||||
r#"
|
|
||||||
struct Foo { bar: Bar }
|
|
||||||
struct Bar(u32);
|
|
||||||
fn outer(Foo { bar$0 }: Foo) {}
|
|
||||||
"#,
|
|
||||||
expect![[r#""#]],
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -134,56 +134,6 @@ fn foo() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn bind_pat_and_path_ignore_at() {
|
|
||||||
check(
|
|
||||||
r#"
|
|
||||||
enum Enum { A, B }
|
|
||||||
fn quux(x: Option<Enum>) {
|
|
||||||
match x {
|
|
||||||
None => (),
|
|
||||||
Some(en$0 @ Enum::A) => (),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
expect![[r#""#]],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn bind_pat_and_path_ignore_ref() {
|
|
||||||
check(
|
|
||||||
r#"
|
|
||||||
enum Enum { A, B }
|
|
||||||
fn quux(x: Option<Enum>) {
|
|
||||||
match x {
|
|
||||||
None => (),
|
|
||||||
Some(ref en$0) => (),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
expect![[r#""#]],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn bind_pat_and_path() {
|
|
||||||
check(
|
|
||||||
r#"
|
|
||||||
enum Enum { A, B }
|
|
||||||
fn quux(x: Option<Enum>) {
|
|
||||||
match x {
|
|
||||||
None => (),
|
|
||||||
Some(En$0) => (),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
expect![[r#"
|
|
||||||
en Enum
|
|
||||||
"#]],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn completes_bindings_from_let() {
|
fn completes_bindings_from_let() {
|
||||||
check(
|
check(
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
mod item_list;
|
mod item_list;
|
||||||
mod use_tree;
|
mod use_tree;
|
||||||
mod items;
|
mod items;
|
||||||
|
mod pattern;
|
||||||
|
|
||||||
use hir::{PrefixKind, Semantics};
|
use hir::{PrefixKind, Semantics};
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
|
|
348
crates/ide_completion/src/tests/pattern.rs
Normal file
348
crates/ide_completion/src/tests/pattern.rs
Normal file
|
@ -0,0 +1,348 @@
|
||||||
|
//! Completions tests for pattern position.
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {}
|
||||||
|
|
||||||
|
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));
|
||||||
|
expect.assert_eq(&actual)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ident_rebind_pat() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
fn quux() {
|
||||||
|
let en$0 @ x
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
kw mut
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ident_ref_pat() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
fn quux() {
|
||||||
|
let ref en$0
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
kw mut
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
check(
|
||||||
|
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
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
fn quux() {
|
||||||
|
let ref mut en$0
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
kw mut
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
fn quux() {
|
||||||
|
let ref mut en$0 @ x
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
kw mut
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ref_pat() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
fn quux() {
|
||||||
|
let &en$0
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
kw mut
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
// FIXME mut is already here, don't complete it again
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
fn quux() {
|
||||||
|
let &mut en$0
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
kw mut
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn refutable() {
|
||||||
|
check_with(
|
||||||
|
r#"
|
||||||
|
fn foo() {
|
||||||
|
if let a$0
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
kw mut
|
||||||
|
bn Record Record { field$1 }$0
|
||||||
|
st Record
|
||||||
|
en Enum
|
||||||
|
bn Tuple Tuple($1)$0
|
||||||
|
st Tuple
|
||||||
|
md module
|
||||||
|
bn TupleV TupleV($1)$0
|
||||||
|
ev TupleV
|
||||||
|
st Unit
|
||||||
|
ct CONST
|
||||||
|
ma makro!(…) macro_rules! makro
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn irrefutable() {
|
||||||
|
check_with(
|
||||||
|
r#"
|
||||||
|
fn foo() {
|
||||||
|
let a$0
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
kw mut
|
||||||
|
bn Record Record { field$1 }$0
|
||||||
|
st Record
|
||||||
|
bn Tuple Tuple($1)$0
|
||||||
|
st Tuple
|
||||||
|
st Unit
|
||||||
|
ma makro!(…) macro_rules! makro
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn in_param() {
|
||||||
|
check_with(
|
||||||
|
r#"
|
||||||
|
fn foo(a$0) {
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
kw mut
|
||||||
|
bn Record Record { field$1 }: Record$0
|
||||||
|
st Record
|
||||||
|
bn Tuple Tuple($1): Tuple$0
|
||||||
|
st Tuple
|
||||||
|
st Unit
|
||||||
|
ma makro!(…) macro_rules! makro
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn only_fn_like_macros() {
|
||||||
|
check(
|
||||||
|
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() {
|
||||||
|
check(
|
||||||
|
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() {
|
||||||
|
check(
|
||||||
|
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 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(
|
||||||
|
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]
|
||||||
|
fn completes_qualified_variant() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
enum Foo {
|
||||||
|
Bar { baz: i32 }
|
||||||
|
}
|
||||||
|
impl Foo {
|
||||||
|
fn foo() {
|
||||||
|
match {Foo::Bar { baz: 0 }} {
|
||||||
|
B$0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
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
|
||||||
|
"#]],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn completes_in_record_field_pat() {
|
||||||
|
check(
|
||||||
|
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() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
struct Foo { bar: Bar }
|
||||||
|
struct Bar(u32);
|
||||||
|
fn outer(Foo { bar$0 }: Foo) {}
|
||||||
|
"#,
|
||||||
|
expect![[r#""#]],
|
||||||
|
)
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue