]> git.lizzy.rs Git - rust.git/blob - crates/ide-completion/src/tests/flyimport.rs
style: rename crates to kebab case
[rust.git] / crates / ide-completion / src / tests / flyimport.rs
1 use expect_test::{expect, Expect};
2
3 use crate::tests::{check_edit, check_edit_with_config, TEST_CONFIG};
4
5 fn check(ra_fixture: &str, expect: Expect) {
6     let config = TEST_CONFIG;
7     let (db, position) = crate::tests::position(ra_fixture);
8     let ctx = crate::context::CompletionContext::new(&db, position, &config).unwrap();
9
10     let mut acc = crate::completions::Completions::default();
11     crate::completions::flyimport::import_on_the_fly(&mut acc, &ctx);
12
13     expect.assert_eq(&super::render_completion_list(Vec::from(acc)));
14 }
15
16 #[test]
17 fn function_fuzzy_completion() {
18     check_edit(
19         "stdin",
20         r#"
21 //- /lib.rs crate:dep
22 pub mod io {
23     pub fn stdin() {}
24 };
25
26 //- /main.rs crate:main deps:dep
27 fn main() {
28     stdi$0
29 }
30 "#,
31         r#"
32 use dep::io::stdin;
33
34 fn main() {
35     stdin()$0
36 }
37 "#,
38     );
39 }
40
41 #[test]
42 fn macro_fuzzy_completion() {
43     check_edit(
44         "macro_with_curlies!",
45         r#"
46 //- /lib.rs crate:dep
47 /// Please call me as macro_with_curlies! {}
48 #[macro_export]
49 macro_rules! macro_with_curlies {
50     () => {}
51 }
52
53 //- /main.rs crate:main deps:dep
54 fn main() {
55     curli$0
56 }
57 "#,
58         r#"
59 use dep::macro_with_curlies;
60
61 fn main() {
62     macro_with_curlies! {$0}
63 }
64 "#,
65     );
66 }
67
68 #[test]
69 fn struct_fuzzy_completion() {
70     check_edit(
71         "ThirdStruct",
72         r#"
73 //- /lib.rs crate:dep
74 pub struct FirstStruct;
75 pub mod some_module {
76     pub struct SecondStruct;
77     pub struct ThirdStruct;
78 }
79
80 //- /main.rs crate:main deps:dep
81 use dep::{FirstStruct, some_module::SecondStruct};
82
83 fn main() {
84     this$0
85 }
86 "#,
87         r#"
88 use dep::{FirstStruct, some_module::{SecondStruct, ThirdStruct}};
89
90 fn main() {
91     ThirdStruct
92 }
93 "#,
94     );
95 }
96
97 #[test]
98 fn short_paths_are_ignored() {
99     cov_mark::check!(flyimport_exact_on_short_path);
100
101     check(
102         r#"
103 //- /lib.rs crate:dep
104 pub struct Bar;
105 pub struct Rcar;
106 pub struct Rc;
107 pub mod some_module {
108     pub struct Bar;
109     pub struct Rcar;
110     pub struct Rc;
111 }
112
113 //- /main.rs crate:main deps:dep
114 fn main() {
115     rc$0
116 }
117 "#,
118         expect![[r#"
119             st Rc (use dep::Rc)
120             st Rc (use dep::some_module::Rc)
121         "#]],
122     );
123 }
124
125 #[test]
126 fn fuzzy_completions_come_in_specific_order() {
127     cov_mark::check!(certain_fuzzy_order_test);
128     check(
129         r#"
130 //- /lib.rs crate:dep
131 pub struct FirstStruct;
132 pub mod some_module {
133     // already imported, omitted
134     pub struct SecondStruct;
135     // does not contain all letters from the query, omitted
136     pub struct UnrelatedOne;
137     // contains all letters from the query, but not in sequence, displayed last
138     pub struct ThiiiiiirdStruct;
139     // contains all letters from the query, but not in the beginning, displayed second
140     pub struct AfterThirdStruct;
141     // contains all letters from the query in the begginning, displayed first
142     pub struct ThirdStruct;
143 }
144
145 //- /main.rs crate:main deps:dep
146 use dep::{FirstStruct, some_module::SecondStruct};
147
148 fn main() {
149     hir$0
150 }
151 "#,
152         expect![[r#"
153                 st ThirdStruct (use dep::some_module::ThirdStruct)
154                 st AfterThirdStruct (use dep::some_module::AfterThirdStruct)
155                 st ThiiiiiirdStruct (use dep::some_module::ThiiiiiirdStruct)
156             "#]],
157     );
158 }
159
160 #[test]
161 fn trait_function_fuzzy_completion() {
162     let fixture = r#"
163         //- /lib.rs crate:dep
164         pub mod test_mod {
165             pub trait TestTrait {
166                 const SPECIAL_CONST: u8;
167                 type HumbleType;
168                 fn weird_function();
169                 fn random_method(&self);
170             }
171             pub struct TestStruct {}
172             impl TestTrait for TestStruct {
173                 const SPECIAL_CONST: u8 = 42;
174                 type HumbleType = ();
175                 fn weird_function() {}
176                 fn random_method(&self) {}
177             }
178         }
179
180         //- /main.rs crate:main deps:dep
181         fn main() {
182             dep::test_mod::TestStruct::wei$0
183         }
184         "#;
185
186     check(
187         fixture,
188         expect![[r#"
189                 fn weird_function() (use dep::test_mod::TestTrait) fn()
190             "#]],
191     );
192
193     check_edit(
194         "weird_function",
195         fixture,
196         r#"
197 use dep::test_mod::TestTrait;
198
199 fn main() {
200     dep::test_mod::TestStruct::weird_function()$0
201 }
202 "#,
203     );
204 }
205
206 #[test]
207 fn trait_const_fuzzy_completion() {
208     let fixture = r#"
209         //- /lib.rs crate:dep
210         pub mod test_mod {
211             pub trait TestTrait {
212                 const SPECIAL_CONST: u8;
213                 type HumbleType;
214                 fn weird_function();
215                 fn random_method(&self);
216             }
217             pub struct TestStruct {}
218             impl TestTrait for TestStruct {
219                 const SPECIAL_CONST: u8 = 42;
220                 type HumbleType = ();
221                 fn weird_function() {}
222                 fn random_method(&self) {}
223             }
224         }
225
226         //- /main.rs crate:main deps:dep
227         fn main() {
228             dep::test_mod::TestStruct::spe$0
229         }
230         "#;
231
232     check(
233         fixture,
234         expect![[r#"
235             ct SPECIAL_CONST (use dep::test_mod::TestTrait)
236         "#]],
237     );
238
239     check_edit(
240         "SPECIAL_CONST",
241         fixture,
242         r#"
243 use dep::test_mod::TestTrait;
244
245 fn main() {
246     dep::test_mod::TestStruct::SPECIAL_CONST
247 }
248 "#,
249     );
250 }
251
252 #[test]
253 fn trait_method_fuzzy_completion() {
254     let fixture = r#"
255         //- /lib.rs crate:dep
256         pub mod test_mod {
257             pub trait TestTrait {
258                 const SPECIAL_CONST: u8;
259                 type HumbleType;
260                 fn weird_function();
261                 fn random_method(&self);
262             }
263             pub struct TestStruct {}
264             impl TestTrait for TestStruct {
265                 const SPECIAL_CONST: u8 = 42;
266                 type HumbleType = ();
267                 fn weird_function() {}
268                 fn random_method(&self) {}
269             }
270         }
271
272         //- /main.rs crate:main deps:dep
273         fn main() {
274             let test_struct = dep::test_mod::TestStruct {};
275             test_struct.ran$0
276         }
277         "#;
278
279     check(
280         fixture,
281         expect![[r#"
282                 me random_method() (use dep::test_mod::TestTrait) fn(&self)
283             "#]],
284     );
285
286     check_edit(
287         "random_method",
288         fixture,
289         r#"
290 use dep::test_mod::TestTrait;
291
292 fn main() {
293     let test_struct = dep::test_mod::TestStruct {};
294     test_struct.random_method()$0
295 }
296 "#,
297     );
298 }
299
300 #[test]
301 fn trait_method_from_alias() {
302     let fixture = r#"
303 //- /lib.rs crate:dep
304 pub mod test_mod {
305     pub trait TestTrait {
306         fn random_method();
307     }
308     pub struct TestStruct {}
309     impl TestTrait for TestStruct {
310         fn random_method() {}
311     }
312     pub type TestAlias = TestStruct;
313 }
314
315 //- /main.rs crate:main deps:dep
316 fn main() {
317     dep::test_mod::TestAlias::ran$0
318 }
319 "#;
320
321     check(
322         fixture,
323         expect![[r#"
324                 fn random_method() (use dep::test_mod::TestTrait) fn()
325             "#]],
326     );
327
328     check_edit(
329         "random_method",
330         fixture,
331         r#"
332 use dep::test_mod::TestTrait;
333
334 fn main() {
335     dep::test_mod::TestAlias::random_method()$0
336 }
337 "#,
338     );
339 }
340
341 #[test]
342 fn no_trait_type_fuzzy_completion() {
343     check(
344         r#"
345 //- /lib.rs crate:dep
346 pub mod test_mod {
347     pub trait TestTrait {
348         const SPECIAL_CONST: u8;
349         type HumbleType;
350         fn weird_function();
351         fn random_method(&self);
352     }
353     pub struct TestStruct {}
354     impl TestTrait for TestStruct {
355         const SPECIAL_CONST: u8 = 42;
356         type HumbleType = ();
357         fn weird_function() {}
358         fn random_method(&self) {}
359     }
360 }
361
362 //- /main.rs crate:main deps:dep
363 fn main() {
364     dep::test_mod::TestStruct::hum$0
365 }
366 "#,
367         expect![[r#""#]],
368     );
369 }
370
371 #[test]
372 fn does_not_propose_names_in_scope() {
373     check(
374         r#"
375 //- /lib.rs crate:dep
376 pub mod test_mod {
377     pub trait TestTrait {
378         const SPECIAL_CONST: u8;
379         type HumbleType;
380         fn weird_function();
381         fn random_method(&self);
382     }
383     pub struct TestStruct {}
384     impl TestTrait for TestStruct {
385         const SPECIAL_CONST: u8 = 42;
386         type HumbleType = ();
387         fn weird_function() {}
388         fn random_method(&self) {}
389     }
390 }
391
392 //- /main.rs crate:main deps:dep
393 use dep::test_mod::TestStruct;
394 fn main() {
395     TestSt$0
396 }
397 "#,
398         expect![[r#""#]],
399     );
400 }
401
402 #[test]
403 fn does_not_propose_traits_in_scope() {
404     check(
405         r#"
406 //- /lib.rs crate:dep
407 pub mod test_mod {
408     pub trait TestTrait {
409         const SPECIAL_CONST: u8;
410         type HumbleType;
411         fn weird_function();
412         fn random_method(&self);
413     }
414     pub struct TestStruct {}
415     impl TestTrait for TestStruct {
416         const SPECIAL_CONST: u8 = 42;
417         type HumbleType = ();
418         fn weird_function() {}
419         fn random_method(&self) {}
420     }
421 }
422
423 //- /main.rs crate:main deps:dep
424 use dep::test_mod::{TestStruct, TestTrait};
425 fn main() {
426     dep::test_mod::TestStruct::hum$0
427 }
428 "#,
429         expect![[r#""#]],
430     );
431 }
432
433 #[test]
434 fn blanket_trait_impl_import() {
435     check_edit(
436         "another_function",
437         r#"
438 //- /lib.rs crate:dep
439 pub mod test_mod {
440     pub struct TestStruct {}
441     pub trait TestTrait {
442         fn another_function();
443     }
444     impl<T> TestTrait for T {
445         fn another_function() {}
446     }
447 }
448
449 //- /main.rs crate:main deps:dep
450 fn main() {
451     dep::test_mod::TestStruct::ano$0
452 }
453 "#,
454         r#"
455 use dep::test_mod::TestTrait;
456
457 fn main() {
458     dep::test_mod::TestStruct::another_function()$0
459 }
460 "#,
461     );
462 }
463
464 #[test]
465 fn zero_input_deprecated_assoc_item_completion() {
466     check(
467         r#"
468 //- /lib.rs crate:dep
469 pub mod test_mod {
470     #[deprecated]
471     pub trait TestTrait {
472         const SPECIAL_CONST: u8;
473         type HumbleType;
474         fn weird_function();
475         fn random_method(&self);
476     }
477     pub struct TestStruct {}
478     impl TestTrait for TestStruct {
479         const SPECIAL_CONST: u8 = 42;
480         type HumbleType = ();
481         fn weird_function() {}
482         fn random_method(&self) {}
483     }
484 }
485
486 //- /main.rs crate:main deps:dep
487 fn main() {
488     let test_struct = dep::test_mod::TestStruct {};
489     test_struct.$0
490 }
491         "#,
492         expect![[r#"
493                 me random_method() (use dep::test_mod::TestTrait) fn(&self) DEPRECATED
494             "#]],
495     );
496
497     check(
498         r#"
499 //- /lib.rs crate:dep
500 pub mod test_mod {
501     #[deprecated]
502     pub trait TestTrait {
503         const SPECIAL_CONST: u8;
504         type HumbleType;
505         fn weird_function();
506         fn random_method(&self);
507     }
508     pub struct TestStruct {}
509     impl TestTrait for TestStruct {
510         const SPECIAL_CONST: u8 = 42;
511         type HumbleType = ();
512         fn weird_function() {}
513         fn random_method(&self) {}
514     }
515 }
516
517 //- /main.rs crate:main deps:dep
518 fn main() {
519     dep::test_mod::TestStruct::$0
520 }
521 "#,
522         expect![[r#"
523                 fn weird_function() (use dep::test_mod::TestTrait) fn() DEPRECATED
524                 ct SPECIAL_CONST (use dep::test_mod::TestTrait) DEPRECATED
525             "#]],
526     );
527 }
528
529 #[test]
530 fn no_completions_in_use_statements() {
531     check(
532         r#"
533 //- /lib.rs crate:dep
534 pub mod io {
535     pub fn stdin() {}
536 };
537
538 //- /main.rs crate:main deps:dep
539 use stdi$0
540
541 fn main() {}
542 "#,
543         expect![[]],
544     );
545 }
546
547 #[test]
548 fn prefix_config_usage() {
549     let fixture = r#"
550 mod foo {
551     pub mod bar {
552         pub struct Item;
553     }
554 }
555
556 use crate::foo::bar;
557
558 fn main() {
559     Ite$0
560 }"#;
561     let mut config = TEST_CONFIG;
562
563     config.insert_use.prefix_kind = hir::PrefixKind::ByCrate;
564     check_edit_with_config(
565         config.clone(),
566         "Item",
567         fixture,
568         r#"
569 mod foo {
570     pub mod bar {
571         pub struct Item;
572     }
573 }
574
575 use crate::foo::bar::{self, Item};
576
577 fn main() {
578     Item
579 }"#,
580     );
581
582     config.insert_use.prefix_kind = hir::PrefixKind::BySelf;
583     check_edit_with_config(
584         config.clone(),
585         "Item",
586         fixture,
587         r#"
588 mod foo {
589     pub mod bar {
590         pub struct Item;
591     }
592 }
593
594 use crate::foo::bar;
595
596 use self::foo::bar::Item;
597
598 fn main() {
599     Item
600 }"#,
601     );
602
603     config.insert_use.prefix_kind = hir::PrefixKind::Plain;
604     check_edit_with_config(
605         config,
606         "Item",
607         fixture,
608         r#"
609 mod foo {
610     pub mod bar {
611         pub struct Item;
612     }
613 }
614
615 use foo::bar::Item;
616
617 use crate::foo::bar;
618
619 fn main() {
620     Item
621 }"#,
622     );
623 }
624
625 #[test]
626 fn unresolved_qualifier() {
627     let fixture = r#"
628 mod foo {
629     pub mod bar {
630         pub mod baz {
631             pub struct Item;
632         }
633     }
634 }
635
636 fn main() {
637     bar::baz::Ite$0
638 }"#;
639
640     check(
641         fixture,
642         expect![[r#"
643         st Item (use foo::bar::baz::Item)
644         "#]],
645     );
646
647     check_edit(
648         "Item",
649         fixture,
650         r#"
651         use foo::bar;
652
653         mod foo {
654             pub mod bar {
655                 pub mod baz {
656                     pub struct Item;
657                 }
658             }
659         }
660
661         fn main() {
662             bar::baz::Item
663         }"#,
664     );
665 }
666
667 #[test]
668 fn unresolved_assoc_item_container() {
669     let fixture = r#"
670 mod foo {
671     pub struct Item;
672
673     impl Item {
674         pub const TEST_ASSOC: usize = 3;
675     }
676 }
677
678 fn main() {
679     Item::TEST_A$0
680 }"#;
681
682     check(
683         fixture,
684         expect![[r#"
685         ct TEST_ASSOC (use foo::Item)
686         "#]],
687     );
688
689     check_edit(
690         "TEST_ASSOC",
691         fixture,
692         r#"
693 use foo::Item;
694
695 mod foo {
696     pub struct Item;
697
698     impl Item {
699         pub const TEST_ASSOC: usize = 3;
700     }
701 }
702
703 fn main() {
704     Item::TEST_ASSOC
705 }"#,
706     );
707 }
708
709 #[test]
710 fn unresolved_assoc_item_container_with_path() {
711     let fixture = r#"
712 mod foo {
713     pub mod bar {
714         pub struct Item;
715
716         impl Item {
717             pub const TEST_ASSOC: usize = 3;
718         }
719     }
720 }
721
722 fn main() {
723     bar::Item::TEST_A$0
724 }"#;
725
726     check(
727         fixture,
728         expect![[r#"
729         ct TEST_ASSOC (use foo::bar::Item)
730     "#]],
731     );
732
733     check_edit(
734         "TEST_ASSOC",
735         fixture,
736         r#"
737 use foo::bar;
738
739 mod foo {
740     pub mod bar {
741         pub struct Item;
742
743         impl Item {
744             pub const TEST_ASSOC: usize = 3;
745         }
746     }
747 }
748
749 fn main() {
750     bar::Item::TEST_ASSOC
751 }"#,
752     );
753 }
754
755 #[test]
756 fn fuzzy_unresolved_path() {
757     check(
758         r#"
759 mod foo {
760     pub mod bar {
761         pub struct Item;
762
763         impl Item {
764             pub const TEST_ASSOC: usize = 3;
765         }
766     }
767 }
768
769 fn main() {
770     bar::ASS$0
771 }"#,
772         expect![[]],
773     )
774 }
775
776 #[test]
777 fn unqualified_assoc_items_are_omitted() {
778     check(
779         r#"
780 mod something {
781     pub trait BaseTrait {
782         fn test_function() -> i32;
783     }
784
785     pub struct Item1;
786     pub struct Item2;
787
788     impl BaseTrait for Item1 {
789         fn test_function() -> i32 {
790             1
791         }
792     }
793
794     impl BaseTrait for Item2 {
795         fn test_function() -> i32 {
796             2
797         }
798     }
799 }
800
801 fn main() {
802     test_f$0
803 }"#,
804         expect![[]],
805     )
806 }
807
808 #[test]
809 fn case_matters() {
810     check(
811         r#"
812 mod foo {
813     pub const TEST_CONST: usize = 3;
814     pub fn test_function() -> i32 {
815         4
816     }
817 }
818
819 fn main() {
820     TES$0
821 }"#,
822         expect![[r#"
823         ct TEST_CONST (use foo::TEST_CONST)
824     "#]],
825     );
826
827     check(
828         r#"
829 mod foo {
830     pub const TEST_CONST: usize = 3;
831     pub fn test_function() -> i32 {
832         4
833     }
834 }
835
836 fn main() {
837     tes$0
838 }"#,
839         expect![[r#"
840         ct TEST_CONST (use foo::TEST_CONST)
841         fn test_function() (use foo::test_function) fn() -> i32
842     "#]],
843     );
844
845     check(
846         r#"
847 mod foo {
848     pub const TEST_CONST: usize = 3;
849     pub fn test_function() -> i32 {
850         4
851     }
852 }
853
854 fn main() {
855     Te$0
856 }"#,
857         expect![[]],
858     );
859 }
860
861 #[test]
862 fn no_fuzzy_during_fields_of_record_lit_syntax() {
863     check(
864         r#"
865 mod m {
866     pub fn some_fn() -> i32 {
867         42
868     }
869 }
870 struct Foo {
871     some_field: i32,
872 }
873 fn main() {
874     let _ = Foo { so$0 };
875 }
876 "#,
877         expect![[]],
878     );
879 }
880
881 #[test]
882 fn fuzzy_after_fields_of_record_lit_syntax() {
883     check(
884         r#"
885 mod m {
886     pub fn some_fn() -> i32 {
887         42
888     }
889 }
890 struct Foo {
891     some_field: i32,
892 }
893 fn main() {
894     let _ = Foo { some_field: som$0 };
895 }
896 "#,
897         expect![[r#"
898                 fn some_fn() (use m::some_fn) fn() -> i32
899             "#]],
900     );
901 }
902
903 #[test]
904 fn no_flyimports_in_traits_and_impl_declarations() {
905     check(
906         r#"
907 mod m {
908     pub fn some_fn() -> i32 {
909         42
910     }
911 }
912 trait Foo {
913     som$0
914 }
915 "#,
916         expect![[r#""#]],
917     );
918
919     check(
920         r#"
921 mod m {
922     pub fn some_fn() -> i32 {
923         42
924     }
925 }
926 struct Foo;
927 impl Foo {
928     som$0
929 }
930 "#,
931         expect![[r#""#]],
932     );
933
934     check(
935         r#"
936 mod m {
937     pub fn some_fn() -> i32 {
938         42
939     }
940 }
941 struct Foo;
942 trait Bar {}
943 impl Bar for Foo {
944     som$0
945 }
946 "#,
947         expect![[r#""#]],
948     );
949 }
950
951 #[test]
952 fn no_inherent_candidates_proposed() {
953     check(
954         r#"
955 mod baz {
956     pub trait DefDatabase {
957         fn method1(&self);
958     }
959     pub trait HirDatabase: DefDatabase {
960         fn method2(&self);
961     }
962 }
963
964 mod bar {
965     fn test(db: &dyn crate::baz::HirDatabase) {
966         db.metho$0
967     }
968 }
969             "#,
970         expect![[r#""#]],
971     );
972     check(
973         r#"
974 mod baz {
975     pub trait DefDatabase {
976         fn method1(&self);
977     }
978     pub trait HirDatabase: DefDatabase {
979         fn method2(&self);
980     }
981 }
982
983 mod bar {
984     fn test(db: &impl crate::baz::HirDatabase) {
985         db.metho$0
986     }
987 }
988 "#,
989         expect![[r#""#]],
990     );
991     check(
992         r#"
993 mod baz {
994     pub trait DefDatabase {
995         fn method1(&self);
996     }
997     pub trait HirDatabase: DefDatabase {
998         fn method2(&self);
999     }
1000 }
1001
1002 mod bar {
1003     fn test<T: crate::baz::HirDatabase>(db: T) {
1004         db.metho$0
1005     }
1006 }
1007 "#,
1008         expect![[r#""#]],
1009     );
1010 }
1011
1012 #[test]
1013 fn respects_doc_hidden() {
1014     check(
1015         r#"
1016 //- /lib.rs crate:lib deps:dep
1017 fn f() {
1018     ().fro$0
1019 }
1020
1021 //- /dep.rs crate:dep
1022 #[doc(hidden)]
1023 pub trait Private {
1024     fn frob(&self) {}
1025 }
1026
1027 impl<T> Private for T {}
1028             "#,
1029         expect![[r#""#]],
1030     );
1031     check(
1032         r#"
1033 //- /lib.rs crate:lib deps:dep
1034 fn f() {
1035     ().fro$0
1036 }
1037
1038 //- /dep.rs crate:dep
1039 pub trait Private {
1040     #[doc(hidden)]
1041     fn frob(&self) {}
1042 }
1043
1044 impl<T> Private for T {}
1045             "#,
1046         expect![[r#""#]],
1047     );
1048 }
1049
1050 #[test]
1051 fn regression_9760() {
1052     check(
1053         r#"
1054 struct Struct;
1055 fn main() {}
1056
1057 mod mud {
1058     fn func() {
1059         let struct_instance = Stru$0
1060     }
1061 }
1062 "#,
1063         expect![[r#"
1064                 st Struct (use crate::Struct)
1065             "#]],
1066     );
1067 }
1068
1069 #[test]
1070 fn flyimport_pattern() {
1071     check(
1072         r#"
1073 mod module {
1074     pub struct FooStruct {}
1075     pub const FooConst: () = ();
1076     pub fn foo_fun() {}
1077 }
1078 fn function() {
1079     let foo$0
1080 }
1081 "#,
1082         expect![[r#"
1083             ct FooConst (use module::FooConst)
1084             st FooStruct (use module::FooStruct)
1085         "#]],
1086     );
1087 }
1088
1089 #[test]
1090 fn flyimport_item_name() {
1091     check(
1092         r#"
1093 mod module {
1094     pub struct Struct;
1095 }
1096 struct Str$0
1097     "#,
1098         expect![[r#""#]],
1099     );
1100 }
1101
1102 #[test]
1103 fn flyimport_rename() {
1104     check(
1105         r#"
1106 mod module {
1107     pub struct Struct;
1108 }
1109 use self as Str$0;
1110     "#,
1111         expect![[r#""#]],
1112     );
1113 }
1114
1115 #[test]
1116 fn flyimport_enum_variant() {
1117     check(
1118         r#"
1119 mod foo {
1120     pub struct Barbara;
1121 }
1122
1123 enum Foo {
1124     Barba$0()
1125 }
1126 }"#,
1127         expect![[r#""#]],
1128     );
1129
1130     check(
1131         r#"
1132 mod foo {
1133     pub struct Barbara;
1134 }
1135
1136 enum Foo {
1137     Barba(Barba$0)
1138 }
1139 }"#,
1140         expect![[r#"
1141             st Barbara (use foo::Barbara)
1142         "#]],
1143     )
1144 }
1145
1146 #[test]
1147 fn flyimport_attribute() {
1148     check(
1149         r#"
1150 //- proc_macros:identity
1151 #[ide$0]
1152 struct Foo;
1153 "#,
1154         expect![[r#"
1155             at identity (use proc_macros::identity) proc_macro identity
1156         "#]],
1157     );
1158     check_edit(
1159         "identity",
1160         r#"
1161 //- proc_macros:identity
1162 #[ide$0]
1163 struct Foo;
1164 "#,
1165         r#"
1166 use proc_macros::identity;
1167
1168 #[identity]
1169 struct Foo;
1170 "#,
1171     );
1172 }
1173
1174 #[test]
1175 fn flyimport_in_type_bound_omits_types() {
1176     check(
1177         r#"
1178 mod module {
1179     pub struct CompletemeStruct;
1180     pub type CompletemeType = ();
1181     pub enum CompletemeEnum {}
1182     pub trait CompletemeTrait {}
1183 }
1184
1185 fn f<T>() where T: Comp$0
1186 "#,
1187         expect![[r#"
1188             tt CompletemeTrait (use module::CompletemeTrait)
1189         "#]],
1190     );
1191 }