Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-completion/src/tests/pattern.rs')
| -rw-r--r-- | crates/ide-completion/src/tests/pattern.rs | 137 |
1 files changed, 109 insertions, 28 deletions
diff --git a/crates/ide-completion/src/tests/pattern.rs b/crates/ide-completion/src/tests/pattern.rs index 7169209d81..63ccf9003b 100644 --- a/crates/ide-completion/src/tests/pattern.rs +++ b/crates/ide-completion/src/tests/pattern.rs @@ -1,7 +1,7 @@ //! Completion tests for pattern position. use expect_test::{expect, Expect}; -use crate::tests::{completion_list, BASE_ITEMS_FIXTURE}; +use crate::tests::{check_edit, completion_list, BASE_ITEMS_FIXTURE}; fn check_empty(ra_fixture: &str, expect: Expect) { let actual = completion_list(ra_fixture); @@ -127,15 +127,15 @@ fn foo() { expect![[r#" ct CONST en Enum - ma makro!(…) macro_rules! makro + ma makro!(…) macro_rules! makro md module st Record st Tuple st Unit ev TupleV - bn Record Record { field$1 }$0 - bn Tuple Tuple($1)$0 - bn TupleV TupleV($1)$0 + bn Record {…} Record { field$1 }$0 + bn Tuple(…) Tuple($1)$0 + bn TupleV(…) TupleV($1)$0 kw mut kw ref "#]], @@ -162,8 +162,9 @@ fn foo() { st Tuple st Unit ev Variant - bn Record Record { field$1 }$0 - bn Tuple Tuple($1)$0 + bn Record {…} Record { field$1 }$0 + bn Tuple(…) Tuple($1)$0 + bn Variant Variant$0 kw mut kw ref "#]], @@ -178,13 +179,13 @@ fn foo(a$0) { } "#, expect![[r#" - ma makro!(…) macro_rules! makro + ma makro!(…) macro_rules! makro md module st Record st Tuple st Unit - bn Record Record { field$1 }: Record$0 - bn Tuple Tuple($1): Tuple$0 + bn Record {…} Record { field$1 }: Record$0 + bn Tuple(…) Tuple($1): Tuple$0 kw mut kw ref "#]], @@ -195,13 +196,13 @@ fn foo(a$0: Tuple) { } "#, expect![[r#" - ma makro!(…) macro_rules! makro + ma makro!(…) macro_rules! makro md module st Record st Tuple st Unit - bn Record Record { field$1 }$0 - bn Tuple Tuple($1)$0 + bn Record {…} Record { field$1 }$0 + bn Tuple(…) Tuple($1)$0 kw mut kw ref "#]], @@ -243,6 +244,7 @@ fn foo() { expect![[r#" en E ma m!(…) macro_rules! m + bn E::X E::X$0 kw mut kw ref "#]], @@ -269,8 +271,8 @@ fn outer() { st Invisible st Record st Tuple - bn Record Record { field$1, .. }$0 - bn Tuple Tuple($1, ..)$0 + bn Record {…} Record { field$1, .. }$0 + bn Tuple(…) Tuple($1, ..)$0 kw mut kw ref "#]], @@ -293,8 +295,8 @@ impl Foo { expect![[r#" sp Self st Foo - bn Foo Foo($1)$0 - bn Self Self($1)$0 + bn Foo(…) Foo($1)$0 + bn Self(…) Self($1)$0 kw mut kw ref "#]], @@ -316,9 +318,9 @@ fn func() { "#, expect![[r#" ct ASSOC_CONST const ASSOC_CONST: () - ev RecordV {…} RecordV { field: u32 } - ev TupleV(…) TupleV(u32) - ev UnitV UnitV + bn RecordV {…} RecordV { field$1 }$0 + bn TupleV(…) TupleV($1)$0 + bn UnitV UnitV$0 "#]], ); } @@ -334,8 +336,8 @@ fn outer(Foo { bar: $0 }: Foo) {} expect![[r#" st Bar st Foo - bn Bar Bar($1)$0 - bn Foo Foo { bar$1 }$0 + bn Bar(…) Bar($1)$0 + bn Foo {…} Foo { bar$1 }$0 kw mut kw ref "#]], @@ -368,8 +370,8 @@ fn foo($0) {} expect![[r#" st Bar st Foo - bn Bar Bar($1): Bar$0 - bn Foo Foo { bar$1 }: Foo$0 + bn Bar(…) Bar($1): Bar$0 + bn Foo {…} Foo { bar$1 }: Foo$0 kw mut kw ref "#]], @@ -389,8 +391,8 @@ fn foo() { expect![[r#" st Bar st Foo - bn Bar Bar($1)$0 - bn Foo Foo { bar$1 }$0 + bn Bar(…) Bar($1)$0 + bn Foo {…} Foo { bar$1 }$0 kw mut kw ref "#]], @@ -443,7 +445,7 @@ fn foo() { } "#, expect![[r#" - ev TupleVariant TupleVariant + bn TupleVariant(…) TupleVariant($1)$0 "#]], ); check_empty( @@ -458,7 +460,86 @@ fn foo() { } "#, expect![[r#" - ev RecordVariant RecordVariant + bn RecordVariant {…} RecordVariant { field$1 }$0 + "#]], + ); +} + +#[test] +fn completes_enum_variant_pat() { + cov_mark::check!(enum_variant_pattern_path); + check_edit( + "RecordVariant {…}", + r#" +enum Enum { + RecordVariant { field: u32 } +} +fn foo() { + match (Enum::RecordVariant { field: 0 }) { + Enum::RecordV$0 + } +} +"#, + r#" +enum Enum { + RecordVariant { field: u32 } +} +fn foo() { + match (Enum::RecordVariant { field: 0 }) { + Enum::RecordVariant { field$1 }$0 + } +} +"#, + ); +} + +#[test] +fn completes_enum_variant_pat_escape() { + cov_mark::check!(enum_variant_pattern_path); + check_empty( + r#" +enum Enum { + A, + B { r#type: i32 }, + r#type, + r#struct { r#type: i32 }, +} +fn foo() { + match (Enum::A) { + $0 + } +} +"#, + expect![[r#" + en Enum + bn Enum::A Enum::A$0 + bn Enum::B {…} Enum::B { r#type$1 }$0 + bn Enum::struct {…} Enum::r#struct { r#type$1 }$0 + bn Enum::type Enum::r#type$0 + kw mut + kw ref + "#]], + ); + + check_empty( + r#" +enum Enum { + A, + B { r#type: i32 }, + r#type, + r#struct { r#type: i32 }, +} +fn foo() { + match (Enum::A) { + Enum::$0 + } +} +"#, + expect![[r#" + bn A A$0 + bn B {…} B { r#type$1 }$0 + bn struct {…} r#struct { r#type$1 }$0 + bn type r#type$0 "#]], ); } |