diff options
Diffstat (limited to 'crates/assists/src/tests/generated.rs')
-rw-r--r-- | crates/assists/src/tests/generated.rs | 892 |
1 files changed, 892 insertions, 0 deletions
diff --git a/crates/assists/src/tests/generated.rs b/crates/assists/src/tests/generated.rs new file mode 100644 index 000000000..d16e6fb0a --- /dev/null +++ b/crates/assists/src/tests/generated.rs | |||
@@ -0,0 +1,892 @@ | |||
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_custom_impl() { | ||
7 | check_doc_test( | ||
8 | "add_custom_impl", | ||
9 | r#####" | ||
10 | #[derive(Deb<|>ug, Display)] | ||
11 | struct S; | ||
12 | "#####, | ||
13 | r#####" | ||
14 | #[derive(Display)] | ||
15 | struct S; | ||
16 | |||
17 | impl Debug for S { | ||
18 | $0 | ||
19 | } | ||
20 | "#####, | ||
21 | ) | ||
22 | } | ||
23 | |||
24 | #[test] | ||
25 | fn doctest_add_explicit_type() { | ||
26 | check_doc_test( | ||
27 | "add_explicit_type", | ||
28 | r#####" | ||
29 | fn main() { | ||
30 | let x<|> = 92; | ||
31 | } | ||
32 | "#####, | ||
33 | r#####" | ||
34 | fn main() { | ||
35 | let x: i32 = 92; | ||
36 | } | ||
37 | "#####, | ||
38 | ) | ||
39 | } | ||
40 | |||
41 | #[test] | ||
42 | fn doctest_add_hash() { | ||
43 | check_doc_test( | ||
44 | "add_hash", | ||
45 | r#####" | ||
46 | fn main() { | ||
47 | r#"Hello,<|> World!"#; | ||
48 | } | ||
49 | "#####, | ||
50 | r#####" | ||
51 | fn main() { | ||
52 | r##"Hello, World!"##; | ||
53 | } | ||
54 | "#####, | ||
55 | ) | ||
56 | } | ||
57 | |||
58 | #[test] | ||
59 | fn doctest_add_impl_default_members() { | ||
60 | check_doc_test( | ||
61 | "add_impl_default_members", | ||
62 | r#####" | ||
63 | trait Trait { | ||
64 | Type X; | ||
65 | fn foo(&self); | ||
66 | fn bar(&self) {} | ||
67 | } | ||
68 | |||
69 | impl Trait for () { | ||
70 | Type X = (); | ||
71 | fn foo(&self) {}<|> | ||
72 | |||
73 | } | ||
74 | "#####, | ||
75 | r#####" | ||
76 | trait Trait { | ||
77 | Type X; | ||
78 | fn foo(&self); | ||
79 | fn bar(&self) {} | ||
80 | } | ||
81 | |||
82 | impl Trait for () { | ||
83 | Type X = (); | ||
84 | fn foo(&self) {} | ||
85 | $0fn bar(&self) {} | ||
86 | |||
87 | } | ||
88 | "#####, | ||
89 | ) | ||
90 | } | ||
91 | |||
92 | #[test] | ||
93 | fn doctest_add_impl_missing_members() { | ||
94 | check_doc_test( | ||
95 | "add_impl_missing_members", | ||
96 | r#####" | ||
97 | trait Trait<T> { | ||
98 | Type X; | ||
99 | fn foo(&self) -> T; | ||
100 | fn bar(&self) {} | ||
101 | } | ||
102 | |||
103 | impl Trait<u32> for () {<|> | ||
104 | |||
105 | } | ||
106 | "#####, | ||
107 | r#####" | ||
108 | trait Trait<T> { | ||
109 | Type X; | ||
110 | fn foo(&self) -> T; | ||
111 | fn bar(&self) {} | ||
112 | } | ||
113 | |||
114 | impl Trait<u32> for () { | ||
115 | fn foo(&self) -> u32 { | ||
116 | ${0:todo!()} | ||
117 | } | ||
118 | |||
119 | } | ||
120 | "#####, | ||
121 | ) | ||
122 | } | ||
123 | |||
124 | #[test] | ||
125 | fn doctest_add_turbo_fish() { | ||
126 | check_doc_test( | ||
127 | "add_turbo_fish", | ||
128 | r#####" | ||
129 | fn make<T>() -> T { todo!() } | ||
130 | fn main() { | ||
131 | let x = make<|>(); | ||
132 | } | ||
133 | "#####, | ||
134 | r#####" | ||
135 | fn make<T>() -> T { todo!() } | ||
136 | fn main() { | ||
137 | let x = make::<${0:_}>(); | ||
138 | } | ||
139 | "#####, | ||
140 | ) | ||
141 | } | ||
142 | |||
143 | #[test] | ||
144 | fn doctest_apply_demorgan() { | ||
145 | check_doc_test( | ||
146 | "apply_demorgan", | ||
147 | r#####" | ||
148 | fn main() { | ||
149 | if x != 4 ||<|> !y {} | ||
150 | } | ||
151 | "#####, | ||
152 | r#####" | ||
153 | fn main() { | ||
154 | if !(x == 4 && y) {} | ||
155 | } | ||
156 | "#####, | ||
157 | ) | ||
158 | } | ||
159 | |||
160 | #[test] | ||
161 | fn doctest_auto_import() { | ||
162 | check_doc_test( | ||
163 | "auto_import", | ||
164 | r#####" | ||
165 | fn main() { | ||
166 | let map = HashMap<|>::new(); | ||
167 | } | ||
168 | pub mod std { pub mod collections { pub struct HashMap { } } } | ||
169 | "#####, | ||
170 | r#####" | ||
171 | use std::collections::HashMap; | ||
172 | |||
173 | fn main() { | ||
174 | let map = HashMap::new(); | ||
175 | } | ||
176 | pub mod std { pub mod collections { pub struct HashMap { } } } | ||
177 | "#####, | ||
178 | ) | ||
179 | } | ||
180 | |||
181 | #[test] | ||
182 | fn doctest_change_return_type_to_result() { | ||
183 | check_doc_test( | ||
184 | "change_return_type_to_result", | ||
185 | r#####" | ||
186 | fn foo() -> i32<|> { 42i32 } | ||
187 | "#####, | ||
188 | r#####" | ||
189 | fn foo() -> Result<i32, ${0:_}> { Ok(42i32) } | ||
190 | "#####, | ||
191 | ) | ||
192 | } | ||
193 | |||
194 | #[test] | ||
195 | fn doctest_change_visibility() { | ||
196 | check_doc_test( | ||
197 | "change_visibility", | ||
198 | r#####" | ||
199 | <|>fn frobnicate() {} | ||
200 | "#####, | ||
201 | r#####" | ||
202 | pub(crate) fn frobnicate() {} | ||
203 | "#####, | ||
204 | ) | ||
205 | } | ||
206 | |||
207 | #[test] | ||
208 | fn doctest_convert_to_guarded_return() { | ||
209 | check_doc_test( | ||
210 | "convert_to_guarded_return", | ||
211 | r#####" | ||
212 | fn main() { | ||
213 | <|>if cond { | ||
214 | foo(); | ||
215 | bar(); | ||
216 | } | ||
217 | } | ||
218 | "#####, | ||
219 | r#####" | ||
220 | fn main() { | ||
221 | if !cond { | ||
222 | return; | ||
223 | } | ||
224 | foo(); | ||
225 | bar(); | ||
226 | } | ||
227 | "#####, | ||
228 | ) | ||
229 | } | ||
230 | |||
231 | #[test] | ||
232 | fn doctest_expand_glob_import() { | ||
233 | check_doc_test( | ||
234 | "expand_glob_import", | ||
235 | r#####" | ||
236 | mod foo { | ||
237 | pub struct Bar; | ||
238 | pub struct Baz; | ||
239 | } | ||
240 | |||
241 | use foo::*<|>; | ||
242 | |||
243 | fn qux(bar: Bar, baz: Baz) {} | ||
244 | "#####, | ||
245 | r#####" | ||
246 | mod foo { | ||
247 | pub struct Bar; | ||
248 | pub struct Baz; | ||
249 | } | ||
250 | |||
251 | use foo::{Baz, Bar}; | ||
252 | |||
253 | fn qux(bar: Bar, baz: Baz) {} | ||
254 | "#####, | ||
255 | ) | ||
256 | } | ||
257 | |||
258 | #[test] | ||
259 | fn doctest_extract_struct_from_enum_variant() { | ||
260 | check_doc_test( | ||
261 | "extract_struct_from_enum_variant", | ||
262 | r#####" | ||
263 | enum A { <|>One(u32, u32) } | ||
264 | "#####, | ||
265 | r#####" | ||
266 | struct One(pub u32, pub u32); | ||
267 | |||
268 | enum A { One(One) } | ||
269 | "#####, | ||
270 | ) | ||
271 | } | ||
272 | |||
273 | #[test] | ||
274 | fn doctest_extract_variable() { | ||
275 | check_doc_test( | ||
276 | "extract_variable", | ||
277 | r#####" | ||
278 | fn main() { | ||
279 | <|>(1 + 2)<|> * 4; | ||
280 | } | ||
281 | "#####, | ||
282 | r#####" | ||
283 | fn main() { | ||
284 | let $0var_name = (1 + 2); | ||
285 | var_name * 4; | ||
286 | } | ||
287 | "#####, | ||
288 | ) | ||
289 | } | ||
290 | |||
291 | #[test] | ||
292 | fn doctest_fill_match_arms() { | ||
293 | check_doc_test( | ||
294 | "fill_match_arms", | ||
295 | r#####" | ||
296 | enum Action { Move { distance: u32 }, Stop } | ||
297 | |||
298 | fn handle(action: Action) { | ||
299 | match action { | ||
300 | <|> | ||
301 | } | ||
302 | } | ||
303 | "#####, | ||
304 | r#####" | ||
305 | enum Action { Move { distance: u32 }, Stop } | ||
306 | |||
307 | fn handle(action: Action) { | ||
308 | match action { | ||
309 | $0Action::Move { distance } => {} | ||
310 | Action::Stop => {} | ||
311 | } | ||
312 | } | ||
313 | "#####, | ||
314 | ) | ||
315 | } | ||
316 | |||
317 | #[test] | ||
318 | fn doctest_fix_visibility() { | ||
319 | check_doc_test( | ||
320 | "fix_visibility", | ||
321 | r#####" | ||
322 | mod m { | ||
323 | fn frobnicate() {} | ||
324 | } | ||
325 | fn main() { | ||
326 | m::frobnicate<|>() {} | ||
327 | } | ||
328 | "#####, | ||
329 | r#####" | ||
330 | mod m { | ||
331 | $0pub(crate) fn frobnicate() {} | ||
332 | } | ||
333 | fn main() { | ||
334 | m::frobnicate() {} | ||
335 | } | ||
336 | "#####, | ||
337 | ) | ||
338 | } | ||
339 | |||
340 | #[test] | ||
341 | fn doctest_flip_binexpr() { | ||
342 | check_doc_test( | ||
343 | "flip_binexpr", | ||
344 | r#####" | ||
345 | fn main() { | ||
346 | let _ = 90 +<|> 2; | ||
347 | } | ||
348 | "#####, | ||
349 | r#####" | ||
350 | fn main() { | ||
351 | let _ = 2 + 90; | ||
352 | } | ||
353 | "#####, | ||
354 | ) | ||
355 | } | ||
356 | |||
357 | #[test] | ||
358 | fn doctest_flip_comma() { | ||
359 | check_doc_test( | ||
360 | "flip_comma", | ||
361 | r#####" | ||
362 | fn main() { | ||
363 | ((1, 2),<|> (3, 4)); | ||
364 | } | ||
365 | "#####, | ||
366 | r#####" | ||
367 | fn main() { | ||
368 | ((3, 4), (1, 2)); | ||
369 | } | ||
370 | "#####, | ||
371 | ) | ||
372 | } | ||
373 | |||
374 | #[test] | ||
375 | fn doctest_flip_trait_bound() { | ||
376 | check_doc_test( | ||
377 | "flip_trait_bound", | ||
378 | r#####" | ||
379 | fn foo<T: Clone +<|> Copy>() { } | ||
380 | "#####, | ||
381 | r#####" | ||
382 | fn foo<T: Copy + Clone>() { } | ||
383 | "#####, | ||
384 | ) | ||
385 | } | ||
386 | |||
387 | #[test] | ||
388 | fn doctest_generate_derive() { | ||
389 | check_doc_test( | ||
390 | "generate_derive", | ||
391 | r#####" | ||
392 | struct Point { | ||
393 | x: u32, | ||
394 | y: u32,<|> | ||
395 | } | ||
396 | "#####, | ||
397 | r#####" | ||
398 | #[derive($0)] | ||
399 | struct Point { | ||
400 | x: u32, | ||
401 | y: u32, | ||
402 | } | ||
403 | "#####, | ||
404 | ) | ||
405 | } | ||
406 | |||
407 | #[test] | ||
408 | fn doctest_generate_from_impl_for_enum() { | ||
409 | check_doc_test( | ||
410 | "generate_from_impl_for_enum", | ||
411 | r#####" | ||
412 | enum A { <|>One(u32) } | ||
413 | "#####, | ||
414 | r#####" | ||
415 | enum A { One(u32) } | ||
416 | |||
417 | impl From<u32> for A { | ||
418 | fn from(v: u32) -> Self { | ||
419 | A::One(v) | ||
420 | } | ||
421 | } | ||
422 | "#####, | ||
423 | ) | ||
424 | } | ||
425 | |||
426 | #[test] | ||
427 | fn doctest_generate_function() { | ||
428 | check_doc_test( | ||
429 | "generate_function", | ||
430 | r#####" | ||
431 | struct Baz; | ||
432 | fn baz() -> Baz { Baz } | ||
433 | fn foo() { | ||
434 | bar<|>("", baz()); | ||
435 | } | ||
436 | |||
437 | "#####, | ||
438 | r#####" | ||
439 | struct Baz; | ||
440 | fn baz() -> Baz { Baz } | ||
441 | fn foo() { | ||
442 | bar("", baz()); | ||
443 | } | ||
444 | |||
445 | fn bar(arg: &str, baz: Baz) { | ||
446 | ${0:todo!()} | ||
447 | } | ||
448 | |||
449 | "#####, | ||
450 | ) | ||
451 | } | ||
452 | |||
453 | #[test] | ||
454 | fn doctest_generate_impl() { | ||
455 | check_doc_test( | ||
456 | "generate_impl", | ||
457 | r#####" | ||
458 | struct Ctx<T: Clone> { | ||
459 | data: T,<|> | ||
460 | } | ||
461 | "#####, | ||
462 | r#####" | ||
463 | struct Ctx<T: Clone> { | ||
464 | data: T, | ||
465 | } | ||
466 | |||
467 | impl<T: Clone> Ctx<T> { | ||
468 | $0 | ||
469 | } | ||
470 | "#####, | ||
471 | ) | ||
472 | } | ||
473 | |||
474 | #[test] | ||
475 | fn doctest_generate_new() { | ||
476 | check_doc_test( | ||
477 | "generate_new", | ||
478 | r#####" | ||
479 | struct Ctx<T: Clone> { | ||
480 | data: T,<|> | ||
481 | } | ||
482 | "#####, | ||
483 | r#####" | ||
484 | struct Ctx<T: Clone> { | ||
485 | data: T, | ||
486 | } | ||
487 | |||
488 | impl<T: Clone> Ctx<T> { | ||
489 | fn $0new(data: T) -> Self { Self { data } } | ||
490 | } | ||
491 | |||
492 | "#####, | ||
493 | ) | ||
494 | } | ||
495 | |||
496 | #[test] | ||
497 | fn doctest_inline_local_variable() { | ||
498 | check_doc_test( | ||
499 | "inline_local_variable", | ||
500 | r#####" | ||
501 | fn main() { | ||
502 | let x<|> = 1 + 2; | ||
503 | x * 4; | ||
504 | } | ||
505 | "#####, | ||
506 | r#####" | ||
507 | fn main() { | ||
508 | (1 + 2) * 4; | ||
509 | } | ||
510 | "#####, | ||
511 | ) | ||
512 | } | ||
513 | |||
514 | #[test] | ||
515 | fn doctest_introduce_named_lifetime() { | ||
516 | check_doc_test( | ||
517 | "introduce_named_lifetime", | ||
518 | r#####" | ||
519 | impl Cursor<'_<|>> { | ||
520 | fn node(self) -> &SyntaxNode { | ||
521 | match self { | ||
522 | Cursor::Replace(node) | Cursor::Before(node) => node, | ||
523 | } | ||
524 | } | ||
525 | } | ||
526 | "#####, | ||
527 | r#####" | ||
528 | impl<'a> Cursor<'a> { | ||
529 | fn node(self) -> &SyntaxNode { | ||
530 | match self { | ||
531 | Cursor::Replace(node) | Cursor::Before(node) => node, | ||
532 | } | ||
533 | } | ||
534 | } | ||
535 | "#####, | ||
536 | ) | ||
537 | } | ||
538 | |||
539 | #[test] | ||
540 | fn doctest_invert_if() { | ||
541 | check_doc_test( | ||
542 | "invert_if", | ||
543 | r#####" | ||
544 | fn main() { | ||
545 | if<|> !y { A } else { B } | ||
546 | } | ||
547 | "#####, | ||
548 | r#####" | ||
549 | fn main() { | ||
550 | if y { B } else { A } | ||
551 | } | ||
552 | "#####, | ||
553 | ) | ||
554 | } | ||
555 | |||
556 | #[test] | ||
557 | fn doctest_make_raw_string() { | ||
558 | check_doc_test( | ||
559 | "make_raw_string", | ||
560 | r#####" | ||
561 | fn main() { | ||
562 | "Hello,<|> World!"; | ||
563 | } | ||
564 | "#####, | ||
565 | r#####" | ||
566 | fn main() { | ||
567 | r#"Hello, World!"#; | ||
568 | } | ||
569 | "#####, | ||
570 | ) | ||
571 | } | ||
572 | |||
573 | #[test] | ||
574 | fn doctest_make_usual_string() { | ||
575 | check_doc_test( | ||
576 | "make_usual_string", | ||
577 | r#####" | ||
578 | fn main() { | ||
579 | r#"Hello,<|> "World!""#; | ||
580 | } | ||
581 | "#####, | ||
582 | r#####" | ||
583 | fn main() { | ||
584 | "Hello, \"World!\""; | ||
585 | } | ||
586 | "#####, | ||
587 | ) | ||
588 | } | ||
589 | |||
590 | #[test] | ||
591 | fn doctest_merge_imports() { | ||
592 | check_doc_test( | ||
593 | "merge_imports", | ||
594 | r#####" | ||
595 | use std::<|>fmt::Formatter; | ||
596 | use std::io; | ||
597 | "#####, | ||
598 | r#####" | ||
599 | use std::{fmt::Formatter, io}; | ||
600 | "#####, | ||
601 | ) | ||
602 | } | ||
603 | |||
604 | #[test] | ||
605 | fn doctest_merge_match_arms() { | ||
606 | check_doc_test( | ||
607 | "merge_match_arms", | ||
608 | r#####" | ||
609 | enum Action { Move { distance: u32 }, Stop } | ||
610 | |||
611 | fn handle(action: Action) { | ||
612 | match action { | ||
613 | <|>Action::Move(..) => foo(), | ||
614 | Action::Stop => foo(), | ||
615 | } | ||
616 | } | ||
617 | "#####, | ||
618 | r#####" | ||
619 | enum Action { Move { distance: u32 }, Stop } | ||
620 | |||
621 | fn handle(action: Action) { | ||
622 | match action { | ||
623 | Action::Move(..) | Action::Stop => foo(), | ||
624 | } | ||
625 | } | ||
626 | "#####, | ||
627 | ) | ||
628 | } | ||
629 | |||
630 | #[test] | ||
631 | fn doctest_move_arm_cond_to_match_guard() { | ||
632 | check_doc_test( | ||
633 | "move_arm_cond_to_match_guard", | ||
634 | r#####" | ||
635 | enum Action { Move { distance: u32 }, Stop } | ||
636 | |||
637 | fn handle(action: Action) { | ||
638 | match action { | ||
639 | Action::Move { distance } => <|>if distance > 10 { foo() }, | ||
640 | _ => (), | ||
641 | } | ||
642 | } | ||
643 | "#####, | ||
644 | r#####" | ||
645 | enum Action { Move { distance: u32 }, Stop } | ||
646 | |||
647 | fn handle(action: Action) { | ||
648 | match action { | ||
649 | Action::Move { distance } if distance > 10 => foo(), | ||
650 | _ => (), | ||
651 | } | ||
652 | } | ||
653 | "#####, | ||
654 | ) | ||
655 | } | ||
656 | |||
657 | #[test] | ||
658 | fn doctest_move_bounds_to_where_clause() { | ||
659 | check_doc_test( | ||
660 | "move_bounds_to_where_clause", | ||
661 | r#####" | ||
662 | fn apply<T, U, <|>F: FnOnce(T) -> U>(f: F, x: T) -> U { | ||
663 | f(x) | ||
664 | } | ||
665 | "#####, | ||
666 | r#####" | ||
667 | fn apply<T, U, F>(f: F, x: T) -> U where F: FnOnce(T) -> U { | ||
668 | f(x) | ||
669 | } | ||
670 | "#####, | ||
671 | ) | ||
672 | } | ||
673 | |||
674 | #[test] | ||
675 | fn doctest_move_guard_to_arm_body() { | ||
676 | check_doc_test( | ||
677 | "move_guard_to_arm_body", | ||
678 | r#####" | ||
679 | enum Action { Move { distance: u32 }, Stop } | ||
680 | |||
681 | fn handle(action: Action) { | ||
682 | match action { | ||
683 | Action::Move { distance } <|>if distance > 10 => foo(), | ||
684 | _ => (), | ||
685 | } | ||
686 | } | ||
687 | "#####, | ||
688 | r#####" | ||
689 | enum Action { Move { distance: u32 }, Stop } | ||
690 | |||
691 | fn handle(action: Action) { | ||
692 | match action { | ||
693 | Action::Move { distance } => if distance > 10 { | ||
694 | foo() | ||
695 | }, | ||
696 | _ => (), | ||
697 | } | ||
698 | } | ||
699 | "#####, | ||
700 | ) | ||
701 | } | ||
702 | |||
703 | #[test] | ||
704 | fn doctest_remove_dbg() { | ||
705 | check_doc_test( | ||
706 | "remove_dbg", | ||
707 | r#####" | ||
708 | fn main() { | ||
709 | <|>dbg!(92); | ||
710 | } | ||
711 | "#####, | ||
712 | r#####" | ||
713 | fn main() { | ||
714 | 92; | ||
715 | } | ||
716 | "#####, | ||
717 | ) | ||
718 | } | ||
719 | |||
720 | #[test] | ||
721 | fn doctest_remove_hash() { | ||
722 | check_doc_test( | ||
723 | "remove_hash", | ||
724 | r#####" | ||
725 | fn main() { | ||
726 | r#"Hello,<|> World!"#; | ||
727 | } | ||
728 | "#####, | ||
729 | r#####" | ||
730 | fn main() { | ||
731 | r"Hello, World!"; | ||
732 | } | ||
733 | "#####, | ||
734 | ) | ||
735 | } | ||
736 | |||
737 | #[test] | ||
738 | fn doctest_remove_mut() { | ||
739 | check_doc_test( | ||
740 | "remove_mut", | ||
741 | r#####" | ||
742 | impl Walrus { | ||
743 | fn feed(&mut<|> self, amount: u32) {} | ||
744 | } | ||
745 | "#####, | ||
746 | r#####" | ||
747 | impl Walrus { | ||
748 | fn feed(&self, amount: u32) {} | ||
749 | } | ||
750 | "#####, | ||
751 | ) | ||
752 | } | ||
753 | |||
754 | #[test] | ||
755 | fn doctest_reorder_fields() { | ||
756 | check_doc_test( | ||
757 | "reorder_fields", | ||
758 | r#####" | ||
759 | struct Foo {foo: i32, bar: i32}; | ||
760 | const test: Foo = <|>Foo {bar: 0, foo: 1} | ||
761 | "#####, | ||
762 | r#####" | ||
763 | struct Foo {foo: i32, bar: i32}; | ||
764 | const test: Foo = Foo {foo: 1, bar: 0} | ||
765 | "#####, | ||
766 | ) | ||
767 | } | ||
768 | |||
769 | #[test] | ||
770 | fn doctest_replace_if_let_with_match() { | ||
771 | check_doc_test( | ||
772 | "replace_if_let_with_match", | ||
773 | r#####" | ||
774 | enum Action { Move { distance: u32 }, Stop } | ||
775 | |||
776 | fn handle(action: Action) { | ||
777 | <|>if let Action::Move { distance } = action { | ||
778 | foo(distance) | ||
779 | } else { | ||
780 | bar() | ||
781 | } | ||
782 | } | ||
783 | "#####, | ||
784 | r#####" | ||
785 | enum Action { Move { distance: u32 }, Stop } | ||
786 | |||
787 | fn handle(action: Action) { | ||
788 | match action { | ||
789 | Action::Move { distance } => foo(distance), | ||
790 | _ => bar(), | ||
791 | } | ||
792 | } | ||
793 | "#####, | ||
794 | ) | ||
795 | } | ||
796 | |||
797 | #[test] | ||
798 | fn doctest_replace_let_with_if_let() { | ||
799 | check_doc_test( | ||
800 | "replace_let_with_if_let", | ||
801 | r#####" | ||
802 | enum Option<T> { Some(T), None } | ||
803 | |||
804 | fn main(action: Action) { | ||
805 | <|>let x = compute(); | ||
806 | } | ||
807 | |||
808 | fn compute() -> Option<i32> { None } | ||
809 | "#####, | ||
810 | r#####" | ||
811 | enum Option<T> { Some(T), None } | ||
812 | |||
813 | fn main(action: Action) { | ||
814 | if let Some(x) = compute() { | ||
815 | } | ||
816 | } | ||
817 | |||
818 | fn compute() -> Option<i32> { None } | ||
819 | "#####, | ||
820 | ) | ||
821 | } | ||
822 | |||
823 | #[test] | ||
824 | fn doctest_replace_qualified_name_with_use() { | ||
825 | check_doc_test( | ||
826 | "replace_qualified_name_with_use", | ||
827 | r#####" | ||
828 | fn process(map: std::collections::<|>HashMap<String, String>) {} | ||
829 | "#####, | ||
830 | r#####" | ||
831 | use std::collections::HashMap; | ||
832 | |||
833 | fn process(map: HashMap<String, String>) {} | ||
834 | "#####, | ||
835 | ) | ||
836 | } | ||
837 | |||
838 | #[test] | ||
839 | fn doctest_replace_unwrap_with_match() { | ||
840 | check_doc_test( | ||
841 | "replace_unwrap_with_match", | ||
842 | r#####" | ||
843 | enum Result<T, E> { Ok(T), Err(E) } | ||
844 | fn main() { | ||
845 | let x: Result<i32, i32> = Result::Ok(92); | ||
846 | let y = x.<|>unwrap(); | ||
847 | } | ||
848 | "#####, | ||
849 | r#####" | ||
850 | enum Result<T, E> { Ok(T), Err(E) } | ||
851 | fn main() { | ||
852 | let x: Result<i32, i32> = Result::Ok(92); | ||
853 | let y = match x { | ||
854 | Ok(a) => a, | ||
855 | $0_ => unreachable!(), | ||
856 | }; | ||
857 | } | ||
858 | "#####, | ||
859 | ) | ||
860 | } | ||
861 | |||
862 | #[test] | ||
863 | fn doctest_split_import() { | ||
864 | check_doc_test( | ||
865 | "split_import", | ||
866 | r#####" | ||
867 | use std::<|>collections::HashMap; | ||
868 | "#####, | ||
869 | r#####" | ||
870 | use std::{collections::HashMap}; | ||
871 | "#####, | ||
872 | ) | ||
873 | } | ||
874 | |||
875 | #[test] | ||
876 | fn doctest_unwrap_block() { | ||
877 | check_doc_test( | ||
878 | "unwrap_block", | ||
879 | r#####" | ||
880 | fn foo() { | ||
881 | if true {<|> | ||
882 | println!("foo"); | ||
883 | } | ||
884 | } | ||
885 | "#####, | ||
886 | r#####" | ||
887 | fn foo() { | ||
888 | println!("foo"); | ||
889 | } | ||
890 | "#####, | ||
891 | ) | ||
892 | } | ||