From 4b8e9d5483005844e711e2f6191274c3c6ae1c4a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 24 Apr 2020 01:25:54 +0200 Subject: Move tests to where they belong --- crates/ra_ide/src/completion/complete_dot.rs | 231 --------------------------- crates/ra_ide/src/completion/presentation.rs | 231 +++++++++++++++++++++++++++ 2 files changed, 231 insertions(+), 231 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/completion/complete_dot.rs b/crates/ra_ide/src/completion/complete_dot.rs index 44288f92e..b93153b48 100644 --- a/crates/ra_ide/src/completion/complete_dot.rs +++ b/crates/ra_ide/src/completion/complete_dot.rs @@ -105,237 +105,6 @@ mod tests { ); } - #[test] - fn test_struct_field_completion_in_func_call() { - assert_debug_snapshot!( - do_ref_completion( - r" - struct A { another_field: i64, the_field: u32, my_string: String } - fn test(my_param: u32) -> u32 { my_param } - fn foo(a: A) { - test(a.<|>) - } - ", - ), - @r###" - [ - CompletionItem { - label: "another_field", - source_range: [201; 201), - delete: [201; 201), - insert: "another_field", - kind: Field, - detail: "i64", - }, - CompletionItem { - label: "my_string", - source_range: [201; 201), - delete: [201; 201), - insert: "my_string", - kind: Field, - detail: "{unknown}", - }, - CompletionItem { - label: "the_field", - source_range: [201; 201), - delete: [201; 201), - insert: "the_field", - kind: Field, - detail: "u32", - score: TypeMatch, - }, - ] - "### - ); - } - - #[test] - fn test_struct_field_completion_in_func_call_with_type_and_name() { - assert_debug_snapshot!( - do_ref_completion( - r" - struct A { another_field: i64, another_good_type: u32, the_field: u32 } - fn test(the_field: u32) -> u32 { the_field } - fn foo(a: A) { - test(a.<|>) - } - ", - ), - @r###" - [ - CompletionItem { - label: "another_field", - source_range: [208; 208), - delete: [208; 208), - insert: "another_field", - kind: Field, - detail: "i64", - }, - CompletionItem { - label: "another_good_type", - source_range: [208; 208), - delete: [208; 208), - insert: "another_good_type", - kind: Field, - detail: "u32", - score: TypeMatch, - }, - CompletionItem { - label: "the_field", - source_range: [208; 208), - delete: [208; 208), - insert: "the_field", - kind: Field, - detail: "u32", - score: TypeAndNameMatch, - }, - ] - "### - ); - } - - #[test] - fn test_struct_field_completion_in_record_lit() { - assert_debug_snapshot!( - do_ref_completion( - r" - struct A { another_field: i64, another_good_type: u32, the_field: u32 } - struct B { my_string: String, my_vec: Vec, the_field: u32 } - fn foo(a: A) { - let b = B { - the_field: a.<|> - }; - } - ", - ), - @r###" - [ - CompletionItem { - label: "another_field", - source_range: [270; 270), - delete: [270; 270), - insert: "another_field", - kind: Field, - detail: "i64", - }, - CompletionItem { - label: "another_good_type", - source_range: [270; 270), - delete: [270; 270), - insert: "another_good_type", - kind: Field, - detail: "u32", - score: TypeMatch, - }, - CompletionItem { - label: "the_field", - source_range: [270; 270), - delete: [270; 270), - insert: "the_field", - kind: Field, - detail: "u32", - score: TypeAndNameMatch, - }, - ] - "### - ); - } - - #[test] - fn test_struct_field_completion_in_record_lit_and_fn_call() { - assert_debug_snapshot!( - do_ref_completion( - r" - struct A { another_field: i64, another_good_type: u32, the_field: u32 } - struct B { my_string: String, my_vec: Vec, the_field: u32 } - fn test(the_field: i64) -> i64 { the_field } - fn foo(a: A) { - let b = B { - the_field: test(a.<|>) - }; - } - ", - ), - @r###" - [ - CompletionItem { - label: "another_field", - source_range: [336; 336), - delete: [336; 336), - insert: "another_field", - kind: Field, - detail: "i64", - score: TypeMatch, - }, - CompletionItem { - label: "another_good_type", - source_range: [336; 336), - delete: [336; 336), - insert: "another_good_type", - kind: Field, - detail: "u32", - }, - CompletionItem { - label: "the_field", - source_range: [336; 336), - delete: [336; 336), - insert: "the_field", - kind: Field, - detail: "u32", - }, - ] - "### - ); - } - - #[test] - fn test_struct_field_completion_in_fn_call_and_record_lit() { - assert_debug_snapshot!( - do_ref_completion( - r" - struct A { another_field: i64, another_good_type: u32, the_field: u32 } - struct B { my_string: String, my_vec: Vec, the_field: u32 } - fn test(the_field: i64) -> i64 { the_field } - fn foo(a: A) { - test(B { - the_field: a.<|> - }); - } - ", - ), - @r###" - [ - CompletionItem { - label: "another_field", - source_range: [328; 328), - delete: [328; 328), - insert: "another_field", - kind: Field, - detail: "i64", - }, - CompletionItem { - label: "another_good_type", - source_range: [328; 328), - delete: [328; 328), - insert: "another_good_type", - kind: Field, - detail: "u32", - score: TypeMatch, - }, - CompletionItem { - label: "the_field", - source_range: [328; 328), - delete: [328; 328), - insert: "the_field", - kind: Field, - detail: "u32", - score: TypeAndNameMatch, - }, - ] - "### - ); - } - #[test] fn test_struct_field_completion_self() { assert_debug_snapshot!( diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs index ab43d2a0a..ae15f91de 100644 --- a/crates/ra_ide/src/completion/presentation.rs +++ b/crates/ra_ide/src/completion/presentation.rs @@ -1070,4 +1070,235 @@ mod tests { "### ); } + + #[test] + fn test_struct_field_completion_in_func_call() { + assert_debug_snapshot!( + do_reference_completion( + r" + struct A { another_field: i64, the_field: u32, my_string: String } + fn test(my_param: u32) -> u32 { my_param } + fn foo(a: A) { + test(a.<|>) + } + ", + ), + @r###" + [ + CompletionItem { + label: "another_field", + source_range: [201; 201), + delete: [201; 201), + insert: "another_field", + kind: Field, + detail: "i64", + }, + CompletionItem { + label: "my_string", + source_range: [201; 201), + delete: [201; 201), + insert: "my_string", + kind: Field, + detail: "{unknown}", + }, + CompletionItem { + label: "the_field", + source_range: [201; 201), + delete: [201; 201), + insert: "the_field", + kind: Field, + detail: "u32", + score: TypeMatch, + }, + ] + "### + ); + } + + #[test] + fn test_struct_field_completion_in_func_call_with_type_and_name() { + assert_debug_snapshot!( + do_reference_completion( + r" + struct A { another_field: i64, another_good_type: u32, the_field: u32 } + fn test(the_field: u32) -> u32 { the_field } + fn foo(a: A) { + test(a.<|>) + } + ", + ), + @r###" + [ + CompletionItem { + label: "another_field", + source_range: [208; 208), + delete: [208; 208), + insert: "another_field", + kind: Field, + detail: "i64", + }, + CompletionItem { + label: "another_good_type", + source_range: [208; 208), + delete: [208; 208), + insert: "another_good_type", + kind: Field, + detail: "u32", + score: TypeMatch, + }, + CompletionItem { + label: "the_field", + source_range: [208; 208), + delete: [208; 208), + insert: "the_field", + kind: Field, + detail: "u32", + score: TypeAndNameMatch, + }, + ] + "### + ); + } + + #[test] + fn test_struct_field_completion_in_record_lit() { + assert_debug_snapshot!( + do_reference_completion( + r" + struct A { another_field: i64, another_good_type: u32, the_field: u32 } + struct B { my_string: String, my_vec: Vec, the_field: u32 } + fn foo(a: A) { + let b = B { + the_field: a.<|> + }; + } + ", + ), + @r###" + [ + CompletionItem { + label: "another_field", + source_range: [270; 270), + delete: [270; 270), + insert: "another_field", + kind: Field, + detail: "i64", + }, + CompletionItem { + label: "another_good_type", + source_range: [270; 270), + delete: [270; 270), + insert: "another_good_type", + kind: Field, + detail: "u32", + score: TypeMatch, + }, + CompletionItem { + label: "the_field", + source_range: [270; 270), + delete: [270; 270), + insert: "the_field", + kind: Field, + detail: "u32", + score: TypeAndNameMatch, + }, + ] + "### + ); + } + + #[test] + fn test_struct_field_completion_in_record_lit_and_fn_call() { + assert_debug_snapshot!( + do_reference_completion( + r" + struct A { another_field: i64, another_good_type: u32, the_field: u32 } + struct B { my_string: String, my_vec: Vec, the_field: u32 } + fn test(the_field: i64) -> i64 { the_field } + fn foo(a: A) { + let b = B { + the_field: test(a.<|>) + }; + } + ", + ), + @r###" + [ + CompletionItem { + label: "another_field", + source_range: [336; 336), + delete: [336; 336), + insert: "another_field", + kind: Field, + detail: "i64", + score: TypeMatch, + }, + CompletionItem { + label: "another_good_type", + source_range: [336; 336), + delete: [336; 336), + insert: "another_good_type", + kind: Field, + detail: "u32", + }, + CompletionItem { + label: "the_field", + source_range: [336; 336), + delete: [336; 336), + insert: "the_field", + kind: Field, + detail: "u32", + }, + ] + "### + ); + } + + #[test] + fn test_struct_field_completion_in_fn_call_and_record_lit() { + assert_debug_snapshot!( + do_reference_completion( + r" + struct A { another_field: i64, another_good_type: u32, the_field: u32 } + struct B { my_string: String, my_vec: Vec, the_field: u32 } + fn test(the_field: i64) -> i64 { the_field } + fn foo(a: A) { + test(B { + the_field: a.<|> + }); + } + ", + ), + @r###" + [ + CompletionItem { + label: "another_field", + source_range: [328; 328), + delete: [328; 328), + insert: "another_field", + kind: Field, + detail: "i64", + }, + CompletionItem { + label: "another_good_type", + source_range: [328; 328), + delete: [328; 328), + insert: "another_good_type", + kind: Field, + detail: "u32", + score: TypeMatch, + }, + CompletionItem { + label: "the_field", + source_range: [328; 328), + delete: [328; 328), + insert: "the_field", + kind: Field, + detail: "u32", + score: TypeAndNameMatch, + }, + ] + "### + ); + } } -- cgit v1.2.3