From 460423e66c7a8d48084813c0d592066b4bef3e85 Mon Sep 17 00:00:00 2001 From: Phil Ellison Date: Sun, 28 Jul 2019 11:35:48 +0100 Subject: Inline snapshots for all tests in presentation.rs --- crates/ra_ide_api/src/completion/presentation.rs | 209 +++++++++++++++------ ...ont_render_function_parens_if_already_call.snap | 24 --- ...r_function_parens_if_already_call_assoc_fn.snap | 16 -- ...m__dont_render_function_parens_in_use_item.snap | 16 -- ...n_item__inserts_parens_for_function_calls1.snap | 24 --- ...n_item__inserts_parens_for_function_calls2.snap | 24 --- ...n_item__inserts_parens_for_function_calls3.snap | 16 -- 7 files changed, 152 insertions(+), 177 deletions(-) delete mode 100644 crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_if_already_call.snap delete mode 100644 crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_if_already_call_assoc_fn.snap delete mode 100644 crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_in_use_item.snap delete mode 100644 crates/ra_ide_api/src/completion/snapshots/completion_item__inserts_parens_for_function_calls1.snap delete mode 100644 crates/ra_ide_api/src/completion/snapshots/completion_item__inserts_parens_for_function_calls2.snap delete mode 100644 crates/ra_ide_api/src/completion/snapshots/completion_item__inserts_parens_for_function_calls3.snap (limited to 'crates/ra_ide_api/src') diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs index 5cf55a496..fe7581adf 100644 --- a/crates/ra_ide_api/src/completion/presentation.rs +++ b/crates/ra_ide_api/src/completion/presentation.rs @@ -183,79 +183,174 @@ impl Completions { #[cfg(test)] mod tests { use test_utils::covers; + use crate::completion::{do_completion, CompletionItem, CompletionKind}; + use insta::assert_debug_snapshot_matches; - use crate::completion::{check_completion, CompletionKind}; - - fn check_reference_completion(code: &str, expected_completions: &str) { - check_completion(code, expected_completions, CompletionKind::Reference); + fn do_reference_completion(code: &str) -> Vec { + do_completion(code, CompletionKind::Reference) } #[test] fn inserts_parens_for_function_calls() { covers!(inserts_parens_for_function_calls); - check_reference_completion( - "inserts_parens_for_function_calls1", - r" - fn no_args() {} - fn main() { no_<|> } - ", + assert_debug_snapshot_matches!( + do_reference_completion( + r" + fn no_args() {} + fn main() { no_<|> } + " + ), +@r###" + ⋮[ + ⋮ CompletionItem { + ⋮ label: "main", + ⋮ source_range: [61; 64), + ⋮ delete: [61; 64), + ⋮ insert: "main()$0", + ⋮ kind: Function, + ⋮ detail: "fn main()", + ⋮ }, + ⋮ CompletionItem { + ⋮ label: "no_args", + ⋮ source_range: [61; 64), + ⋮ delete: [61; 64), + ⋮ insert: "no_args()$0", + ⋮ kind: Function, + ⋮ detail: "fn no_args()", + ⋮ }, + ⋮] + "### ); - check_reference_completion( - "inserts_parens_for_function_calls2", - r" - fn with_args(x: i32, y: String) {} - fn main() { with_<|> } - ", + assert_debug_snapshot_matches!( + do_reference_completion( + r" + fn with_args(x: i32, y: String) {} + fn main() { with_<|> } + " + ), +@r###" + ⋮[ + ⋮ CompletionItem { + ⋮ label: "main", + ⋮ source_range: [80; 85), + ⋮ delete: [80; 85), + ⋮ insert: "main()$0", + ⋮ kind: Function, + ⋮ detail: "fn main()", + ⋮ }, + ⋮ CompletionItem { + ⋮ label: "with_args", + ⋮ source_range: [80; 85), + ⋮ delete: [80; 85), + ⋮ insert: "with_args($0)", + ⋮ kind: Function, + ⋮ detail: "fn with_args(x: i32, y: String)", + ⋮ }, + ⋮] + "### + ); + assert_debug_snapshot_matches!( + do_reference_completion( + r" + struct S {} + impl S { + fn foo(&self) {} + } + fn bar(s: &S) { + s.f<|> + } + " + ), +@r###" + ⋮[ + ⋮ CompletionItem { + ⋮ label: "foo", + ⋮ source_range: [163; 164), + ⋮ delete: [163; 164), + ⋮ insert: "foo()$0", + ⋮ kind: Method, + ⋮ detail: "fn foo(&self)", + ⋮ }, + ⋮] + "### ); - check_reference_completion( - "inserts_parens_for_function_calls3", - r" - struct S {} - impl S { - fn foo(&self) {} - } - fn bar(s: &S) { - s.f<|> - } - ", - ) } #[test] fn dont_render_function_parens_in_use_item() { - check_reference_completion( - "dont_render_function_parens_in_use_item", - " - //- /lib.rs - mod m { pub fn foo() {} } - use crate::m::f<|>; - ", - ) + assert_debug_snapshot_matches!( + do_reference_completion( + " + //- /lib.rs + mod m { pub fn foo() {} } + use crate::m::f<|>; + " + ), +@r#"[ + CompletionItem { + label: "foo", + source_range: [40; 41), + delete: [40; 41), + insert: "foo", + kind: Function, + detail: "pub fn foo()", + }, +]"# + ); } #[test] fn dont_render_function_parens_if_already_call() { - check_reference_completion( - "dont_render_function_parens_if_already_call", - " - //- /lib.rs - fn frobnicate() {} - fn main() { - frob<|>(); - } - ", + assert_debug_snapshot_matches!( + do_reference_completion( + " + //- /lib.rs + fn frobnicate() {} + fn main() { + frob<|>(); + } + " + ), +@r#"[ + CompletionItem { + label: "frobnicate", + source_range: [35; 39), + delete: [35; 39), + insert: "frobnicate", + kind: Function, + detail: "fn frobnicate()", + }, + CompletionItem { + label: "main", + source_range: [35; 39), + delete: [35; 39), + insert: "main", + kind: Function, + detail: "fn main()", + }, +]"# + ); + assert_debug_snapshot_matches!( + do_reference_completion( + " + //- /lib.rs + struct Foo {} + impl Foo { fn new() -> Foo {} } + fn main() { + Foo::ne<|>(); + } + " + ), +@r#"[ + CompletionItem { + label: "new", + source_range: [67; 69), + delete: [67; 69), + insert: "new", + kind: Function, + detail: "fn new() -> Foo", + }, +]"# ); - check_reference_completion( - "dont_render_function_parens_if_already_call_assoc_fn", - " - //- /lib.rs - struct Foo {} - impl Foo { fn new() -> Foo {} } - fn main() { - Foo::ne<|>(); - } - ", - ) } - } diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_if_already_call.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_if_already_call.snap deleted file mode 100644 index 46bea2ccd..000000000 --- a/crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_if_already_call.snap +++ /dev/null @@ -1,24 +0,0 @@ ---- -created: "2019-05-23T22:23:35.158296242Z" -creator: insta@0.8.1 -source: crates/ra_ide_api/src/completion/completion_item.rs -expression: kind_completions ---- -[ - CompletionItem { - label: "frobnicate", - source_range: [35; 39), - delete: [35; 39), - insert: "frobnicate", - kind: Function, - detail: "fn frobnicate()", - }, - CompletionItem { - label: "main", - source_range: [35; 39), - delete: [35; 39), - insert: "main", - kind: Function, - detail: "fn main()", - }, -] diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_if_already_call_assoc_fn.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_if_already_call_assoc_fn.snap deleted file mode 100644 index b09a6745e..000000000 --- a/crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_if_already_call_assoc_fn.snap +++ /dev/null @@ -1,16 +0,0 @@ ---- -created: "2019-05-23T22:44:10.920136527Z" -creator: insta@0.8.1 -source: crates/ra_ide_api/src/completion/completion_item.rs -expression: kind_completions ---- -[ - CompletionItem { - label: "new", - source_range: [67; 69), - delete: [67; 69), - insert: "new", - kind: Function, - detail: "fn new() -> Foo", - }, -] diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_in_use_item.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_in_use_item.snap deleted file mode 100644 index 84ccc8160..000000000 --- a/crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_in_use_item.snap +++ /dev/null @@ -1,16 +0,0 @@ ---- -created: "2019-05-23T22:23:35.154795561Z" -creator: insta@0.8.1 -source: crates/ra_ide_api/src/completion/completion_item.rs -expression: kind_completions ---- -[ - CompletionItem { - label: "foo", - source_range: [40; 41), - delete: [40; 41), - insert: "foo", - kind: Function, - detail: "pub fn foo()", - }, -] diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__inserts_parens_for_function_calls1.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__inserts_parens_for_function_calls1.snap deleted file mode 100644 index c795b9aae..000000000 --- a/crates/ra_ide_api/src/completion/snapshots/completion_item__inserts_parens_for_function_calls1.snap +++ /dev/null @@ -1,24 +0,0 @@ ---- -created: "2019-05-23T22:23:35.156115632Z" -creator: insta@0.8.1 -source: crates/ra_ide_api/src/completion/completion_item.rs -expression: kind_completions ---- -[ - CompletionItem { - label: "main", - source_range: [53; 56), - delete: [53; 56), - insert: "main()$0", - kind: Function, - detail: "fn main()", - }, - CompletionItem { - label: "no_args", - source_range: [53; 56), - delete: [53; 56), - insert: "no_args()$0", - kind: Function, - detail: "fn no_args()", - }, -] diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__inserts_parens_for_function_calls2.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__inserts_parens_for_function_calls2.snap deleted file mode 100644 index b49a838e0..000000000 --- a/crates/ra_ide_api/src/completion/snapshots/completion_item__inserts_parens_for_function_calls2.snap +++ /dev/null @@ -1,24 +0,0 @@ ---- -created: "2019-05-23T22:44:10.916806744Z" -creator: insta@0.8.1 -source: crates/ra_ide_api/src/completion/completion_item.rs -expression: kind_completions ---- -[ - CompletionItem { - label: "main", - source_range: [72; 77), - delete: [72; 77), - insert: "main()$0", - kind: Function, - detail: "fn main()", - }, - CompletionItem { - label: "with_args", - source_range: [72; 77), - delete: [72; 77), - insert: "with_args($0)", - kind: Function, - detail: "fn with_args(x: i32, y: String)", - }, -] diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__inserts_parens_for_function_calls3.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__inserts_parens_for_function_calls3.snap deleted file mode 100644 index b62cb7aa1..000000000 --- a/crates/ra_ide_api/src/completion/snapshots/completion_item__inserts_parens_for_function_calls3.snap +++ /dev/null @@ -1,16 +0,0 @@ ---- -created: "2019-05-23T22:44:40.543731193Z" -creator: insta@0.8.1 -source: crates/ra_ide_api/src/completion/completion_item.rs -expression: kind_completions ---- -[ - CompletionItem { - label: "foo", - source_range: [139; 140), - delete: [139; 140), - insert: "foo()$0", - kind: Method, - detail: "fn foo(&self)", - }, -] -- cgit v1.2.3