From 18ad86fddac4c4315df168d84b714cc07b096e0c Mon Sep 17 00:00:00 2001 From: nathanwhit Date: Mon, 20 Apr 2020 15:29:53 -0400 Subject: Add tests for enum completion Adds tests for completion of enum variants in match arms, if-let statements, and basic expressions. --- .../src/completion/complete_unqualified_path.rs | 178 +++++++++++++++++++++ 1 file changed, 178 insertions(+) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/completion/complete_unqualified_path.rs b/crates/ra_ide/src/completion/complete_unqualified_path.rs index ffa3c01a7..b4da342b5 100644 --- a/crates/ra_ide/src/completion/complete_unqualified_path.rs +++ b/crates/ra_ide/src/completion/complete_unqualified_path.rs @@ -1130,4 +1130,182 @@ mod tests { "### ); } + #[test] + fn completes_enum_variant_matcharm() { + assert_debug_snapshot!( + do_reference_completion( + r" + enum Foo { + Bar, + Baz, + Quux + } + + fn main() { + let foo = Foo::Quux; + + match foo { + Qu<|> + } + } + " + ), + @r###" + [ + CompletionItem { + label: "Foo", + source_range: [248; 250), + delete: [248; 250), + insert: "Foo", + kind: Enum, + }, + CompletionItem { + label: "Foo::Bar", + source_range: [248; 250), + delete: [248; 250), + insert: "Foo::Bar", + kind: EnumVariant, + detail: "()", + }, + CompletionItem { + label: "Foo::Baz", + source_range: [248; 250), + delete: [248; 250), + insert: "Foo::Baz", + kind: EnumVariant, + detail: "()", + }, + CompletionItem { + label: "Foo::Quux", + source_range: [248; 250), + delete: [248; 250), + insert: "Foo::Quux", + kind: EnumVariant, + detail: "()", + }, + ] + "### + ) + } + + #[test] + fn completes_enum_variant_iflet() { + assert_debug_snapshot!( + do_reference_completion( + r" + enum Foo { + Bar, + Baz, + Quux + } + + fn main() { + let foo = Foo::Quux; + + if let Qu<|> = foo { + + } + } + " + ), + @r###" + [ + CompletionItem { + label: "Foo", + source_range: [219; 221), + delete: [219; 221), + insert: "Foo", + kind: Enum, + }, + CompletionItem { + label: "Foo::Bar", + source_range: [219; 221), + delete: [219; 221), + insert: "Foo::Bar", + kind: EnumVariant, + detail: "()", + }, + CompletionItem { + label: "Foo::Baz", + source_range: [219; 221), + delete: [219; 221), + insert: "Foo::Baz", + kind: EnumVariant, + detail: "()", + }, + CompletionItem { + label: "Foo::Quux", + source_range: [219; 221), + delete: [219; 221), + insert: "Foo::Quux", + kind: EnumVariant, + detail: "()", + }, + ] + "### + ) + } + + #[test] + fn completes_enum_variant_basic_expr() { + assert_debug_snapshot!( + do_reference_completion( + r" + enum Foo { + Bar, + Baz, + Quux + } + + fn main() { + let foo: Foo = Q<|> + } + " + ), + @r###" + [ + CompletionItem { + label: "Foo", + source_range: [185; 186), + delete: [185; 186), + insert: "Foo", + kind: Enum, + }, + CompletionItem { + label: "Foo::Bar", + source_range: [185; 186), + delete: [185; 186), + insert: "Foo::Bar", + kind: EnumVariant, + detail: "()", + }, + CompletionItem { + label: "Foo::Baz", + source_range: [185; 186), + delete: [185; 186), + insert: "Foo::Baz", + kind: EnumVariant, + detail: "()", + }, + CompletionItem { + label: "Foo::Quux", + source_range: [185; 186), + delete: [185; 186), + insert: "Foo::Quux", + kind: EnumVariant, + detail: "()", + }, + CompletionItem { + label: "main()", + source_range: [185; 186), + delete: [185; 186), + insert: "main()$0", + kind: Function, + lookup: "main", + detail: "fn main()", + }, + ] + "### + ) + } } -- cgit v1.2.3