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