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