aboutsummaryrefslogtreecommitdiff
path: root/crates/assists/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'crates/assists/src/tests')
-rw-r--r--crates/assists/src/tests/generated.rs217
1 files changed, 120 insertions, 97 deletions
diff --git a/crates/assists/src/tests/generated.rs b/crates/assists/src/tests/generated.rs
index b91a816e8..e28837b53 100644
--- a/crates/assists/src/tests/generated.rs
+++ b/crates/assists/src/tests/generated.rs
@@ -8,7 +8,7 @@ fn doctest_add_explicit_type() {
8 "add_explicit_type", 8 "add_explicit_type",
9 r#####" 9 r#####"
10fn main() { 10fn main() {
11 let x<|> = 92; 11 let x$0 = 92;
12} 12}
13"#####, 13"#####,
14 r#####" 14 r#####"
@@ -25,7 +25,7 @@ fn doctest_add_hash() {
25 "add_hash", 25 "add_hash",
26 r#####" 26 r#####"
27fn main() { 27fn main() {
28 r#"Hello,<|> World!"#; 28 r#"Hello,$0 World!"#;
29} 29}
30"#####, 30"#####,
31 r#####" 31 r#####"
@@ -49,7 +49,7 @@ trait Trait {
49 49
50impl Trait for () { 50impl Trait for () {
51 type X = (); 51 type X = ();
52 fn foo(&self) {}<|> 52 fn foo(&self) {}$0
53 53
54} 54}
55"#####, 55"#####,
@@ -81,7 +81,7 @@ trait Trait<T> {
81 fn bar(&self) {} 81 fn bar(&self) {}
82} 82}
83 83
84impl Trait<u32> for () {<|> 84impl Trait<u32> for () {$0
85 85
86} 86}
87"#####, 87"#####,
@@ -110,7 +110,7 @@ fn doctest_add_turbo_fish() {
110 r#####" 110 r#####"
111fn make<T>() -> T { todo!() } 111fn make<T>() -> T { todo!() }
112fn main() { 112fn main() {
113 let x = make<|>(); 113 let x = make$0();
114} 114}
115"#####, 115"#####,
116 r#####" 116 r#####"
@@ -128,7 +128,7 @@ fn doctest_apply_demorgan() {
128 "apply_demorgan", 128 "apply_demorgan",
129 r#####" 129 r#####"
130fn main() { 130fn main() {
131 if x != 4 ||<|> !y {} 131 if x != 4 ||$0 !y {}
132} 132}
133"#####, 133"#####,
134 r#####" 134 r#####"
@@ -145,7 +145,7 @@ fn doctest_auto_import() {
145 "auto_import", 145 "auto_import",
146 r#####" 146 r#####"
147fn main() { 147fn main() {
148 let map = HashMap<|>::new(); 148 let map = HashMap$0::new();
149} 149}
150pub mod std { pub mod collections { pub struct HashMap { } } } 150pub mod std { pub mod collections { pub struct HashMap { } } }
151"#####, 151"#####,
@@ -165,7 +165,7 @@ fn doctest_change_visibility() {
165 check_doc_test( 165 check_doc_test(
166 "change_visibility", 166 "change_visibility",
167 r#####" 167 r#####"
168<|>fn frobnicate() {} 168$0fn frobnicate() {}
169"#####, 169"#####,
170 r#####" 170 r#####"
171pub(crate) fn frobnicate() {} 171pub(crate) fn frobnicate() {}
@@ -178,7 +178,7 @@ fn doctest_convert_integer_literal() {
178 check_doc_test( 178 check_doc_test(
179 "convert_integer_literal", 179 "convert_integer_literal",
180 r#####" 180 r#####"
181const _: i32 = 10<|>; 181const _: i32 = 10$0;
182"#####, 182"#####,
183 r#####" 183 r#####"
184const _: i32 = 0b1010; 184const _: i32 = 0b1010;
@@ -192,7 +192,7 @@ fn doctest_convert_to_guarded_return() {
192 "convert_to_guarded_return", 192 "convert_to_guarded_return",
193 r#####" 193 r#####"
194fn main() { 194fn main() {
195 <|>if cond { 195 $0if cond {
196 foo(); 196 foo();
197 bar(); 197 bar();
198 } 198 }
@@ -220,7 +220,7 @@ mod foo {
220 pub struct Baz; 220 pub struct Baz;
221} 221}
222 222
223use foo::*<|>; 223use foo::*$0;
224 224
225fn qux(bar: Bar, baz: Baz) {} 225fn qux(bar: Bar, baz: Baz) {}
226"#####, 226"#####,
@@ -238,55 +238,11 @@ fn qux(bar: Bar, baz: Baz) {}
238} 238}
239 239
240#[test] 240#[test]
241fn doctest_extract_assignment() {
242 check_doc_test(
243 "extract_assignment",
244 r#####"
245fn main() {
246 let mut foo = 6;
247
248 if true {
249 <|>foo = 5;
250 } else {
251 foo = 4;
252 }
253}
254"#####,
255 r#####"
256fn main() {
257 let mut foo = 6;
258
259 foo = if true {
260 5
261 } else {
262 4
263 };
264}
265"#####,
266 )
267}
268
269#[test]
270fn doctest_extract_module_to_file() {
271 check_doc_test(
272 "extract_module_to_file",
273 r#####"
274mod foo {<|>
275 fn t() {}
276}
277"#####,
278 r#####"
279mod foo;
280"#####,
281 )
282}
283
284#[test]
285fn doctest_extract_struct_from_enum_variant() { 241fn doctest_extract_struct_from_enum_variant() {
286 check_doc_test( 242 check_doc_test(
287 "extract_struct_from_enum_variant", 243 "extract_struct_from_enum_variant",
288 r#####" 244 r#####"
289enum A { <|>One(u32, u32) } 245enum A { $0One(u32, u32) }
290"#####, 246"#####,
291 r#####" 247 r#####"
292struct One(pub u32, pub u32); 248struct One(pub u32, pub u32);
@@ -302,7 +258,7 @@ fn doctest_extract_variable() {
302 "extract_variable", 258 "extract_variable",
303 r#####" 259 r#####"
304fn main() { 260fn main() {
305 <|>(1 + 2)<|> * 4; 261 $0(1 + 2)$0 * 4;
306} 262}
307"#####, 263"#####,
308 r#####" 264 r#####"
@@ -323,7 +279,7 @@ enum Action { Move { distance: u32 }, Stop }
323 279
324fn handle(action: Action) { 280fn handle(action: Action) {
325 match action { 281 match action {
326 <|> 282 $0
327 } 283 }
328} 284}
329"#####, 285"#####,
@@ -349,7 +305,7 @@ mod m {
349 fn frobnicate() {} 305 fn frobnicate() {}
350} 306}
351fn main() { 307fn main() {
352 m::frobnicate<|>() {} 308 m::frobnicate$0() {}
353} 309}
354"#####, 310"#####,
355 r#####" 311 r#####"
@@ -369,7 +325,7 @@ fn doctest_flip_binexpr() {
369 "flip_binexpr", 325 "flip_binexpr",
370 r#####" 326 r#####"
371fn main() { 327fn main() {
372 let _ = 90 +<|> 2; 328 let _ = 90 +$0 2;
373} 329}
374"#####, 330"#####,
375 r#####" 331 r#####"
@@ -386,7 +342,7 @@ fn doctest_flip_comma() {
386 "flip_comma", 342 "flip_comma",
387 r#####" 343 r#####"
388fn main() { 344fn main() {
389 ((1, 2),<|> (3, 4)); 345 ((1, 2),$0 (3, 4));
390} 346}
391"#####, 347"#####,
392 r#####" 348 r#####"
@@ -402,7 +358,7 @@ fn doctest_flip_trait_bound() {
402 check_doc_test( 358 check_doc_test(
403 "flip_trait_bound", 359 "flip_trait_bound",
404 r#####" 360 r#####"
405fn foo<T: Clone +<|> Copy>() { } 361fn foo<T: Clone +$0 Copy>() { }
406"#####, 362"#####,
407 r#####" 363 r#####"
408fn foo<T: Copy + Clone>() { } 364fn foo<T: Copy + Clone>() { }
@@ -417,7 +373,7 @@ fn doctest_generate_default_from_enum_variant() {
417 r#####" 373 r#####"
418enum Version { 374enum Version {
419 Undefined, 375 Undefined,
420 Minor<|>, 376 Minor$0,
421 Major, 377 Major,
422} 378}
423"#####, 379"#####,
@@ -444,7 +400,7 @@ fn doctest_generate_derive() {
444 r#####" 400 r#####"
445struct Point { 401struct Point {
446 x: u32, 402 x: u32,
447 y: u32,<|> 403 y: u32,$0
448} 404}
449"#####, 405"#####,
450 r#####" 406 r#####"
@@ -462,7 +418,7 @@ fn doctest_generate_from_impl_for_enum() {
462 check_doc_test( 418 check_doc_test(
463 "generate_from_impl_for_enum", 419 "generate_from_impl_for_enum",
464 r#####" 420 r#####"
465enum A { <|>One(u32) } 421enum A { $0One(u32) }
466"#####, 422"#####,
467 r#####" 423 r#####"
468enum A { One(u32) } 424enum A { One(u32) }
@@ -484,7 +440,7 @@ fn doctest_generate_function() {
484struct Baz; 440struct Baz;
485fn baz() -> Baz { Baz } 441fn baz() -> Baz { Baz }
486fn foo() { 442fn foo() {
487 bar<|>("", baz()); 443 bar$0("", baz());
488} 444}
489 445
490"#####, 446"#####,
@@ -509,7 +465,7 @@ fn doctest_generate_impl() {
509 "generate_impl", 465 "generate_impl",
510 r#####" 466 r#####"
511struct Ctx<T: Clone> { 467struct Ctx<T: Clone> {
512 data: T,<|> 468 data: T,$0
513} 469}
514"#####, 470"#####,
515 r#####" 471 r#####"
@@ -530,7 +486,7 @@ fn doctest_generate_new() {
530 "generate_new", 486 "generate_new",
531 r#####" 487 r#####"
532struct Ctx<T: Clone> { 488struct Ctx<T: Clone> {
533 data: T,<|> 489 data: T,$0
534} 490}
535"#####, 491"#####,
536 r#####" 492 r#####"
@@ -551,7 +507,7 @@ fn doctest_infer_function_return_type() {
551 check_doc_test( 507 check_doc_test(
552 "infer_function_return_type", 508 "infer_function_return_type",
553 r#####" 509 r#####"
554fn foo() { 4<|>2i32 } 510fn foo() { 4$02i32 }
555"#####, 511"#####,
556 r#####" 512 r#####"
557fn foo() -> i32 { 42i32 } 513fn foo() -> i32 { 42i32 }
@@ -560,12 +516,35 @@ fn foo() -> i32 { 42i32 }
560} 516}
561 517
562#[test] 518#[test]
519fn doctest_inline_function() {
520 check_doc_test(
521 "inline_function",
522 r#####"
523fn add(a: u32, b: u32) -> u32 { a + b }
524fn main() {
525 let x = add$0(1, 2);
526}
527"#####,
528 r#####"
529fn add(a: u32, b: u32) -> u32 { a + b }
530fn main() {
531 let x = {
532 let a = 1;
533 let b = 2;
534 a + b
535 };
536}
537"#####,
538 )
539}
540
541#[test]
563fn doctest_inline_local_variable() { 542fn doctest_inline_local_variable() {
564 check_doc_test( 543 check_doc_test(
565 "inline_local_variable", 544 "inline_local_variable",
566 r#####" 545 r#####"
567fn main() { 546fn main() {
568 let x<|> = 1 + 2; 547 let x$0 = 1 + 2;
569 x * 4; 548 x * 4;
570} 549}
571"#####, 550"#####,
@@ -582,7 +561,7 @@ fn doctest_introduce_named_lifetime() {
582 check_doc_test( 561 check_doc_test(
583 "introduce_named_lifetime", 562 "introduce_named_lifetime",
584 r#####" 563 r#####"
585impl Cursor<'_<|>> { 564impl Cursor<'_$0> {
586 fn node(self) -> &SyntaxNode { 565 fn node(self) -> &SyntaxNode {
587 match self { 566 match self {
588 Cursor::Replace(node) | Cursor::Before(node) => node, 567 Cursor::Replace(node) | Cursor::Before(node) => node,
@@ -608,7 +587,7 @@ fn doctest_invert_if() {
608 "invert_if", 587 "invert_if",
609 r#####" 588 r#####"
610fn main() { 589fn main() {
611 if<|> !y { A } else { B } 590 if$0 !y { A } else { B }
612} 591}
613"#####, 592"#####,
614 r#####" 593 r#####"
@@ -625,7 +604,7 @@ fn doctest_make_raw_string() {
625 "make_raw_string", 604 "make_raw_string",
626 r#####" 605 r#####"
627fn main() { 606fn main() {
628 "Hello,<|> World!"; 607 "Hello,$0 World!";
629} 608}
630"#####, 609"#####,
631 r#####" 610 r#####"
@@ -642,7 +621,7 @@ fn doctest_make_usual_string() {
642 "make_usual_string", 621 "make_usual_string",
643 r#####" 622 r#####"
644fn main() { 623fn main() {
645 r#"Hello,<|> "World!""#; 624 r#"Hello,$0 "World!""#;
646} 625}
647"#####, 626"#####,
648 r#####" 627 r#####"
@@ -658,7 +637,7 @@ fn doctest_merge_imports() {
658 check_doc_test( 637 check_doc_test(
659 "merge_imports", 638 "merge_imports",
660 r#####" 639 r#####"
661use std::<|>fmt::Formatter; 640use std::$0fmt::Formatter;
662use std::io; 641use std::io;
663"#####, 642"#####,
664 r#####" 643 r#####"
@@ -676,7 +655,7 @@ enum Action { Move { distance: u32 }, Stop }
676 655
677fn handle(action: Action) { 656fn handle(action: Action) {
678 match action { 657 match action {
679 <|>Action::Move(..) => foo(), 658 $0Action::Move(..) => foo(),
680 Action::Stop => foo(), 659 Action::Stop => foo(),
681 } 660 }
682} 661}
@@ -702,7 +681,7 @@ enum Action { Move { distance: u32 }, Stop }
702 681
703fn handle(action: Action) { 682fn handle(action: Action) {
704 match action { 683 match action {
705 Action::Move { distance } => <|>if distance > 10 { foo() }, 684 Action::Move { distance } => $0if distance > 10 { foo() },
706 _ => (), 685 _ => (),
707 } 686 }
708} 687}
@@ -725,7 +704,7 @@ fn doctest_move_bounds_to_where_clause() {
725 check_doc_test( 704 check_doc_test(
726 "move_bounds_to_where_clause", 705 "move_bounds_to_where_clause",
727 r#####" 706 r#####"
728fn apply<T, U, <|>F: FnOnce(T) -> U>(f: F, x: T) -> U { 707fn apply<T, U, $0F: FnOnce(T) -> U>(f: F, x: T) -> U {
729 f(x) 708 f(x)
730} 709}
731"#####, 710"#####,
@@ -746,7 +725,7 @@ enum Action { Move { distance: u32 }, Stop }
746 725
747fn handle(action: Action) { 726fn handle(action: Action) {
748 match action { 727 match action {
749 Action::Move { distance } <|>if distance > 10 => foo(), 728 Action::Move { distance } $0if distance > 10 => foo(),
750 _ => (), 729 _ => (),
751 } 730 }
752} 731}
@@ -767,12 +746,56 @@ fn handle(action: Action) {
767} 746}
768 747
769#[test] 748#[test]
749fn doctest_move_module_to_file() {
750 check_doc_test(
751 "move_module_to_file",
752 r#####"
753mod $0foo {
754 fn t() {}
755}
756"#####,
757 r#####"
758mod foo;
759"#####,
760 )
761}
762
763#[test]
764fn doctest_pull_assignment_up() {
765 check_doc_test(
766 "pull_assignment_up",
767 r#####"
768fn main() {
769 let mut foo = 6;
770
771 if true {
772 $0foo = 5;
773 } else {
774 foo = 4;
775 }
776}
777"#####,
778 r#####"
779fn main() {
780 let mut foo = 6;
781
782 foo = if true {
783 5
784 } else {
785 4
786 };
787}
788"#####,
789 )
790}
791
792#[test]
770fn doctest_qualify_path() { 793fn doctest_qualify_path() {
771 check_doc_test( 794 check_doc_test(
772 "qualify_path", 795 "qualify_path",
773 r#####" 796 r#####"
774fn main() { 797fn main() {
775 let map = HashMap<|>::new(); 798 let map = HashMap$0::new();
776} 799}
777pub mod std { pub mod collections { pub struct HashMap { } } } 800pub mod std { pub mod collections { pub struct HashMap { } } }
778"#####, 801"#####,
@@ -791,7 +814,7 @@ fn doctest_remove_dbg() {
791 "remove_dbg", 814 "remove_dbg",
792 r#####" 815 r#####"
793fn main() { 816fn main() {
794 <|>dbg!(92); 817 $0dbg!(92);
795} 818}
796"#####, 819"#####,
797 r#####" 820 r#####"
@@ -808,7 +831,7 @@ fn doctest_remove_hash() {
808 "remove_hash", 831 "remove_hash",
809 r#####" 832 r#####"
810fn main() { 833fn main() {
811 r#"Hello,<|> World!"#; 834 r#"Hello,$0 World!"#;
812} 835}
813"#####, 836"#####,
814 r#####" 837 r#####"
@@ -825,7 +848,7 @@ fn doctest_remove_mut() {
825 "remove_mut", 848 "remove_mut",
826 r#####" 849 r#####"
827impl Walrus { 850impl Walrus {
828 fn feed(&mut<|> self, amount: u32) {} 851 fn feed(&mut$0 self, amount: u32) {}
829} 852}
830"#####, 853"#####,
831 r#####" 854 r#####"
@@ -841,7 +864,7 @@ fn doctest_remove_unused_param() {
841 check_doc_test( 864 check_doc_test(
842 "remove_unused_param", 865 "remove_unused_param",
843 r#####" 866 r#####"
844fn frobnicate(x: i32<|>) {} 867fn frobnicate(x: i32$0) {}
845 868
846fn main() { 869fn main() {
847 frobnicate(92); 870 frobnicate(92);
@@ -863,7 +886,7 @@ fn doctest_reorder_fields() {
863 "reorder_fields", 886 "reorder_fields",
864 r#####" 887 r#####"
865struct Foo {foo: i32, bar: i32}; 888struct Foo {foo: i32, bar: i32};
866const test: Foo = <|>Foo {bar: 0, foo: 1} 889const test: Foo = $0Foo {bar: 0, foo: 1}
867"#####, 890"#####,
868 r#####" 891 r#####"
869struct Foo {foo: i32, bar: i32}; 892struct Foo {foo: i32, bar: i32};
@@ -878,7 +901,7 @@ fn doctest_replace_derive_with_manual_impl() {
878 "replace_derive_with_manual_impl", 901 "replace_derive_with_manual_impl",
879 r#####" 902 r#####"
880trait Debug { fn fmt(&self, f: &mut Formatter) -> Result<()>; } 903trait Debug { fn fmt(&self, f: &mut Formatter) -> Result<()>; }
881#[derive(Deb<|>ug, Display)] 904#[derive(Deb$0ug, Display)]
882struct S; 905struct S;
883"#####, 906"#####,
884 r#####" 907 r#####"
@@ -903,7 +926,7 @@ fn doctest_replace_if_let_with_match() {
903enum Action { Move { distance: u32 }, Stop } 926enum Action { Move { distance: u32 }, Stop }
904 927
905fn handle(action: Action) { 928fn handle(action: Action) {
906 <|>if let Action::Move { distance } = action { 929 $0if let Action::Move { distance } = action {
907 foo(distance) 930 foo(distance)
908 } else { 931 } else {
909 bar() 932 bar()
@@ -928,7 +951,7 @@ fn doctest_replace_impl_trait_with_generic() {
928 check_doc_test( 951 check_doc_test(
929 "replace_impl_trait_with_generic", 952 "replace_impl_trait_with_generic",
930 r#####" 953 r#####"
931fn foo(bar: <|>impl Bar) {} 954fn foo(bar: $0impl Bar) {}
932"#####, 955"#####,
933 r#####" 956 r#####"
934fn foo<B: Bar>(bar: B) {} 957fn foo<B: Bar>(bar: B) {}
@@ -944,7 +967,7 @@ fn doctest_replace_let_with_if_let() {
944enum Option<T> { Some(T), None } 967enum Option<T> { Some(T), None }
945 968
946fn main(action: Action) { 969fn main(action: Action) {
947 <|>let x = compute(); 970 $0let x = compute();
948} 971}
949 972
950fn compute() -> Option<i32> { None } 973fn compute() -> Option<i32> { None }
@@ -970,7 +993,7 @@ fn doctest_replace_match_with_if_let() {
970enum Action { Move { distance: u32 }, Stop } 993enum Action { Move { distance: u32 }, Stop }
971 994
972fn handle(action: Action) { 995fn handle(action: Action) {
973 <|>match action { 996 $0match action {
974 Action::Move { distance } => foo(distance), 997 Action::Move { distance } => foo(distance),
975 _ => bar(), 998 _ => bar(),
976 } 999 }
@@ -995,7 +1018,7 @@ fn doctest_replace_qualified_name_with_use() {
995 check_doc_test( 1018 check_doc_test(
996 "replace_qualified_name_with_use", 1019 "replace_qualified_name_with_use",
997 r#####" 1020 r#####"
998fn process(map: std::collections::<|>HashMap<String, String>) {} 1021fn process(map: std::collections::$0HashMap<String, String>) {}
999"#####, 1022"#####,
1000 r#####" 1023 r#####"
1001use std::collections::HashMap; 1024use std::collections::HashMap;
@@ -1011,7 +1034,7 @@ fn doctest_replace_string_with_char() {
1011 "replace_string_with_char", 1034 "replace_string_with_char",
1012 r#####" 1035 r#####"
1013fn main() { 1036fn main() {
1014 find("{<|>"); 1037 find("{$0");
1015} 1038}
1016"#####, 1039"#####,
1017 r#####" 1040 r#####"
@@ -1030,7 +1053,7 @@ fn doctest_replace_unwrap_with_match() {
1030enum Result<T, E> { Ok(T), Err(E) } 1053enum Result<T, E> { Ok(T), Err(E) }
1031fn main() { 1054fn main() {
1032 let x: Result<i32, i32> = Result::Ok(92); 1055 let x: Result<i32, i32> = Result::Ok(92);
1033 let y = x.<|>unwrap(); 1056 let y = x.$0unwrap();
1034} 1057}
1035"#####, 1058"#####,
1036 r#####" 1059 r#####"
@@ -1051,7 +1074,7 @@ fn doctest_split_import() {
1051 check_doc_test( 1074 check_doc_test(
1052 "split_import", 1075 "split_import",
1053 r#####" 1076 r#####"
1054use std::<|>collections::HashMap; 1077use std::$0collections::HashMap;
1055"#####, 1078"#####,
1056 r#####" 1079 r#####"
1057use std::{collections::HashMap}; 1080use std::{collections::HashMap};
@@ -1064,7 +1087,7 @@ fn doctest_toggle_ignore() {
1064 check_doc_test( 1087 check_doc_test(
1065 "toggle_ignore", 1088 "toggle_ignore",
1066 r#####" 1089 r#####"
1067<|>#[test] 1090$0#[test]
1068fn arithmetics { 1091fn arithmetics {
1069 assert_eq!(2 + 2, 5); 1092 assert_eq!(2 + 2, 5);
1070} 1093}
@@ -1085,7 +1108,7 @@ fn doctest_unwrap_block() {
1085 "unwrap_block", 1108 "unwrap_block",
1086 r#####" 1109 r#####"
1087fn foo() { 1110fn foo() {
1088 if true {<|> 1111 if true {$0
1089 println!("foo"); 1112 println!("foo");
1090 } 1113 }
1091} 1114}
@@ -1103,7 +1126,7 @@ fn doctest_wrap_return_type_in_result() {
1103 check_doc_test( 1126 check_doc_test(
1104 "wrap_return_type_in_result", 1127 "wrap_return_type_in_result",
1105 r#####" 1128 r#####"
1106fn foo() -> i32<|> { 42i32 } 1129fn foo() -> i32$0 { 42i32 }
1107"#####, 1130"#####,
1108 r#####" 1131 r#####"
1109fn foo() -> Result<i32, ${0:_}> { Ok(42i32) } 1132fn foo() -> Result<i32, ${0:_}> { Ok(42i32) }