aboutsummaryrefslogtreecommitdiff
path: root/crates/completion/src/completions/record.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/completion/src/completions/record.rs')
-rw-r--r--crates/completion/src/completions/record.rs62
1 files changed, 61 insertions, 1 deletions
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 {
53 use expect_test::{expect, Expect}; 53 use expect_test::{expect, Expect};
54 use ide_db::helpers::FamousDefs; 54 use ide_db::helpers::FamousDefs;
55 55
56 use crate::{test_utils::completion_list, CompletionKind}; 56 use crate::{
57 test_utils::{self, completion_list},
58 CompletionKind,
59 };
57 60
58 fn check(ra_fixture: &str, expect: Expect) { 61 fn check(ra_fixture: &str, expect: Expect) {
59 let actual = completion_list(ra_fixture, CompletionKind::Reference); 62 let actual = completion_list(ra_fixture, CompletionKind::Reference);
@@ -68,6 +71,18 @@ mod tests {
68 expect.assert_eq(&actual); 71 expect.assert_eq(&actual);
69 } 72 }
70 73
74 fn check_edit(what: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
75 test_utils::check_edit(
76 what,
77 &format!(
78 "//- /main.rs crate:main deps:core{}\n{}",
79 ra_fixture_before,
80 FamousDefs::FIXTURE,
81 ),
82 &(ra_fixture_after.to_owned() + "\n"),
83 );
84 }
85
71 #[test] 86 #[test]
72 fn test_record_literal_field_default() { 87 fn test_record_literal_field_default() {
73 let test_code = r#" 88 let test_code = r#"
@@ -107,6 +122,51 @@ fn process(f: S) {
107 } 122 }
108 123
109 #[test] 124 #[test]
125 fn test_record_literal_field_default_completion() {
126 check_edit(
127 "..Default::default()",
128 r#"
129struct S { foo: u32, bar: usize }
130
131impl core::default::Default for S {
132 fn default() -> Self {
133 S {
134 foo: 0,
135 bar: 0,
136 }
137 }
138}
139
140fn process(f: S) {
141 let other = S {
142 foo: 5,
143 .<|>
144 };
145}
146"#,
147 r#"
148struct S { foo: u32, bar: usize }
149
150impl core::default::Default for S {
151 fn default() -> Self {
152 S {
153 foo: 0,
154 bar: 0,
155 }
156 }
157}
158
159fn process(f: S) {
160 let other = S {
161 foo: 5,
162 ..Default::default()
163 };
164}
165"#,
166 );
167 }
168
169 #[test]
110 fn test_record_literal_field_without_default() { 170 fn test_record_literal_field_without_default() {
111 let test_code = r#" 171 let test_code = r#"
112struct S { foo: u32, bar: usize } 172struct S { foo: u32, bar: usize }