diff options
Diffstat (limited to 'crates/ide_assists/src/tests')
-rw-r--r-- | crates/ide_assists/src/tests/generated.rs | 1329 |
1 files changed, 1329 insertions, 0 deletions
diff --git a/crates/ide_assists/src/tests/generated.rs b/crates/ide_assists/src/tests/generated.rs new file mode 100644 index 000000000..0516deaff --- /dev/null +++ b/crates/ide_assists/src/tests/generated.rs | |||
@@ -0,0 +1,1329 @@ | |||
1 | //! Generated file, do not edit by hand, see `xtask/src/codegen` | ||
2 | |||
3 | use super::check_doc_test; | ||
4 | |||
5 | #[test] | ||
6 | fn doctest_add_explicit_type() { | ||
7 | check_doc_test( | ||
8 | "add_explicit_type", | ||
9 | r#####" | ||
10 | fn main() { | ||
11 | let x$0 = 92; | ||
12 | } | ||
13 | "#####, | ||
14 | r#####" | ||
15 | fn main() { | ||
16 | let x: i32 = 92; | ||
17 | } | ||
18 | "#####, | ||
19 | ) | ||
20 | } | ||
21 | |||
22 | #[test] | ||
23 | fn doctest_add_hash() { | ||
24 | check_doc_test( | ||
25 | "add_hash", | ||
26 | r#####" | ||
27 | fn main() { | ||
28 | r#"Hello,$0 World!"#; | ||
29 | } | ||
30 | "#####, | ||
31 | r#####" | ||
32 | fn main() { | ||
33 | r##"Hello, World!"##; | ||
34 | } | ||
35 | "#####, | ||
36 | ) | ||
37 | } | ||
38 | |||
39 | #[test] | ||
40 | fn doctest_add_impl_default_members() { | ||
41 | check_doc_test( | ||
42 | "add_impl_default_members", | ||
43 | r#####" | ||
44 | trait Trait { | ||
45 | type X; | ||
46 | fn foo(&self); | ||
47 | fn bar(&self) {} | ||
48 | } | ||
49 | |||
50 | impl Trait for () { | ||
51 | type X = (); | ||
52 | fn foo(&self) {}$0 | ||
53 | |||
54 | } | ||
55 | "#####, | ||
56 | r#####" | ||
57 | trait Trait { | ||
58 | type X; | ||
59 | fn foo(&self); | ||
60 | fn bar(&self) {} | ||
61 | } | ||
62 | |||
63 | impl Trait for () { | ||
64 | type X = (); | ||
65 | fn foo(&self) {} | ||
66 | |||
67 | $0fn bar(&self) {} | ||
68 | } | ||
69 | "#####, | ||
70 | ) | ||
71 | } | ||
72 | |||
73 | #[test] | ||
74 | fn doctest_add_impl_missing_members() { | ||
75 | check_doc_test( | ||
76 | "add_impl_missing_members", | ||
77 | r#####" | ||
78 | trait Trait<T> { | ||
79 | type X; | ||
80 | fn foo(&self) -> T; | ||
81 | fn bar(&self) {} | ||
82 | } | ||
83 | |||
84 | impl Trait<u32> for () {$0 | ||
85 | |||
86 | } | ||
87 | "#####, | ||
88 | r#####" | ||
89 | trait Trait<T> { | ||
90 | type X; | ||
91 | fn foo(&self) -> T; | ||
92 | fn bar(&self) {} | ||
93 | } | ||
94 | |||
95 | impl Trait<u32> for () { | ||
96 | $0type X; | ||
97 | |||
98 | fn foo(&self) -> u32 { | ||
99 | todo!() | ||
100 | } | ||
101 | } | ||
102 | "#####, | ||
103 | ) | ||
104 | } | ||
105 | |||
106 | #[test] | ||
107 | fn doctest_add_lifetime_to_type() { | ||
108 | check_doc_test( | ||
109 | "add_lifetime_to_type", | ||
110 | r#####" | ||
111 | struct Point { | ||
112 | x: &$0u32, | ||
113 | y: u32, | ||
114 | } | ||
115 | "#####, | ||
116 | r#####" | ||
117 | struct Point<'a> { | ||
118 | x: &'a u32, | ||
119 | y: u32, | ||
120 | } | ||
121 | "#####, | ||
122 | ) | ||
123 | } | ||
124 | |||
125 | #[test] | ||
126 | fn doctest_add_turbo_fish() { | ||
127 | check_doc_test( | ||
128 | "add_turbo_fish", | ||
129 | r#####" | ||
130 | fn make<T>() -> T { todo!() } | ||
131 | fn main() { | ||
132 | let x = make$0(); | ||
133 | } | ||
134 | "#####, | ||
135 | r#####" | ||
136 | fn make<T>() -> T { todo!() } | ||
137 | fn main() { | ||
138 | let x = make::<${0:_}>(); | ||
139 | } | ||
140 | "#####, | ||
141 | ) | ||
142 | } | ||
143 | |||
144 | #[test] | ||
145 | fn doctest_apply_demorgan() { | ||
146 | check_doc_test( | ||
147 | "apply_demorgan", | ||
148 | r#####" | ||
149 | fn main() { | ||
150 | if x != 4 ||$0 !y {} | ||
151 | } | ||
152 | "#####, | ||
153 | r#####" | ||
154 | fn main() { | ||
155 | if !(x == 4 && y) {} | ||
156 | } | ||
157 | "#####, | ||
158 | ) | ||
159 | } | ||
160 | |||
161 | #[test] | ||
162 | fn doctest_auto_import() { | ||
163 | check_doc_test( | ||
164 | "auto_import", | ||
165 | r#####" | ||
166 | fn main() { | ||
167 | let map = HashMap$0::new(); | ||
168 | } | ||
169 | pub mod std { pub mod collections { pub struct HashMap { } } } | ||
170 | "#####, | ||
171 | r#####" | ||
172 | use std::collections::HashMap; | ||
173 | |||
174 | fn main() { | ||
175 | let map = HashMap::new(); | ||
176 | } | ||
177 | pub mod std { pub mod collections { pub struct HashMap { } } } | ||
178 | "#####, | ||
179 | ) | ||
180 | } | ||
181 | |||
182 | #[test] | ||
183 | fn doctest_change_visibility() { | ||
184 | check_doc_test( | ||
185 | "change_visibility", | ||
186 | r#####" | ||
187 | $0fn frobnicate() {} | ||
188 | "#####, | ||
189 | r#####" | ||
190 | pub(crate) fn frobnicate() {} | ||
191 | "#####, | ||
192 | ) | ||
193 | } | ||
194 | |||
195 | #[test] | ||
196 | fn doctest_convert_integer_literal() { | ||
197 | check_doc_test( | ||
198 | "convert_integer_literal", | ||
199 | r#####" | ||
200 | const _: i32 = 10$0; | ||
201 | "#####, | ||
202 | r#####" | ||
203 | const _: i32 = 0b1010; | ||
204 | "#####, | ||
205 | ) | ||
206 | } | ||
207 | |||
208 | #[test] | ||
209 | fn doctest_convert_to_guarded_return() { | ||
210 | check_doc_test( | ||
211 | "convert_to_guarded_return", | ||
212 | r#####" | ||
213 | fn main() { | ||
214 | $0if cond { | ||
215 | foo(); | ||
216 | bar(); | ||
217 | } | ||
218 | } | ||
219 | "#####, | ||
220 | r#####" | ||
221 | fn main() { | ||
222 | if !cond { | ||
223 | return; | ||
224 | } | ||
225 | foo(); | ||
226 | bar(); | ||
227 | } | ||
228 | "#####, | ||
229 | ) | ||
230 | } | ||
231 | |||
232 | #[test] | ||
233 | fn doctest_expand_glob_import() { | ||
234 | check_doc_test( | ||
235 | "expand_glob_import", | ||
236 | r#####" | ||
237 | mod foo { | ||
238 | pub struct Bar; | ||
239 | pub struct Baz; | ||
240 | } | ||
241 | |||
242 | use foo::*$0; | ||
243 | |||
244 | fn qux(bar: Bar, baz: Baz) {} | ||
245 | "#####, | ||
246 | r#####" | ||
247 | mod foo { | ||
248 | pub struct Bar; | ||
249 | pub struct Baz; | ||
250 | } | ||
251 | |||
252 | use foo::{Baz, Bar}; | ||
253 | |||
254 | fn qux(bar: Bar, baz: Baz) {} | ||
255 | "#####, | ||
256 | ) | ||
257 | } | ||
258 | |||
259 | #[test] | ||
260 | fn doctest_extract_function() { | ||
261 | check_doc_test( | ||
262 | "extract_function", | ||
263 | r#####" | ||
264 | fn main() { | ||
265 | let n = 1; | ||
266 | $0let m = n + 2; | ||
267 | let k = m + n;$0 | ||
268 | let g = 3; | ||
269 | } | ||
270 | "#####, | ||
271 | r#####" | ||
272 | fn main() { | ||
273 | let n = 1; | ||
274 | fun_name(n); | ||
275 | let g = 3; | ||
276 | } | ||
277 | |||
278 | fn $0fun_name(n: i32) { | ||
279 | let m = n + 2; | ||
280 | let k = m + n; | ||
281 | } | ||
282 | "#####, | ||
283 | ) | ||
284 | } | ||
285 | |||
286 | #[test] | ||
287 | fn doctest_extract_struct_from_enum_variant() { | ||
288 | check_doc_test( | ||
289 | "extract_struct_from_enum_variant", | ||
290 | r#####" | ||
291 | enum A { $0One(u32, u32) } | ||
292 | "#####, | ||
293 | r#####" | ||
294 | struct One(pub u32, pub u32); | ||
295 | |||
296 | enum A { One(One) } | ||
297 | "#####, | ||
298 | ) | ||
299 | } | ||
300 | |||
301 | #[test] | ||
302 | fn doctest_extract_variable() { | ||
303 | check_doc_test( | ||
304 | "extract_variable", | ||
305 | r#####" | ||
306 | fn main() { | ||
307 | $0(1 + 2)$0 * 4; | ||
308 | } | ||
309 | "#####, | ||
310 | r#####" | ||
311 | fn main() { | ||
312 | let $0var_name = (1 + 2); | ||
313 | var_name * 4; | ||
314 | } | ||
315 | "#####, | ||
316 | ) | ||
317 | } | ||
318 | |||
319 | #[test] | ||
320 | fn doctest_fill_match_arms() { | ||
321 | check_doc_test( | ||
322 | "fill_match_arms", | ||
323 | r#####" | ||
324 | enum Action { Move { distance: u32 }, Stop } | ||
325 | |||
326 | fn handle(action: Action) { | ||
327 | match action { | ||
328 | $0 | ||
329 | } | ||
330 | } | ||
331 | "#####, | ||
332 | r#####" | ||
333 | enum Action { Move { distance: u32 }, Stop } | ||
334 | |||
335 | fn handle(action: Action) { | ||
336 | match action { | ||
337 | $0Action::Move { distance } => {} | ||
338 | Action::Stop => {} | ||
339 | } | ||
340 | } | ||
341 | "#####, | ||
342 | ) | ||
343 | } | ||
344 | |||
345 | #[test] | ||
346 | fn doctest_fix_visibility() { | ||
347 | check_doc_test( | ||
348 | "fix_visibility", | ||
349 | r#####" | ||
350 | mod m { | ||
351 | fn frobnicate() {} | ||
352 | } | ||
353 | fn main() { | ||
354 | m::frobnicate$0() {} | ||
355 | } | ||
356 | "#####, | ||
357 | r#####" | ||
358 | mod m { | ||
359 | $0pub(crate) fn frobnicate() {} | ||
360 | } | ||
361 | fn main() { | ||
362 | m::frobnicate() {} | ||
363 | } | ||
364 | "#####, | ||
365 | ) | ||
366 | } | ||
367 | |||
368 | #[test] | ||
369 | fn doctest_flip_binexpr() { | ||
370 | check_doc_test( | ||
371 | "flip_binexpr", | ||
372 | r#####" | ||
373 | fn main() { | ||
374 | let _ = 90 +$0 2; | ||
375 | } | ||
376 | "#####, | ||
377 | r#####" | ||
378 | fn main() { | ||
379 | let _ = 2 + 90; | ||
380 | } | ||
381 | "#####, | ||
382 | ) | ||
383 | } | ||
384 | |||
385 | #[test] | ||
386 | fn doctest_flip_comma() { | ||
387 | check_doc_test( | ||
388 | "flip_comma", | ||
389 | r#####" | ||
390 | fn main() { | ||
391 | ((1, 2),$0 (3, 4)); | ||
392 | } | ||
393 | "#####, | ||
394 | r#####" | ||
395 | fn main() { | ||
396 | ((3, 4), (1, 2)); | ||
397 | } | ||
398 | "#####, | ||
399 | ) | ||
400 | } | ||
401 | |||
402 | #[test] | ||
403 | fn doctest_flip_trait_bound() { | ||
404 | check_doc_test( | ||
405 | "flip_trait_bound", | ||
406 | r#####" | ||
407 | fn foo<T: Clone +$0 Copy>() { } | ||
408 | "#####, | ||
409 | r#####" | ||
410 | fn foo<T: Copy + Clone>() { } | ||
411 | "#####, | ||
412 | ) | ||
413 | } | ||
414 | |||
415 | #[test] | ||
416 | fn doctest_generate_default_from_enum_variant() { | ||
417 | check_doc_test( | ||
418 | "generate_default_from_enum_variant", | ||
419 | r#####" | ||
420 | enum Version { | ||
421 | Undefined, | ||
422 | Minor$0, | ||
423 | Major, | ||
424 | } | ||
425 | "#####, | ||
426 | r#####" | ||
427 | enum Version { | ||
428 | Undefined, | ||
429 | Minor, | ||
430 | Major, | ||
431 | } | ||
432 | |||
433 | impl Default for Version { | ||
434 | fn default() -> Self { | ||
435 | Self::Minor | ||
436 | } | ||
437 | } | ||
438 | "#####, | ||
439 | ) | ||
440 | } | ||
441 | |||
442 | #[test] | ||
443 | fn doctest_generate_derive() { | ||
444 | check_doc_test( | ||
445 | "generate_derive", | ||
446 | r#####" | ||
447 | struct Point { | ||
448 | x: u32, | ||
449 | y: u32,$0 | ||
450 | } | ||
451 | "#####, | ||
452 | r#####" | ||
453 | #[derive($0)] | ||
454 | struct Point { | ||
455 | x: u32, | ||
456 | y: u32, | ||
457 | } | ||
458 | "#####, | ||
459 | ) | ||
460 | } | ||
461 | |||
462 | #[test] | ||
463 | fn doctest_generate_enum_match_method() { | ||
464 | check_doc_test( | ||
465 | "generate_enum_match_method", | ||
466 | r#####" | ||
467 | enum Version { | ||
468 | Undefined, | ||
469 | Minor$0, | ||
470 | Major, | ||
471 | } | ||
472 | "#####, | ||
473 | r#####" | ||
474 | enum Version { | ||
475 | Undefined, | ||
476 | Minor, | ||
477 | Major, | ||
478 | } | ||
479 | |||
480 | impl Version { | ||
481 | /// Returns `true` if the version is [`Minor`]. | ||
482 | fn is_minor(&self) -> bool { | ||
483 | matches!(self, Self::Minor) | ||
484 | } | ||
485 | } | ||
486 | "#####, | ||
487 | ) | ||
488 | } | ||
489 | |||
490 | #[test] | ||
491 | fn doctest_generate_from_impl_for_enum() { | ||
492 | check_doc_test( | ||
493 | "generate_from_impl_for_enum", | ||
494 | r#####" | ||
495 | enum A { $0One(u32) } | ||
496 | "#####, | ||
497 | r#####" | ||
498 | enum A { One(u32) } | ||
499 | |||
500 | impl From<u32> for A { | ||
501 | fn from(v: u32) -> Self { | ||
502 | Self::One(v) | ||
503 | } | ||
504 | } | ||
505 | "#####, | ||
506 | ) | ||
507 | } | ||
508 | |||
509 | #[test] | ||
510 | fn doctest_generate_function() { | ||
511 | check_doc_test( | ||
512 | "generate_function", | ||
513 | r#####" | ||
514 | struct Baz; | ||
515 | fn baz() -> Baz { Baz } | ||
516 | fn foo() { | ||
517 | bar$0("", baz()); | ||
518 | } | ||
519 | |||
520 | "#####, | ||
521 | r#####" | ||
522 | struct Baz; | ||
523 | fn baz() -> Baz { Baz } | ||
524 | fn foo() { | ||
525 | bar("", baz()); | ||
526 | } | ||
527 | |||
528 | fn bar(arg: &str, baz: Baz) ${0:-> ()} { | ||
529 | todo!() | ||
530 | } | ||
531 | |||
532 | "#####, | ||
533 | ) | ||
534 | } | ||
535 | |||
536 | #[test] | ||
537 | fn doctest_generate_getter() { | ||
538 | check_doc_test( | ||
539 | "generate_getter", | ||
540 | r#####" | ||
541 | struct Person { | ||
542 | nam$0e: String, | ||
543 | } | ||
544 | "#####, | ||
545 | r#####" | ||
546 | struct Person { | ||
547 | name: String, | ||
548 | } | ||
549 | |||
550 | impl Person { | ||
551 | /// Get a reference to the person's name. | ||
552 | fn name(&self) -> &String { | ||
553 | &self.name | ||
554 | } | ||
555 | } | ||
556 | "#####, | ||
557 | ) | ||
558 | } | ||
559 | |||
560 | #[test] | ||
561 | fn doctest_generate_getter_mut() { | ||
562 | check_doc_test( | ||
563 | "generate_getter_mut", | ||
564 | r#####" | ||
565 | struct Person { | ||
566 | nam$0e: String, | ||
567 | } | ||
568 | "#####, | ||
569 | r#####" | ||
570 | struct Person { | ||
571 | name: String, | ||
572 | } | ||
573 | |||
574 | impl Person { | ||
575 | /// Get a mutable reference to the person's name. | ||
576 | fn name_mut(&mut self) -> &mut String { | ||
577 | &mut self.name | ||
578 | } | ||
579 | } | ||
580 | "#####, | ||
581 | ) | ||
582 | } | ||
583 | |||
584 | #[test] | ||
585 | fn doctest_generate_impl() { | ||
586 | check_doc_test( | ||
587 | "generate_impl", | ||
588 | r#####" | ||
589 | struct Ctx<T: Clone> { | ||
590 | data: T,$0 | ||
591 | } | ||
592 | "#####, | ||
593 | r#####" | ||
594 | struct Ctx<T: Clone> { | ||
595 | data: T, | ||
596 | } | ||
597 | |||
598 | impl<T: Clone> Ctx<T> { | ||
599 | $0 | ||
600 | } | ||
601 | "#####, | ||
602 | ) | ||
603 | } | ||
604 | |||
605 | #[test] | ||
606 | fn doctest_generate_new() { | ||
607 | check_doc_test( | ||
608 | "generate_new", | ||
609 | r#####" | ||
610 | struct Ctx<T: Clone> { | ||
611 | data: T,$0 | ||
612 | } | ||
613 | "#####, | ||
614 | r#####" | ||
615 | struct Ctx<T: Clone> { | ||
616 | data: T, | ||
617 | } | ||
618 | |||
619 | impl<T: Clone> Ctx<T> { | ||
620 | fn $0new(data: T) -> Self { Self { data } } | ||
621 | } | ||
622 | "#####, | ||
623 | ) | ||
624 | } | ||
625 | |||
626 | #[test] | ||
627 | fn doctest_generate_setter() { | ||
628 | check_doc_test( | ||
629 | "generate_setter", | ||
630 | r#####" | ||
631 | struct Person { | ||
632 | nam$0e: String, | ||
633 | } | ||
634 | "#####, | ||
635 | r#####" | ||
636 | struct Person { | ||
637 | name: String, | ||
638 | } | ||
639 | |||
640 | impl Person { | ||
641 | /// Set the person's name. | ||
642 | fn set_name(&mut self, name: String) { | ||
643 | self.name = name; | ||
644 | } | ||
645 | } | ||
646 | "#####, | ||
647 | ) | ||
648 | } | ||
649 | |||
650 | #[test] | ||
651 | fn doctest_infer_function_return_type() { | ||
652 | check_doc_test( | ||
653 | "infer_function_return_type", | ||
654 | r#####" | ||
655 | fn foo() { 4$02i32 } | ||
656 | "#####, | ||
657 | r#####" | ||
658 | fn foo() -> i32 { 42i32 } | ||
659 | "#####, | ||
660 | ) | ||
661 | } | ||
662 | |||
663 | #[test] | ||
664 | fn doctest_inline_function() { | ||
665 | check_doc_test( | ||
666 | "inline_function", | ||
667 | r#####" | ||
668 | fn add(a: u32, b: u32) -> u32 { a + b } | ||
669 | fn main() { | ||
670 | let x = add$0(1, 2); | ||
671 | } | ||
672 | "#####, | ||
673 | r#####" | ||
674 | fn add(a: u32, b: u32) -> u32 { a + b } | ||
675 | fn main() { | ||
676 | let x = { | ||
677 | let a = 1; | ||
678 | let b = 2; | ||
679 | a + b | ||
680 | }; | ||
681 | } | ||
682 | "#####, | ||
683 | ) | ||
684 | } | ||
685 | |||
686 | #[test] | ||
687 | fn doctest_inline_local_variable() { | ||
688 | check_doc_test( | ||
689 | "inline_local_variable", | ||
690 | r#####" | ||
691 | fn main() { | ||
692 | let x$0 = 1 + 2; | ||
693 | x * 4; | ||
694 | } | ||
695 | "#####, | ||
696 | r#####" | ||
697 | fn main() { | ||
698 | (1 + 2) * 4; | ||
699 | } | ||
700 | "#####, | ||
701 | ) | ||
702 | } | ||
703 | |||
704 | #[test] | ||
705 | fn doctest_introduce_named_lifetime() { | ||
706 | check_doc_test( | ||
707 | "introduce_named_lifetime", | ||
708 | r#####" | ||
709 | impl Cursor<'_$0> { | ||
710 | fn node(self) -> &SyntaxNode { | ||
711 | match self { | ||
712 | Cursor::Replace(node) | Cursor::Before(node) => node, | ||
713 | } | ||
714 | } | ||
715 | } | ||
716 | "#####, | ||
717 | r#####" | ||
718 | impl<'a> Cursor<'a> { | ||
719 | fn node(self) -> &SyntaxNode { | ||
720 | match self { | ||
721 | Cursor::Replace(node) | Cursor::Before(node) => node, | ||
722 | } | ||
723 | } | ||
724 | } | ||
725 | "#####, | ||
726 | ) | ||
727 | } | ||
728 | |||
729 | #[test] | ||
730 | fn doctest_invert_if() { | ||
731 | check_doc_test( | ||
732 | "invert_if", | ||
733 | r#####" | ||
734 | fn main() { | ||
735 | if$0 !y { A } else { B } | ||
736 | } | ||
737 | "#####, | ||
738 | r#####" | ||
739 | fn main() { | ||
740 | if y { B } else { A } | ||
741 | } | ||
742 | "#####, | ||
743 | ) | ||
744 | } | ||
745 | |||
746 | #[test] | ||
747 | fn doctest_make_raw_string() { | ||
748 | check_doc_test( | ||
749 | "make_raw_string", | ||
750 | r#####" | ||
751 | fn main() { | ||
752 | "Hello,$0 World!"; | ||
753 | } | ||
754 | "#####, | ||
755 | r#####" | ||
756 | fn main() { | ||
757 | r#"Hello, World!"#; | ||
758 | } | ||
759 | "#####, | ||
760 | ) | ||
761 | } | ||
762 | |||
763 | #[test] | ||
764 | fn doctest_make_usual_string() { | ||
765 | check_doc_test( | ||
766 | "make_usual_string", | ||
767 | r#####" | ||
768 | fn main() { | ||
769 | r#"Hello,$0 "World!""#; | ||
770 | } | ||
771 | "#####, | ||
772 | r#####" | ||
773 | fn main() { | ||
774 | "Hello, \"World!\""; | ||
775 | } | ||
776 | "#####, | ||
777 | ) | ||
778 | } | ||
779 | |||
780 | #[test] | ||
781 | fn doctest_merge_imports() { | ||
782 | check_doc_test( | ||
783 | "merge_imports", | ||
784 | r#####" | ||
785 | use std::$0fmt::Formatter; | ||
786 | use std::io; | ||
787 | "#####, | ||
788 | r#####" | ||
789 | use std::{fmt::Formatter, io}; | ||
790 | "#####, | ||
791 | ) | ||
792 | } | ||
793 | |||
794 | #[test] | ||
795 | fn doctest_merge_match_arms() { | ||
796 | check_doc_test( | ||
797 | "merge_match_arms", | ||
798 | r#####" | ||
799 | enum Action { Move { distance: u32 }, Stop } | ||
800 | |||
801 | fn handle(action: Action) { | ||
802 | match action { | ||
803 | $0Action::Move(..) => foo(), | ||
804 | Action::Stop => foo(), | ||
805 | } | ||
806 | } | ||
807 | "#####, | ||
808 | r#####" | ||
809 | enum Action { Move { distance: u32 }, Stop } | ||
810 | |||
811 | fn handle(action: Action) { | ||
812 | match action { | ||
813 | Action::Move(..) | Action::Stop => foo(), | ||
814 | } | ||
815 | } | ||
816 | "#####, | ||
817 | ) | ||
818 | } | ||
819 | |||
820 | #[test] | ||
821 | fn doctest_move_arm_cond_to_match_guard() { | ||
822 | check_doc_test( | ||
823 | "move_arm_cond_to_match_guard", | ||
824 | r#####" | ||
825 | enum Action { Move { distance: u32 }, Stop } | ||
826 | |||
827 | fn handle(action: Action) { | ||
828 | match action { | ||
829 | Action::Move { distance } => $0if distance > 10 { foo() }, | ||
830 | _ => (), | ||
831 | } | ||
832 | } | ||
833 | "#####, | ||
834 | r#####" | ||
835 | enum Action { Move { distance: u32 }, Stop } | ||
836 | |||
837 | fn handle(action: Action) { | ||
838 | match action { | ||
839 | Action::Move { distance } if distance > 10 => foo(), | ||
840 | _ => (), | ||
841 | } | ||
842 | } | ||
843 | "#####, | ||
844 | ) | ||
845 | } | ||
846 | |||
847 | #[test] | ||
848 | fn doctest_move_bounds_to_where_clause() { | ||
849 | check_doc_test( | ||
850 | "move_bounds_to_where_clause", | ||
851 | r#####" | ||
852 | fn apply<T, U, $0F: FnOnce(T) -> U>(f: F, x: T) -> U { | ||
853 | f(x) | ||
854 | } | ||
855 | "#####, | ||
856 | r#####" | ||
857 | fn apply<T, U, F>(f: F, x: T) -> U where F: FnOnce(T) -> U { | ||
858 | f(x) | ||
859 | } | ||
860 | "#####, | ||
861 | ) | ||
862 | } | ||
863 | |||
864 | #[test] | ||
865 | fn doctest_move_guard_to_arm_body() { | ||
866 | check_doc_test( | ||
867 | "move_guard_to_arm_body", | ||
868 | r#####" | ||
869 | enum Action { Move { distance: u32 }, Stop } | ||
870 | |||
871 | fn handle(action: Action) { | ||
872 | match action { | ||
873 | Action::Move { distance } $0if distance > 10 => foo(), | ||
874 | _ => (), | ||
875 | } | ||
876 | } | ||
877 | "#####, | ||
878 | r#####" | ||
879 | enum Action { Move { distance: u32 }, Stop } | ||
880 | |||
881 | fn handle(action: Action) { | ||
882 | match action { | ||
883 | Action::Move { distance } => if distance > 10 { | ||
884 | foo() | ||
885 | }, | ||
886 | _ => (), | ||
887 | } | ||
888 | } | ||
889 | "#####, | ||
890 | ) | ||
891 | } | ||
892 | |||
893 | #[test] | ||
894 | fn doctest_move_module_to_file() { | ||
895 | check_doc_test( | ||
896 | "move_module_to_file", | ||
897 | r#####" | ||
898 | mod $0foo { | ||
899 | fn t() {} | ||
900 | } | ||
901 | "#####, | ||
902 | r#####" | ||
903 | mod foo; | ||
904 | "#####, | ||
905 | ) | ||
906 | } | ||
907 | |||
908 | #[test] | ||
909 | fn doctest_pull_assignment_up() { | ||
910 | check_doc_test( | ||
911 | "pull_assignment_up", | ||
912 | r#####" | ||
913 | fn main() { | ||
914 | let mut foo = 6; | ||
915 | |||
916 | if true { | ||
917 | $0foo = 5; | ||
918 | } else { | ||
919 | foo = 4; | ||
920 | } | ||
921 | } | ||
922 | "#####, | ||
923 | r#####" | ||
924 | fn main() { | ||
925 | let mut foo = 6; | ||
926 | |||
927 | foo = if true { | ||
928 | 5 | ||
929 | } else { | ||
930 | 4 | ||
931 | }; | ||
932 | } | ||
933 | "#####, | ||
934 | ) | ||
935 | } | ||
936 | |||
937 | #[test] | ||
938 | fn doctest_qualify_path() { | ||
939 | check_doc_test( | ||
940 | "qualify_path", | ||
941 | r#####" | ||
942 | fn main() { | ||
943 | let map = HashMap$0::new(); | ||
944 | } | ||
945 | pub mod std { pub mod collections { pub struct HashMap { } } } | ||
946 | "#####, | ||
947 | r#####" | ||
948 | fn main() { | ||
949 | let map = std::collections::HashMap::new(); | ||
950 | } | ||
951 | pub mod std { pub mod collections { pub struct HashMap { } } } | ||
952 | "#####, | ||
953 | ) | ||
954 | } | ||
955 | |||
956 | #[test] | ||
957 | fn doctest_remove_dbg() { | ||
958 | check_doc_test( | ||
959 | "remove_dbg", | ||
960 | r#####" | ||
961 | fn main() { | ||
962 | $0dbg!(92); | ||
963 | } | ||
964 | "#####, | ||
965 | r#####" | ||
966 | fn main() { | ||
967 | 92; | ||
968 | } | ||
969 | "#####, | ||
970 | ) | ||
971 | } | ||
972 | |||
973 | #[test] | ||
974 | fn doctest_remove_hash() { | ||
975 | check_doc_test( | ||
976 | "remove_hash", | ||
977 | r#####" | ||
978 | fn main() { | ||
979 | r#"Hello,$0 World!"#; | ||
980 | } | ||
981 | "#####, | ||
982 | r#####" | ||
983 | fn main() { | ||
984 | r"Hello, World!"; | ||
985 | } | ||
986 | "#####, | ||
987 | ) | ||
988 | } | ||
989 | |||
990 | #[test] | ||
991 | fn doctest_remove_mut() { | ||
992 | check_doc_test( | ||
993 | "remove_mut", | ||
994 | r#####" | ||
995 | impl Walrus { | ||
996 | fn feed(&mut$0 self, amount: u32) {} | ||
997 | } | ||
998 | "#####, | ||
999 | r#####" | ||
1000 | impl Walrus { | ||
1001 | fn feed(&self, amount: u32) {} | ||
1002 | } | ||
1003 | "#####, | ||
1004 | ) | ||
1005 | } | ||
1006 | |||
1007 | #[test] | ||
1008 | fn doctest_remove_unused_param() { | ||
1009 | check_doc_test( | ||
1010 | "remove_unused_param", | ||
1011 | r#####" | ||
1012 | fn frobnicate(x: i32$0) {} | ||
1013 | |||
1014 | fn main() { | ||
1015 | frobnicate(92); | ||
1016 | } | ||
1017 | "#####, | ||
1018 | r#####" | ||
1019 | fn frobnicate() {} | ||
1020 | |||
1021 | fn main() { | ||
1022 | frobnicate(); | ||
1023 | } | ||
1024 | "#####, | ||
1025 | ) | ||
1026 | } | ||
1027 | |||
1028 | #[test] | ||
1029 | fn doctest_reorder_fields() { | ||
1030 | check_doc_test( | ||
1031 | "reorder_fields", | ||
1032 | r#####" | ||
1033 | struct Foo {foo: i32, bar: i32}; | ||
1034 | const test: Foo = $0Foo {bar: 0, foo: 1} | ||
1035 | "#####, | ||
1036 | r#####" | ||
1037 | struct Foo {foo: i32, bar: i32}; | ||
1038 | const test: Foo = Foo {foo: 1, bar: 0} | ||
1039 | "#####, | ||
1040 | ) | ||
1041 | } | ||
1042 | |||
1043 | #[test] | ||
1044 | fn doctest_reorder_impl() { | ||
1045 | check_doc_test( | ||
1046 | "reorder_impl", | ||
1047 | r#####" | ||
1048 | trait Foo { | ||
1049 | fn a() {} | ||
1050 | fn b() {} | ||
1051 | fn c() {} | ||
1052 | } | ||
1053 | |||
1054 | struct Bar; | ||
1055 | $0impl Foo for Bar { | ||
1056 | fn b() {} | ||
1057 | fn c() {} | ||
1058 | fn a() {} | ||
1059 | } | ||
1060 | "#####, | ||
1061 | r#####" | ||
1062 | trait Foo { | ||
1063 | fn a() {} | ||
1064 | fn b() {} | ||
1065 | fn c() {} | ||
1066 | } | ||
1067 | |||
1068 | struct Bar; | ||
1069 | impl Foo for Bar { | ||
1070 | fn a() {} | ||
1071 | fn b() {} | ||
1072 | fn c() {} | ||
1073 | } | ||
1074 | "#####, | ||
1075 | ) | ||
1076 | } | ||
1077 | |||
1078 | #[test] | ||
1079 | fn doctest_replace_derive_with_manual_impl() { | ||
1080 | check_doc_test( | ||
1081 | "replace_derive_with_manual_impl", | ||
1082 | r#####" | ||
1083 | trait Debug { fn fmt(&self, f: &mut Formatter) -> Result<()>; } | ||
1084 | #[derive(Deb$0ug, Display)] | ||
1085 | struct S; | ||
1086 | "#####, | ||
1087 | r#####" | ||
1088 | trait Debug { fn fmt(&self, f: &mut Formatter) -> Result<()>; } | ||
1089 | #[derive(Display)] | ||
1090 | struct S; | ||
1091 | |||
1092 | impl Debug for S { | ||
1093 | fn fmt(&self, f: &mut Formatter) -> Result<()> { | ||
1094 | ${0:todo!()} | ||
1095 | } | ||
1096 | } | ||
1097 | "#####, | ||
1098 | ) | ||
1099 | } | ||
1100 | |||
1101 | #[test] | ||
1102 | fn doctest_replace_if_let_with_match() { | ||
1103 | check_doc_test( | ||
1104 | "replace_if_let_with_match", | ||
1105 | r#####" | ||
1106 | enum Action { Move { distance: u32 }, Stop } | ||
1107 | |||
1108 | fn handle(action: Action) { | ||
1109 | $0if let Action::Move { distance } = action { | ||
1110 | foo(distance) | ||
1111 | } else { | ||
1112 | bar() | ||
1113 | } | ||
1114 | } | ||
1115 | "#####, | ||
1116 | r#####" | ||
1117 | enum Action { Move { distance: u32 }, Stop } | ||
1118 | |||
1119 | fn handle(action: Action) { | ||
1120 | match action { | ||
1121 | Action::Move { distance } => foo(distance), | ||
1122 | _ => bar(), | ||
1123 | } | ||
1124 | } | ||
1125 | "#####, | ||
1126 | ) | ||
1127 | } | ||
1128 | |||
1129 | #[test] | ||
1130 | fn doctest_replace_impl_trait_with_generic() { | ||
1131 | check_doc_test( | ||
1132 | "replace_impl_trait_with_generic", | ||
1133 | r#####" | ||
1134 | fn foo(bar: $0impl Bar) {} | ||
1135 | "#####, | ||
1136 | r#####" | ||
1137 | fn foo<B: Bar>(bar: B) {} | ||
1138 | "#####, | ||
1139 | ) | ||
1140 | } | ||
1141 | |||
1142 | #[test] | ||
1143 | fn doctest_replace_let_with_if_let() { | ||
1144 | check_doc_test( | ||
1145 | "replace_let_with_if_let", | ||
1146 | r#####" | ||
1147 | enum Option<T> { Some(T), None } | ||
1148 | |||
1149 | fn main(action: Action) { | ||
1150 | $0let x = compute(); | ||
1151 | } | ||
1152 | |||
1153 | fn compute() -> Option<i32> { None } | ||
1154 | "#####, | ||
1155 | r#####" | ||
1156 | enum Option<T> { Some(T), None } | ||
1157 | |||
1158 | fn main(action: Action) { | ||
1159 | if let Some(x) = compute() { | ||
1160 | } | ||
1161 | } | ||
1162 | |||
1163 | fn compute() -> Option<i32> { None } | ||
1164 | "#####, | ||
1165 | ) | ||
1166 | } | ||
1167 | |||
1168 | #[test] | ||
1169 | fn doctest_replace_match_with_if_let() { | ||
1170 | check_doc_test( | ||
1171 | "replace_match_with_if_let", | ||
1172 | r#####" | ||
1173 | enum Action { Move { distance: u32 }, Stop } | ||
1174 | |||
1175 | fn handle(action: Action) { | ||
1176 | $0match action { | ||
1177 | Action::Move { distance } => foo(distance), | ||
1178 | _ => bar(), | ||
1179 | } | ||
1180 | } | ||
1181 | "#####, | ||
1182 | r#####" | ||
1183 | enum Action { Move { distance: u32 }, Stop } | ||
1184 | |||
1185 | fn handle(action: Action) { | ||
1186 | if let Action::Move { distance } = action { | ||
1187 | foo(distance) | ||
1188 | } else { | ||
1189 | bar() | ||
1190 | } | ||
1191 | } | ||
1192 | "#####, | ||
1193 | ) | ||
1194 | } | ||
1195 | |||
1196 | #[test] | ||
1197 | fn doctest_replace_qualified_name_with_use() { | ||
1198 | check_doc_test( | ||
1199 | "replace_qualified_name_with_use", | ||
1200 | r#####" | ||
1201 | fn process(map: std::collections::$0HashMap<String, String>) {} | ||
1202 | "#####, | ||
1203 | r#####" | ||
1204 | use std::collections::HashMap; | ||
1205 | |||
1206 | fn process(map: HashMap<String, String>) {} | ||
1207 | "#####, | ||
1208 | ) | ||
1209 | } | ||
1210 | |||
1211 | #[test] | ||
1212 | fn doctest_replace_string_with_char() { | ||
1213 | check_doc_test( | ||
1214 | "replace_string_with_char", | ||
1215 | r#####" | ||
1216 | fn main() { | ||
1217 | find("{$0"); | ||
1218 | } | ||
1219 | "#####, | ||
1220 | r#####" | ||
1221 | fn main() { | ||
1222 | find('{'); | ||
1223 | } | ||
1224 | "#####, | ||
1225 | ) | ||
1226 | } | ||
1227 | |||
1228 | #[test] | ||
1229 | fn doctest_replace_unwrap_with_match() { | ||
1230 | check_doc_test( | ||
1231 | "replace_unwrap_with_match", | ||
1232 | r#####" | ||
1233 | enum Result<T, E> { Ok(T), Err(E) } | ||
1234 | fn main() { | ||
1235 | let x: Result<i32, i32> = Result::Ok(92); | ||
1236 | let y = x.$0unwrap(); | ||
1237 | } | ||
1238 | "#####, | ||
1239 | r#####" | ||
1240 | enum Result<T, E> { Ok(T), Err(E) } | ||
1241 | fn main() { | ||
1242 | let x: Result<i32, i32> = Result::Ok(92); | ||
1243 | let y = match x { | ||
1244 | Ok(a) => a, | ||
1245 | $0_ => unreachable!(), | ||
1246 | }; | ||
1247 | } | ||
1248 | "#####, | ||
1249 | ) | ||
1250 | } | ||
1251 | |||
1252 | #[test] | ||
1253 | fn doctest_split_import() { | ||
1254 | check_doc_test( | ||
1255 | "split_import", | ||
1256 | r#####" | ||
1257 | use std::$0collections::HashMap; | ||
1258 | "#####, | ||
1259 | r#####" | ||
1260 | use std::{collections::HashMap}; | ||
1261 | "#####, | ||
1262 | ) | ||
1263 | } | ||
1264 | |||
1265 | #[test] | ||
1266 | fn doctest_toggle_ignore() { | ||
1267 | check_doc_test( | ||
1268 | "toggle_ignore", | ||
1269 | r#####" | ||
1270 | $0#[test] | ||
1271 | fn arithmetics { | ||
1272 | assert_eq!(2 + 2, 5); | ||
1273 | } | ||
1274 | "#####, | ||
1275 | r#####" | ||
1276 | #[test] | ||
1277 | #[ignore] | ||
1278 | fn arithmetics { | ||
1279 | assert_eq!(2 + 2, 5); | ||
1280 | } | ||
1281 | "#####, | ||
1282 | ) | ||
1283 | } | ||
1284 | |||
1285 | #[test] | ||
1286 | fn doctest_unmerge_use() { | ||
1287 | check_doc_test( | ||
1288 | "unmerge_use", | ||
1289 | r#####" | ||
1290 | use std::fmt::{Debug, Display$0}; | ||
1291 | "#####, | ||
1292 | r#####" | ||
1293 | use std::fmt::{Debug}; | ||
1294 | use std::fmt::Display; | ||
1295 | "#####, | ||
1296 | ) | ||
1297 | } | ||
1298 | |||
1299 | #[test] | ||
1300 | fn doctest_unwrap_block() { | ||
1301 | check_doc_test( | ||
1302 | "unwrap_block", | ||
1303 | r#####" | ||
1304 | fn foo() { | ||
1305 | if true {$0 | ||
1306 | println!("foo"); | ||
1307 | } | ||
1308 | } | ||
1309 | "#####, | ||
1310 | r#####" | ||
1311 | fn foo() { | ||
1312 | println!("foo"); | ||
1313 | } | ||
1314 | "#####, | ||
1315 | ) | ||
1316 | } | ||
1317 | |||
1318 | #[test] | ||
1319 | fn doctest_wrap_return_type_in_result() { | ||
1320 | check_doc_test( | ||
1321 | "wrap_return_type_in_result", | ||
1322 | r#####" | ||
1323 | fn foo() -> i32$0 { 42i32 } | ||
1324 | "#####, | ||
1325 | r#####" | ||
1326 | fn foo() -> Result<i32, ${0:_}> { Ok(42i32) } | ||
1327 | "#####, | ||
1328 | ) | ||
1329 | } | ||