diff options
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r-- | crates/ra_ide/src/completion/complete_keyword.rs | 52 |
1 files changed, 34 insertions, 18 deletions
diff --git a/crates/ra_ide/src/completion/complete_keyword.rs b/crates/ra_ide/src/completion/complete_keyword.rs index 2e76f8592..feaa438af 100644 --- a/crates/ra_ide/src/completion/complete_keyword.rs +++ b/crates/ra_ide/src/completion/complete_keyword.rs | |||
@@ -118,43 +118,59 @@ mod tests { | |||
118 | }, | 118 | }, |
119 | CompletionItemKind, | 119 | CompletionItemKind, |
120 | }; | 120 | }; |
121 | use insta::{assert_snapshot, assert_debug_snapshot}; | 121 | use insta::assert_debug_snapshot; |
122 | use rustc_hash::FxHashSet; | ||
123 | 122 | ||
124 | fn do_keyword_completion(code: &str) -> Vec<CompletionItem> { | 123 | fn do_keyword_completion(code: &str) -> Vec<CompletionItem> { |
125 | do_completion(code, CompletionKind::Keyword) | 124 | do_completion(code, CompletionKind::Keyword) |
126 | } | 125 | } |
127 | 126 | ||
128 | fn assert_completion_keyword(code: &str, keywords: &[(&str, &str)]) { | 127 | fn get_completion_text_and_assert_positions(code: &str) -> Vec<(String, String)> { |
129 | let (position, completion_items) = | 128 | let (position, completion_items) = |
130 | do_completion_with_position(code, CompletionKind::Keyword); | 129 | do_completion_with_position(code, CompletionKind::Keyword); |
131 | let mut expected_keywords = FxHashSet::<(String, String)>::default(); | 130 | let mut returned_keywords = Vec::<(String, String)>::new(); |
132 | for (key, value) in keywords { | 131 | |
133 | expected_keywords.insert(((*key).to_string(), (*value).to_string())); | ||
134 | } | ||
135 | let mut returned_keywords = FxHashSet::<(String, String)>::default(); | ||
136 | |||
137 | for item in completion_items { | 132 | for item in completion_items { |
138 | assert!(item.text_edit().len() == 1); | 133 | debug_assert!(item.text_edit().len() == 1); |
139 | assert!(item.kind() == Some(CompletionItemKind::Keyword)); | 134 | assert!(item.kind() == Some(CompletionItemKind::Keyword)); |
140 | let atom = item.text_edit().iter().next().unwrap().clone(); | 135 | let atom = item.text_edit().iter().next().unwrap().clone(); |
141 | assert!(atom.delete.start() == position.offset); | 136 | assert!(atom.delete.start() == position.offset); |
142 | assert!(atom.delete.end() == position.offset); | 137 | assert!(atom.delete.end() == position.offset); |
143 | let pair = (item.label().to_string(), atom.insert); | 138 | let pair = (item.label().to_string(), atom.insert); |
144 | returned_keywords.insert(pair); | 139 | returned_keywords.push(pair); |
145 | } | 140 | } |
146 | let assert_failed_message = format!("Expected keywords: {:#?}\nReceived keywords: {:#?}", expected_keywords, returned_keywords); | 141 | returned_keywords.sort(); |
147 | debug_assert!(returned_keywords == expected_keywords, assert_failed_message); | 142 | returned_keywords |
148 | } | 143 | } |
149 | 144 | ||
150 | #[test] | 145 | #[test] |
151 | fn completes_keywords_in_use_stmt_new_approach() { | 146 | fn completes_keywords_in_use_stmt_new_approach() { |
152 | assert_completion_keyword( | 147 | assert_debug_snapshot!( |
153 | r" | 148 | get_completion_text_and_assert_positions(r" |
154 | use <|> | 149 | use <|> |
155 | ", | 150 | "), |
156 | &[("crate", "crate::"), ("self", "self"), ("super", "super::")], | 151 | @r###" |
152 | [ | ||
153 | ( | ||
154 | "crate", | ||
155 | "crate::", | ||
156 | ), | ||
157 | ( | ||
158 | "self", | ||
159 | "self", | ||
160 | ), | ||
161 | ( | ||
162 | "super", | ||
163 | "super::", | ||
164 | ), | ||
165 | ] | ||
166 | "### | ||
157 | ); | 167 | ); |
168 | // assert_completion_keyword( | ||
169 | // r" | ||
170 | // use <|> | ||
171 | // ", | ||
172 | // &[("crate", "crate::"), ("self", "self"), ("super", "super::")], | ||
173 | // ); | ||
158 | } | 174 | } |
159 | 175 | ||
160 | #[test] | 176 | #[test] |