From 49eeeb61ae309a245de2f9bf65ffb0ea9576ba6c Mon Sep 17 00:00:00 2001 From: Nick Spain Date: Fri, 1 Jan 2021 11:10:02 +1100 Subject: Add a test for correct completion of ..Default::default() --- crates/completion/src/completions/record.rs | 62 ++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) (limited to 'crates') diff --git a/crates/completion/src/completions/record.rs b/crates/completion/src/completions/record.rs index 8f904adfd..f55ae11e6 100644 --- a/crates/completion/src/completions/record.rs +++ b/crates/completion/src/completions/record.rs @@ -53,7 +53,10 @@ mod tests { use expect_test::{expect, Expect}; use ide_db::helpers::FamousDefs; - use crate::{test_utils::completion_list, CompletionKind}; + use crate::{ + test_utils::{self, completion_list}, + CompletionKind, + }; fn check(ra_fixture: &str, expect: Expect) { let actual = completion_list(ra_fixture, CompletionKind::Reference); @@ -68,6 +71,18 @@ mod tests { expect.assert_eq(&actual); } + fn check_edit(what: &str, ra_fixture_before: &str, ra_fixture_after: &str) { + test_utils::check_edit( + what, + &format!( + "//- /main.rs crate:main deps:core{}\n{}", + ra_fixture_before, + FamousDefs::FIXTURE, + ), + &(ra_fixture_after.to_owned() + "\n"), + ); + } + #[test] fn test_record_literal_field_default() { let test_code = r#" @@ -106,6 +121,51 @@ fn process(f: S) { ); } + #[test] + fn test_record_literal_field_default_completion() { + check_edit( + "..Default::default()", + r#" +struct S { foo: u32, bar: usize } + +impl core::default::Default for S { + fn default() -> Self { + S { + foo: 0, + bar: 0, + } + } +} + +fn process(f: S) { + let other = S { + foo: 5, + .<|> + }; +} +"#, + r#" +struct S { foo: u32, bar: usize } + +impl core::default::Default for S { + fn default() -> Self { + S { + foo: 0, + bar: 0, + } + } +} + +fn process(f: S) { + let other = S { + foo: 5, + ..Default::default() + }; +} +"#, + ); + } + #[test] fn test_record_literal_field_without_default() { let test_code = r#" -- cgit v1.2.3