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