1 //! Completion tests for attributes.
2 use expect_test::{expect, Expect};
4 use crate::tests::{check_edit, completion_list};
6 fn check(ra_fixture: &str, expect: Expect) {
7 let actual = completion_list(ra_fixture);
8 expect.assert_eq(&actual);
12 fn doesnt_complete_items() {
37 fn doesnt_complete_qualified() {
49 fn inside_nested_attr() {
50 check(r#"#[cfg($0)]"#, expect![[]])
54 fn with_existing_attr() {
56 r#"#[no_mangle] #[$0] mcall!();"#,
69 fn attr_on_source_file() {
87 at no_implicit_prelude
90 at recursion_limit = "…"
91 at type_length_limit = …
92 at windows_subsystem = "…"
119 r#"mod foo {#![$0]}"#,
133 at no_implicit_prelude
139 fn attr_on_macro_rules() {
141 r#"#[$0] macro_rules! foo {}"#,
162 fn attr_on_macro_def() {
164 r#"#[$0] macro foo {}"#,
183 fn attr_on_extern_crate() {
185 r#"#[$0] extern crate foo;"#,
226 fn attr_on_type_alias() {
228 r#"#[$0] type foo = ();"#,
247 fn attr_on_struct() {
249 r#"#[$0] struct Foo;"#,
273 r#"#[$0] enum Foo {}"#,
297 r#"#[$0] const FOO: () = ();"#,
316 fn attr_on_static() {
318 r#"#[$0] static FOO: () = ()"#,
334 at link_section = "…"
344 r#"#[$0] trait Foo {}"#,
366 r#"#[$0] impl () {}"#,
380 at automatically_derived
384 r#"impl () {#![$0]}"#,
403 fn attr_on_extern_block() {
405 r#"#[$0] extern {}"#,
423 r#"extern {#![$0]}"#,
443 fn attr_on_variant() {
445 r#"enum Foo { #[$0] Bar }"#,
461 r#"#[$0] fn main() {}"#,
477 at link_section = "…"
484 at proc_macro_derive(…)
485 at proc_macro_attribute
487 at target_feature = "…"
496 cov_mark::check!(no_keyword_completion_in_attr_of_expr);
498 r#"fn main() { #[$0] foo() }"#,
511 fn attr_in_source_file_end() {
516 at automatically_derived
533 at link_section = "…"
542 at proc_macro_attribute
543 at proc_macro_derive(…)
546 at target_feature = "…"
559 fn cfg_target_endian() {
561 r#"#[cfg(target_endian = $0"#,
573 fn check_derive(ra_fixture: &str, expect: Expect) {
574 let actual = completion_list(ra_fixture);
575 expect.assert_eq(&actual);
579 fn no_completion_for_incorrect_derive() {
582 //- minicore: derive, copy, clone, ord, eq, default, fmt
583 #[derive{$0)] struct Test;
593 //- minicore: derive, copy, clone, ord, eq, default, fmt
594 #[derive($0)] struct Test;
601 de PartialEq, Eq, PartialOrd, Ord
603 de PartialEq, PartialOrd
609 fn derive_with_input_before() {
612 //- minicore: derive, copy, clone, ord, eq, default, fmt
613 #[derive(serde::Serialize, PartialEq, $0)] struct Test;
619 de Eq, PartialOrd, Ord
627 fn derive_with_input_after() {
630 //- minicore: derive, copy, clone, ord, eq, default, fmt
631 #[derive($0 serde::Serialize, PartialEq)] struct Test;
637 de Eq, PartialOrd, Ord
645 fn derive_flyimport() {
648 //- proc_macros: derive_identity
649 #[derive(der$0)] struct Test;
652 de DeriveIdentity (use proc_macros::DeriveIdentity)
657 //- proc_macros: derive_identity
658 use proc_macros::DeriveIdentity;
659 #[derive(der$0)] struct Test;
668 fn derive_flyimport_edit() {
672 //- proc_macros: derive_identity
673 #[derive(der$0)] struct Test;
676 use proc_macros::DeriveIdentity;
678 #[derive(DeriveIdentity)] struct Test;
691 r#"#[allow($0)] struct Test;"#,
692 r#"#[allow(deprecated)] struct Test;"#,
697 fn lint_with_existing() {
700 r#"#[allow(keyword_idents, $0)] struct Test;"#,
701 r#"#[allow(keyword_idents, deprecated)] struct Test;"#,
706 fn lint_qualified() {
709 r#"#[allow(keyword_idents, $0)] struct Test;"#,
710 r#"#[allow(keyword_idents, deprecated)] struct Test;"#,
718 r#"#[feature(box_$0)] struct Test;"#,
719 r#"#[feature(box_syntax)] struct Test;"#,
724 fn lint_clippy_unqualified() {
726 "clippy::as_conversions",
727 r#"#[allow($0)] struct Test;"#,
728 r#"#[allow(clippy::as_conversions)] struct Test;"#,
733 fn lint_clippy_qualified() {
736 r#"#[allow(clippy::$0)] struct Test;"#,
737 r#"#[allow(clippy::as_conversions)] struct Test;"#,
742 fn lint_rustdoc_unqualified() {
744 "rustdoc::bare_urls",
745 r#"#[allow($0)] struct Test;"#,
746 r#"#[allow(rustdoc::bare_urls)] struct Test;"#,
751 fn lint_rustdoc_qualified() {
754 r#"#[allow(rustdoc::$0)] struct Test;"#,
755 r#"#[allow(rustdoc::bare_urls)] struct Test;"#,
763 fn check_repr(ra_fixture: &str, expect: Expect) {
764 let actual = completion_list(ra_fixture);
765 expect.assert_eq(&actual);
769 fn no_completion_for_incorrect_repr() {
770 check_repr(r#"#[repr{$0)] struct Test;"#, expect![[]])
776 r#"#[repr($0)] struct Test;"#,
800 check_repr(r#"#[repr(transparent, $0)] struct Test;"#, expect![[r#""#]]);
806 r#"#[repr(align(1), $0)] struct Test;"#,
829 r#"#[repr(packed, $0)] struct Test;"#,
852 r#"#[repr(C, $0)] struct Test;"#,
875 r#"#[repr(usize, $0)] struct Test;"#,