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