aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_assists
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-05-23 21:15:54 +0100
committerAleksey Kladov <[email protected]>2021-05-23 21:15:54 +0100
commitc06599504bc4fcbb3d5024d9a8bdb14f263bad36 (patch)
treeed4b5acf93ff3cbbfd47a30954e9212ef00b9a1a /crates/ide_assists
parent4c8259e210bbb6c6c6e4781ce15d42a2f9c43f22 (diff)
remove duplicate tests
Diffstat (limited to 'crates/ide_assists')
-rw-r--r--crates/ide_assists/src/handlers/generate_getter.rs129
1 files changed, 26 insertions, 103 deletions
diff --git a/crates/ide_assists/src/handlers/generate_getter.rs b/crates/ide_assists/src/handlers/generate_getter.rs
index e01985112..fbd47d761 100644
--- a/crates/ide_assists/src/handlers/generate_getter.rs
+++ b/crates/ide_assists/src/handlers/generate_getter.rs
@@ -130,10 +130,6 @@ mod tests {
130 130
131 use super::*; 131 use super::*;
132 132
133 fn check_not_applicable(ra_fixture: &str) {
134 check_assist_not_applicable(generate_getter, ra_fixture)
135 }
136
137 #[test] 133 #[test]
138 fn test_generate_getter_from_field() { 134 fn test_generate_getter_from_field() {
139 check_assist( 135 check_assist(
@@ -154,121 +150,48 @@ impl<T: Clone> Context<T> {
154 } 150 }
155}"#, 151}"#,
156 ); 152 );
157 }
158
159 #[test]
160 fn test_generate_getter_already_implemented() {
161 check_not_applicable(
162 r#"
163struct Context<T: Clone> {
164 dat$0a: T,
165}
166
167impl<T: Clone> Context<T> {
168 fn data(&self) -> &T {
169 &self.data
170 }
171}"#,
172 );
173 }
174 153
175 #[test]
176 fn test_generate_getter_from_field_with_visibility_marker() {
177 check_assist( 154 check_assist(
178 generate_getter, 155 generate_getter_mut,
179 r#" 156 r#"
180pub(crate) struct Context<T: Clone> { 157struct Context<T: Clone> {
181 dat$0a: T, 158 dat$0a: T,
182}"#, 159}"#,
183 r#" 160 r#"
184pub(crate) struct Context<T: Clone> { 161struct Context<T: Clone> {
185 data: T, 162 data: T,
186} 163}
187 164
188impl<T: Clone> Context<T> { 165impl<T: Clone> Context<T> {
189 /// Get a reference to the context's data. 166 /// Get a mutable reference to the context's data.
190 pub(crate) fn data(&self) -> &T { 167 fn data_mut(&mut self) -> &mut T {
191 &self.data 168 &mut self.data
192 } 169 }
193}"#, 170}"#,
194 ); 171 );
195 } 172 }
196 173
197 #[test] 174 #[test]
198 fn test_multiple_generate_getter() { 175 fn test_generate_getter_already_implemented() {
199 check_assist( 176 check_assist_not_applicable(
200 generate_getter, 177 generate_getter,
201 r#" 178 r#"
202struct Context<T: Clone> { 179struct Context<T: Clone> {
203 data: T, 180 dat$0a: T,
204 cou$0nt: usize,
205}
206
207impl<T: Clone> Context<T> {
208 /// Get a reference to the context's data.
209 fn data(&self) -> &T {
210 &self.data
211 }
212}"#,
213 r#"
214struct Context<T: Clone> {
215 data: T,
216 count: usize,
217} 181}
218 182
219impl<T: Clone> Context<T> { 183impl<T: Clone> Context<T> {
220 /// Get a reference to the context's data.
221 fn data(&self) -> &T { 184 fn data(&self) -> &T {
222 &self.data 185 &self.data
223 } 186 }
224
225 /// Get a reference to the context's count.
226 fn count(&self) -> &usize {
227 &self.count
228 }
229}"#, 187}"#,
230 ); 188 );
231 }
232}
233
234#[cfg(test)]
235mod tests_mut {
236 use crate::tests::{check_assist, check_assist_not_applicable};
237
238 use super::*;
239 189
240 fn check_not_applicable(ra_fixture: &str) { 190 check_assist_not_applicable(
241 check_assist_not_applicable(generate_getter_mut, ra_fixture)
242 }
243
244 #[test]
245 fn test_generate_getter_mut_from_field() {
246 check_assist(
247 generate_getter_mut, 191 generate_getter_mut,
248 r#" 192 r#"
249struct Context<T: Clone> { 193struct Context<T: Clone> {
250 dat$0a: T, 194 dat$0a: T,
251}"#,
252 r#"
253struct Context<T: Clone> {
254 data: T,
255}
256
257impl<T: Clone> Context<T> {
258 /// Get a mutable reference to the context's data.
259 fn data_mut(&mut self) -> &mut T {
260 &mut self.data
261 }
262}"#,
263 );
264 }
265
266 #[test]
267 fn test_generate_getter_mut_already_implemented() {
268 check_not_applicable(
269 r#"
270struct Context<T: Clone> {
271 dat$0a: T,
272} 195}
273 196
274impl<T: Clone> Context<T> { 197impl<T: Clone> Context<T> {
@@ -280,9 +203,9 @@ impl<T: Clone> Context<T> {
280 } 203 }
281 204
282 #[test] 205 #[test]
283 fn test_generate_getter_mut_from_field_with_visibility_marker() { 206 fn test_generate_getter_from_field_with_visibility_marker() {
284 check_assist( 207 check_assist(
285 generate_getter_mut, 208 generate_getter,
286 r#" 209 r#"
287pub(crate) struct Context<T: Clone> { 210pub(crate) struct Context<T: Clone> {
288 dat$0a: T, 211 dat$0a: T,
@@ -293,18 +216,18 @@ pub(crate) struct Context<T: Clone> {
293} 216}
294 217
295impl<T: Clone> Context<T> { 218impl<T: Clone> Context<T> {
296 /// Get a mutable reference to the context's data. 219 /// Get a reference to the context's data.
297 pub(crate) fn data_mut(&mut self) -> &mut T { 220 pub(crate) fn data(&self) -> &T {
298 &mut self.data 221 &self.data
299 } 222 }
300}"#, 223}"#,
301 ); 224 );
302 } 225 }
303 226
304 #[test] 227 #[test]
305 fn test_multiple_generate_getter_mut() { 228 fn test_multiple_generate_getter() {
306 check_assist( 229 check_assist(
307 generate_getter_mut, 230 generate_getter,
308 r#" 231 r#"
309struct Context<T: Clone> { 232struct Context<T: Clone> {
310 data: T, 233 data: T,
@@ -312,9 +235,9 @@ struct Context<T: Clone> {
312} 235}
313 236
314impl<T: Clone> Context<T> { 237impl<T: Clone> Context<T> {
315 /// Get a mutable reference to the context's data. 238 /// Get a reference to the context's data.
316 fn data_mut(&mut self) -> &mut T { 239 fn data(&self) -> &T {
317 &mut self.data 240 &self.data
318 } 241 }
319}"#, 242}"#,
320 r#" 243 r#"
@@ -324,14 +247,14 @@ struct Context<T: Clone> {
324} 247}
325 248
326impl<T: Clone> Context<T> { 249impl<T: Clone> Context<T> {
327 /// Get a mutable reference to the context's data. 250 /// Get a reference to the context's data.
328 fn data_mut(&mut self) -> &mut T { 251 fn data(&self) -> &T {
329 &mut self.data 252 &self.data
330 } 253 }
331 254
332 /// Get a mutable reference to the context's count. 255 /// Get a reference to the context's count.
333 fn count_mut(&mut self) -> &mut usize { 256 fn count(&self) -> &usize {
334 &mut self.count 257 &self.count
335 } 258 }
336}"#, 259}"#,
337 ); 260 );