From 57283b4e5f5cebdf4bc88f4253ee1fd94acf637b Mon Sep 17 00:00:00 2001 From: Ville Penttinen Date: Wed, 10 Apr 2019 13:47:20 +0300 Subject: Use inline snapshots in complete_dot --- crates/ra_ide_api/src/completion/complete_dot.rs | 163 +++++++++++++++++---- .../completion_item__method_attr_filtering.snap | 16 -- .../completion_item__method_completion.snap | 16 -- .../completion_item__no_non_self_method.snap | 7 - ...no_struct_field_completion_for_method_call.snap | 7 - .../completion_item__struct_field_completion.snap | 16 -- ...on_item__struct_field_completion_autoderef.snap | 24 --- ...pletion_item__struct_field_completion_self.snap | 27 ---- .../completion_item__tuple_field_completion.snap | 24 --- .../completion_item__tuple_field_inference.snap | 16 -- 10 files changed, 136 insertions(+), 180 deletions(-) delete mode 100644 crates/ra_ide_api/src/completion/snapshots/completion_item__method_attr_filtering.snap delete mode 100644 crates/ra_ide_api/src/completion/snapshots/completion_item__method_completion.snap delete mode 100644 crates/ra_ide_api/src/completion/snapshots/completion_item__no_non_self_method.snap delete mode 100644 crates/ra_ide_api/src/completion/snapshots/completion_item__no_struct_field_completion_for_method_call.snap delete mode 100644 crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion.snap delete mode 100644 crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion_autoderef.snap delete mode 100644 crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion_self.snap delete mode 100644 crates/ra_ide_api/src/completion/snapshots/completion_item__tuple_field_completion.snap delete mode 100644 crates/ra_ide_api/src/completion/snapshots/completion_item__tuple_field_inference.snap diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index 18b2d68d5..c093d5cfb 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs @@ -55,29 +55,41 @@ fn complete_methods(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty #[cfg(test)] mod tests { - use crate::completion::{check_completion, CompletionKind}; + use crate::completion::{do_completion, CompletionKind, CompletionItem}; + use insta::assert_debug_snapshot_matches; - fn check_ref_completion(name: &str, code: &str) { - check_completion(name, code, CompletionKind::Reference); + fn do_ref_completion(code: &str) -> Vec { + do_completion(code, CompletionKind::Reference) } #[test] fn test_struct_field_completion() { - check_ref_completion( - "struct_field_completion", - r" - struct A { the_field: u32 } - fn foo(a: A) { - a.<|> - } - ", + assert_debug_snapshot_matches!( + do_ref_completion( + r" + struct A { the_field: u32 } + fn foo(a: A) { + a.<|> + } + ", + ), + @r###"[ + CompletionItem { + label: "the_field", + source_range: [94; 94), + delete: [94; 94), + insert: "the_field", + kind: Field, + detail: "u32" + } +]"### ); } #[test] fn test_struct_field_completion_self() { - check_ref_completion( - "struct_field_completion_self", + assert_debug_snapshot_matches!( + do_ref_completion( r" struct A { /// This is the_field @@ -89,13 +101,35 @@ mod tests { } } ", + ), + @r###"[ + CompletionItem { + label: "foo", + source_range: [187; 187), + delete: [187; 187), + insert: "foo()$0", + kind: Method, + detail: "fn foo(self)" + }, + CompletionItem { + label: "the_field", + source_range: [187; 187), + delete: [187; 187), + insert: "the_field", + kind: Field, + detail: "(u32,)", + documentation: Documentation( + "This is the_field" + ) + } +]"### ); } #[test] fn test_struct_field_completion_autoderef() { - check_ref_completion( - "struct_field_completion_autoderef", + assert_debug_snapshot_matches!( + do_ref_completion( r" struct A { the_field: (u32, i32) } impl A { @@ -104,26 +138,47 @@ mod tests { } } ", + ), + @r###"[ + CompletionItem { + label: "foo", + source_range: [126; 126), + delete: [126; 126), + insert: "foo()$0", + kind: Method, + detail: "fn foo(&self)" + }, + CompletionItem { + label: "the_field", + source_range: [126; 126), + delete: [126; 126), + insert: "the_field", + kind: Field, + detail: "(u32, i32)" + } +]"### ); } #[test] fn test_no_struct_field_completion_for_method_call() { - check_ref_completion( - "no_struct_field_completion_for_method_call", + assert_debug_snapshot_matches!( + do_ref_completion( r" struct A { the_field: u32 } fn foo(a: A) { a.<|>() } ", + ), + @"[]" ); } #[test] fn test_method_completion() { - check_ref_completion( - "method_completion", + assert_debug_snapshot_matches!( + do_ref_completion( r" struct A {} impl A { @@ -133,13 +188,24 @@ mod tests { a.<|> } ", + ), + @r###"[ + CompletionItem { + label: "the_method", + source_range: [144; 144), + delete: [144; 144), + insert: "the_method()$0", + kind: Method, + detail: "fn the_method(&self)" + } +]"### ); } #[test] fn test_no_non_self_method() { - check_ref_completion( - "no_non_self_method", + assert_debug_snapshot_matches!( + do_ref_completion( r" struct A {} impl A { @@ -149,13 +215,15 @@ mod tests { a.<|> } ", + ), + @"[]" ); } #[test] fn test_method_attr_filtering() { - check_ref_completion( - "method_attr_filtering", + assert_debug_snapshot_matches!( + do_ref_completion( r" struct A {} impl A { @@ -169,26 +237,56 @@ mod tests { a.<|> } ", + ), + @r###"[ + CompletionItem { + label: "the_method", + source_range: [249; 249), + delete: [249; 249), + insert: "the_method()$0", + kind: Method, + detail: "fn the_method(&self)" + } +]"### ); } #[test] fn test_tuple_field_completion() { - check_ref_completion( - "tuple_field_completion", + assert_debug_snapshot_matches!( + do_ref_completion( r" fn foo() { let b = (0, 3.14); b.<|> } ", + ), + @r###"[ + CompletionItem { + label: "0", + source_range: [75; 75), + delete: [75; 75), + insert: "0", + kind: Field, + detail: "i32" + }, + CompletionItem { + label: "1", + source_range: [75; 75), + delete: [75; 75), + insert: "1", + kind: Field, + detail: "f64" + } +]"### ); } #[test] fn test_tuple_field_inference() { - check_ref_completion( - "tuple_field_inference", + assert_debug_snapshot_matches!( + do_ref_completion( r" pub struct S; impl S { @@ -204,6 +302,17 @@ mod tests { } } ", + ), + @r###"[ + CompletionItem { + label: "blah", + source_range: [299; 300), + delete: [299; 300), + insert: "blah()$0", + kind: Method, + detail: "pub fn blah(&self)" + } +]"### ); } } diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__method_attr_filtering.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__method_attr_filtering.snap deleted file mode 100644 index ce8af2159..000000000 --- a/crates/ra_ide_api/src/completion/snapshots/completion_item__method_attr_filtering.snap +++ /dev/null @@ -1,16 +0,0 @@ ---- -created: "2019-02-18T09:22:23.941335305Z" -creator: insta@0.6.2 -source: crates/ra_ide_api/src/completion/completion_item.rs -expression: kind_completions ---- -[ - CompletionItem { - label: "the_method", - source_range: [249; 249), - delete: [249; 249), - insert: "the_method()$0", - kind: Method, - detail: "fn the_method(&self)" - } -] diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__method_completion.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__method_completion.snap deleted file mode 100644 index 41a10de14..000000000 --- a/crates/ra_ide_api/src/completion/snapshots/completion_item__method_completion.snap +++ /dev/null @@ -1,16 +0,0 @@ ---- -created: "2019-02-18T09:22:23.939676100Z" -creator: insta@0.6.2 -source: crates/ra_ide_api/src/completion/completion_item.rs -expression: kind_completions ---- -[ - CompletionItem { - label: "the_method", - source_range: [144; 144), - delete: [144; 144), - insert: "the_method()$0", - kind: Method, - detail: "fn the_method(&self)" - } -] diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__no_non_self_method.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__no_non_self_method.snap deleted file mode 100644 index 7cc827532..000000000 --- a/crates/ra_ide_api/src/completion/snapshots/completion_item__no_non_self_method.snap +++ /dev/null @@ -1,7 +0,0 @@ ---- -created: "2019-01-22T14:45:00.552379600+00:00" -creator: insta@0.4.0 -expression: kind_completions -source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs" ---- -[] diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__no_struct_field_completion_for_method_call.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__no_struct_field_completion_for_method_call.snap deleted file mode 100644 index 7cc827532..000000000 --- a/crates/ra_ide_api/src/completion/snapshots/completion_item__no_struct_field_completion_for_method_call.snap +++ /dev/null @@ -1,7 +0,0 @@ ---- -created: "2019-01-22T14:45:00.552379600+00:00" -creator: insta@0.4.0 -expression: kind_completions -source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs" ---- -[] diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion.snap deleted file mode 100644 index 58271b873..000000000 --- a/crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion.snap +++ /dev/null @@ -1,16 +0,0 @@ ---- -created: "2019-02-18T09:22:23.939645902Z" -creator: insta@0.6.2 -source: crates/ra_ide_api/src/completion/completion_item.rs -expression: kind_completions ---- -[ - CompletionItem { - label: "the_field", - source_range: [85; 85), - delete: [85; 85), - insert: "the_field", - kind: Field, - detail: "u32" - } -] diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion_autoderef.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion_autoderef.snap deleted file mode 100644 index b38867b81..000000000 --- a/crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion_autoderef.snap +++ /dev/null @@ -1,24 +0,0 @@ ---- -created: "2019-02-18T09:22:23.940872916Z" -creator: insta@0.6.2 -source: crates/ra_ide_api/src/completion/completion_item.rs -expression: kind_completions ---- -[ - CompletionItem { - label: "foo", - source_range: [126; 126), - delete: [126; 126), - insert: "foo()$0", - kind: Method, - detail: "fn foo(&self)" - }, - CompletionItem { - label: "the_field", - source_range: [126; 126), - delete: [126; 126), - insert: "the_field", - kind: Field, - detail: "(u32, i32)" - } -] diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion_self.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion_self.snap deleted file mode 100644 index 8e5cab43e..000000000 --- a/crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion_self.snap +++ /dev/null @@ -1,27 +0,0 @@ ---- -created: "2019-02-18T09:22:23.940872918Z" -creator: insta@0.6.2 -source: crates/ra_ide_api/src/completion/completion_item.rs -expression: kind_completions ---- -[ - CompletionItem { - label: "foo", - source_range: [187; 187), - delete: [187; 187), - insert: "foo()$0", - kind: Method, - detail: "fn foo(self)" - }, - CompletionItem { - label: "the_field", - source_range: [187; 187), - delete: [187; 187), - insert: "the_field", - kind: Field, - detail: "(u32,)", - documentation: Documentation( - "This is the_field" - ) - } -] diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__tuple_field_completion.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__tuple_field_completion.snap deleted file mode 100644 index 3f2780621..000000000 --- a/crates/ra_ide_api/src/completion/snapshots/completion_item__tuple_field_completion.snap +++ /dev/null @@ -1,24 +0,0 @@ ---- -created: "2019-02-18T09:22:23.939710971Z" -creator: insta@0.6.2 -source: crates/ra_ide_api/src/completion/completion_item.rs -expression: kind_completions ---- -[ - CompletionItem { - label: "0", - source_range: [75; 75), - delete: [75; 75), - insert: "0", - kind: Field, - detail: "i32" - }, - CompletionItem { - label: "1", - source_range: [75; 75), - delete: [75; 75), - insert: "1", - kind: Field, - detail: "f64" - } -] diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__tuple_field_inference.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__tuple_field_inference.snap deleted file mode 100644 index 72c8973b8..000000000 --- a/crates/ra_ide_api/src/completion/snapshots/completion_item__tuple_field_inference.snap +++ /dev/null @@ -1,16 +0,0 @@ ---- -created: "2019-04-05T23:00:18.283812700Z" -creator: insta@0.7.4 -source: crates/ra_ide_api/src/completion/completion_item.rs -expression: kind_completions ---- -[ - CompletionItem { - label: "blah", - source_range: [299; 300), - delete: [299; 300), - insert: "blah()$0", - kind: Method, - detail: "pub fn blah(&self)" - } -] -- cgit v1.2.3