diff options
author | Kirill Bulatov <[email protected]> | 2020-09-08 00:26:55 +0100 |
---|---|---|
committer | Kirill Bulatov <[email protected]> | 2020-09-09 23:42:20 +0100 |
commit | 5aebf54fd4d075389ce2c74a460ea0c48ccdbad2 (patch) | |
tree | faef62064ec661d3577d98d59e8d19f307b29163 /crates/ide/src | |
parent | dbf70cd015454cf125fda9b006251fa2782fbc7f (diff) |
Add tests
Diffstat (limited to 'crates/ide/src')
-rw-r--r-- | crates/ide/src/completion/complete_mod.rs | 153 |
1 files changed, 153 insertions, 0 deletions
diff --git a/crates/ide/src/completion/complete_mod.rs b/crates/ide/src/completion/complete_mod.rs index b5f2d636c..049e99674 100644 --- a/crates/ide/src/completion/complete_mod.rs +++ b/crates/ide/src/completion/complete_mod.rs | |||
@@ -147,3 +147,156 @@ fn module_chain_to_containing_module_file( | |||
147 | 147 | ||
148 | path | 148 | path |
149 | } | 149 | } |
150 | |||
151 | #[cfg(test)] | ||
152 | mod tests { | ||
153 | use crate::completion::{test_utils::completion_list, CompletionKind}; | ||
154 | use expect_test::{expect, Expect}; | ||
155 | |||
156 | fn check(ra_fixture: &str, expect: Expect) { | ||
157 | let actual = completion_list(ra_fixture, CompletionKind::Magic); | ||
158 | expect.assert_eq(&actual); | ||
159 | } | ||
160 | |||
161 | #[test] | ||
162 | fn lib_module_completion() { | ||
163 | check( | ||
164 | r#" | ||
165 | //- /lib.rs | ||
166 | mod <|> | ||
167 | //- /foo.rs | ||
168 | fn foo() {} | ||
169 | //- /foo/ignored_foo.rs | ||
170 | fn ignored_foo() {} | ||
171 | //- /bar/mod.rs | ||
172 | fn bar() {} | ||
173 | //- /bar/ignored_bar.rs | ||
174 | fn ignored_bar() {} | ||
175 | "#, | ||
176 | expect![[r#" | ||
177 | md bar; | ||
178 | md foo; | ||
179 | "#]], | ||
180 | ); | ||
181 | } | ||
182 | |||
183 | #[test] | ||
184 | fn main_module_completion() { | ||
185 | check( | ||
186 | r#" | ||
187 | //- /main.rs | ||
188 | mod <|> | ||
189 | //- /foo.rs | ||
190 | fn foo() {} | ||
191 | //- /foo/ignored_foo.rs | ||
192 | fn ignored_foo() {} | ||
193 | //- /bar/mod.rs | ||
194 | fn bar() {} | ||
195 | //- /bar/ignored_bar.rs | ||
196 | fn ignored_bar() {} | ||
197 | "#, | ||
198 | expect![[r#" | ||
199 | md bar; | ||
200 | md foo; | ||
201 | "#]], | ||
202 | ); | ||
203 | } | ||
204 | |||
205 | #[test] | ||
206 | fn main_test_module_completion() { | ||
207 | check( | ||
208 | r#" | ||
209 | //- /main.rs | ||
210 | mod tests { | ||
211 | mod <|>; | ||
212 | } | ||
213 | //- /tests/foo.rs | ||
214 | fn foo() {} | ||
215 | "#, | ||
216 | expect![[r#" | ||
217 | md foo | ||
218 | "#]], | ||
219 | ); | ||
220 | } | ||
221 | |||
222 | #[test] | ||
223 | fn directly_nested_module_completion() { | ||
224 | check( | ||
225 | r#" | ||
226 | //- /lib.rs | ||
227 | mod foo; | ||
228 | //- /foo.rs | ||
229 | mod <|>; | ||
230 | //- /foo/bar.rs | ||
231 | fn bar() {} | ||
232 | //- /foo/bar/ignored_bar.rs | ||
233 | fn ignored_bar() {} | ||
234 | //- /foo/baz/mod.rs | ||
235 | fn baz() {} | ||
236 | //- /foo/moar/ignored_moar.rs | ||
237 | fn ignored_moar() {} | ||
238 | "#, | ||
239 | expect![[r#" | ||
240 | md bar | ||
241 | md baz | ||
242 | "#]], | ||
243 | ); | ||
244 | } | ||
245 | |||
246 | #[test] | ||
247 | fn nested_in_source_module_completion() { | ||
248 | check( | ||
249 | r#" | ||
250 | //- /lib.rs | ||
251 | mod foo; | ||
252 | //- /foo.rs | ||
253 | mod bar { | ||
254 | mod <|> | ||
255 | } | ||
256 | //- /foo/bar/baz.rs | ||
257 | fn baz() {} | ||
258 | "#, | ||
259 | expect![[r#" | ||
260 | md baz; | ||
261 | "#]], | ||
262 | ); | ||
263 | } | ||
264 | |||
265 | // FIXME binart modules are not picked up in tests | ||
266 | // #[test] | ||
267 | // fn regular_bin_module_completion() { | ||
268 | // check( | ||
269 | // r#" | ||
270 | // //- /src/main.rs | ||
271 | // fn main() {} | ||
272 | // //- /src/main/foo.rs | ||
273 | // mod <|> | ||
274 | // //- /src/main/bar.rs | ||
275 | // fn bar() {} | ||
276 | // //- /src/main/bar/bar_ignored.rs | ||
277 | // fn bar_ignored() {} | ||
278 | // "#, | ||
279 | // expect![[r#" | ||
280 | // md bar; | ||
281 | // "#]], | ||
282 | // ); | ||
283 | // } | ||
284 | |||
285 | #[test] | ||
286 | fn already_declared_bin_module_completion_omitted() { | ||
287 | check( | ||
288 | r#" | ||
289 | //- /src/main.rs | ||
290 | fn main() {} | ||
291 | //- /src/main/foo.rs | ||
292 | mod <|> | ||
293 | //- /src/main/bar.rs | ||
294 | mod foo; | ||
295 | fn bar() {} | ||
296 | //- /src/main/bar/bar_ignored.rs | ||
297 | fn bar_ignored() {} | ||
298 | "#, | ||
299 | expect![[r#""#]], | ||
300 | ); | ||
301 | } | ||
302 | } | ||