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