aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion/src/completions/attribute
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-05-29 16:33:57 +0100
committerGitHub <[email protected]>2021-05-29 16:33:57 +0100
commit3fa3343e4747c3f7b2ca3e7924ba5286d67af87c (patch)
tree9cc564b0f752609b7dbedbd386b4673a98600bd2 /crates/ide_completion/src/completions/attribute
parent8cd98bde39c67af8a5ab742b6a688edd355f5025 (diff)
parentc9598a4cbfdf4b0d0d993043dca48c1615b63145 (diff)
Merge #9048
9048: Add some lint completion tests r=Veykril a=Veykril bors r+ Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/ide_completion/src/completions/attribute')
-rw-r--r--crates/ide_completion/src/completions/attribute/derive.rs38
-rw-r--r--crates/ide_completion/src/completions/attribute/lint.rs33
2 files changed, 55 insertions, 16 deletions
diff --git a/crates/ide_completion/src/completions/attribute/derive.rs b/crates/ide_completion/src/completions/attribute/derive.rs
index 7b0a778a2..634c0cb00 100644
--- a/crates/ide_completion/src/completions/attribute/derive.rs
+++ b/crates/ide_completion/src/completions/attribute/derive.rs
@@ -45,6 +45,7 @@ pub(super) fn complete_derive(
45 } 45 }
46 } 46 }
47} 47}
48
48fn get_derive_names_in_scope(ctx: &CompletionContext) -> FxHashSet<String> { 49fn get_derive_names_in_scope(ctx: &CompletionContext) -> FxHashSet<String> {
49 let mut result = FxHashSet::default(); 50 let mut result = FxHashSet::default();
50 ctx.scope.process_all_names(&mut |name, scope_def| { 51 ctx.scope.process_all_names(&mut |name, scope_def| {
@@ -89,12 +90,14 @@ mod tests {
89 } 90 }
90 91
91 #[test] 92 #[test]
92 fn empty_derive_completion() { 93 fn no_completion_for_incorrect_derive() {
94 check(r#"#[derive{$0)] struct Test;"#, expect![[]])
95 }
96
97 #[test]
98 fn empty_derive() {
93 check( 99 check(
94 r#" 100 r#"#[derive($0)] struct Test;"#,
95#[derive($0)]
96struct Test {}
97 "#,
98 expect![[r#" 101 expect![[r#"
99 at Clone 102 at Clone
100 at Clone, Copy 103 at Clone, Copy
@@ -110,23 +113,26 @@ struct Test {}
110 } 113 }
111 114
112 #[test] 115 #[test]
113 fn no_completion_for_incorrect_derive() { 116 fn derive_with_input() {
114 check( 117 check(
115 r#" 118 r#"#[derive(serde::Serialize, PartialEq, $0)] struct Test;"#,
116#[derive{$0)] 119 expect![[r#"
117struct Test {} 120 at Clone
118"#, 121 at Clone, Copy
119 expect![[r#""#]], 122 at Debug
123 at Default
124 at Hash
125 at Eq
126 at PartialOrd
127 at Eq, PartialOrd, Ord
128 "#]],
120 ) 129 )
121 } 130 }
122 131
123 #[test] 132 #[test]
124 fn derive_with_input_completion() { 133 fn derive_with_input2() {
125 check( 134 check(
126 r#" 135 r#"#[derive($0 serde::Serialize, PartialEq)] struct Test;"#,
127#[derive(serde::Serialize, PartialEq, $0)]
128struct Test {}
129"#,
130 expect![[r#" 136 expect![[r#"
131 at Clone 137 at Clone
132 at Clone, Copy 138 at Clone, Copy
diff --git a/crates/ide_completion/src/completions/attribute/lint.rs b/crates/ide_completion/src/completions/attribute/lint.rs
index 115c6cfe0..403630dce 100644
--- a/crates/ide_completion/src/completions/attribute/lint.rs
+++ b/crates/ide_completion/src/completions/attribute/lint.rs
@@ -152,3 +152,36 @@ pub(super) const DEFAULT_LINT_COMPLETIONS: &[LintCompletion] = &[
152 LintCompletion { label: "unconditional_panic", description: r#"operation will cause a panic at runtime"# }, 152 LintCompletion { label: "unconditional_panic", description: r#"operation will cause a panic at runtime"# },
153 LintCompletion { label: "unknown_crate_types", description: r#"unknown crate type found in `#[crate_type]` directive"# }, 153 LintCompletion { label: "unknown_crate_types", description: r#"unknown crate type found in `#[crate_type]` directive"# },
154]; 154];
155
156#[cfg(test)]
157mod tests {
158
159 use crate::test_utils::check_edit;
160
161 #[test]
162 fn check_empty() {
163 check_edit(
164 "deprecated",
165 r#"#[allow($0)] struct Test;"#,
166 r#"#[allow(deprecated)] struct Test;"#,
167 )
168 }
169
170 #[test]
171 fn check_with_existing() {
172 check_edit(
173 "deprecated",
174 r#"#[allow(keyword_idents, $0)] struct Test;"#,
175 r#"#[allow(keyword_idents, deprecated)] struct Test;"#,
176 )
177 }
178
179 #[test]
180 fn check_qualified() {
181 check_edit(
182 "deprecated",
183 r#"#[allow(keyword_idents, $0)] struct Test;"#,
184 r#"#[allow(keyword_idents, deprecated)] struct Test;"#,
185 )
186 }
187}