diff options
Diffstat (limited to 'crates/ra_ide/src/completion/complete_keyword.rs')
-rw-r--r-- | crates/ra_ide/src/completion/complete_keyword.rs | 414 |
1 files changed, 207 insertions, 207 deletions
diff --git a/crates/ra_ide/src/completion/complete_keyword.rs b/crates/ra_ide/src/completion/complete_keyword.rs index e599cc3d1..34d061f5a 100644 --- a/crates/ra_ide/src/completion/complete_keyword.rs +++ b/crates/ra_ide/src/completion/complete_keyword.rs | |||
@@ -174,289 +174,289 @@ fn complete_return( | |||
174 | 174 | ||
175 | #[cfg(test)] | 175 | #[cfg(test)] |
176 | mod tests { | 176 | mod tests { |
177 | use crate::completion::{test_utils::completion_list, CompletionKind}; | 177 | use expect::{expect, Expect}; |
178 | use insta::assert_snapshot; | ||
179 | 178 | ||
180 | fn get_keyword_completions(code: &str) -> String { | 179 | use crate::completion::{ |
181 | completion_list(code, CompletionKind::Keyword) | 180 | test_utils::{check_edit, completion_list}, |
181 | CompletionKind, | ||
182 | }; | ||
183 | |||
184 | fn check(ra_fixture: &str, expect: Expect) { | ||
185 | let actual = completion_list(ra_fixture, CompletionKind::Keyword); | ||
186 | expect.assert_eq(&actual) | ||
182 | } | 187 | } |
183 | 188 | ||
184 | #[test] | 189 | #[test] |
185 | fn test_keywords_in_use_stmt() { | 190 | fn test_keywords_in_use_stmt() { |
186 | assert_snapshot!( | 191 | check( |
187 | get_keyword_completions(r"use <|>"), | 192 | r"use <|>", |
188 | @r###" | 193 | expect![[r#" |
189 | kw crate:: | 194 | kw crate:: |
190 | kw self | 195 | kw self |
191 | kw super:: | 196 | kw super:: |
192 | "### | 197 | "#]], |
193 | ); | 198 | ); |
194 | 199 | ||
195 | assert_snapshot!( | 200 | check( |
196 | get_keyword_completions(r"use a::<|>"), | 201 | r"use a::<|>", |
197 | @r###" | 202 | expect![[r#" |
198 | kw self | 203 | kw self |
199 | kw super:: | 204 | kw super:: |
200 | "### | 205 | "#]], |
201 | ); | 206 | ); |
202 | 207 | ||
203 | assert_snapshot!( | 208 | check( |
204 | get_keyword_completions(r"use a::{b, <|>}"), | 209 | r"use a::{b, <|>}", |
205 | @r###" | 210 | expect![[r#" |
206 | kw self | 211 | kw self |
207 | kw super:: | 212 | kw super:: |
208 | "### | 213 | "#]], |
209 | ); | 214 | ); |
210 | } | 215 | } |
211 | 216 | ||
212 | #[test] | 217 | #[test] |
213 | fn test_keywords_at_source_file_level() { | 218 | fn test_keywords_at_source_file_level() { |
214 | assert_snapshot!( | 219 | check( |
215 | get_keyword_completions(r"m<|>"), | 220 | r"m<|>", |
216 | @r###" | 221 | expect![[r#" |
217 | kw const | 222 | kw const |
218 | kw enum | 223 | kw enum |
219 | kw extern | 224 | kw extern |
220 | kw fn | 225 | kw fn |
221 | kw impl | 226 | kw impl |
222 | kw mod | 227 | kw mod |
223 | kw pub | 228 | kw pub |
224 | kw static | 229 | kw static |
225 | kw struct | 230 | kw struct |
226 | kw trait | 231 | kw trait |
227 | kw type | 232 | kw type |
228 | kw union | 233 | kw union |
229 | kw unsafe | 234 | kw unsafe |
230 | kw use | 235 | kw use |
231 | "### | 236 | "#]], |
232 | ); | 237 | ); |
233 | } | 238 | } |
234 | 239 | ||
235 | #[test] | 240 | #[test] |
236 | fn test_keywords_in_function() { | 241 | fn test_keywords_in_function() { |
237 | assert_snapshot!( | 242 | check( |
238 | get_keyword_completions(r"fn quux() { <|> }"), | 243 | r"fn quux() { <|> }", |
239 | @r###" | 244 | expect![[r#" |
240 | kw const | 245 | kw const |
241 | kw extern | 246 | kw extern |
242 | kw fn | 247 | kw fn |
243 | kw if | 248 | kw if |
244 | kw if let | 249 | kw if let |
245 | kw impl | 250 | kw impl |
246 | kw let | 251 | kw let |
247 | kw loop | 252 | kw loop |
248 | kw match | 253 | kw match |
249 | kw mod | 254 | kw mod |
250 | kw return | 255 | kw return |
251 | kw static | 256 | kw static |
252 | kw trait | 257 | kw trait |
253 | kw type | 258 | kw type |
254 | kw unsafe | 259 | kw unsafe |
255 | kw use | 260 | kw use |
256 | kw while | 261 | kw while |
257 | "### | 262 | "#]], |
258 | ); | 263 | ); |
259 | } | 264 | } |
260 | 265 | ||
261 | #[test] | 266 | #[test] |
262 | fn test_keywords_inside_block() { | 267 | fn test_keywords_inside_block() { |
263 | assert_snapshot!( | 268 | check( |
264 | get_keyword_completions(r"fn quux() { if true { <|> } }"), | 269 | r"fn quux() { if true { <|> } }", |
265 | @r###" | 270 | expect![[r#" |
266 | kw const | 271 | kw const |
267 | kw extern | 272 | kw extern |
268 | kw fn | 273 | kw fn |
269 | kw if | 274 | kw if |
270 | kw if let | 275 | kw if let |
271 | kw impl | 276 | kw impl |
272 | kw let | 277 | kw let |
273 | kw loop | 278 | kw loop |
274 | kw match | 279 | kw match |
275 | kw mod | 280 | kw mod |
276 | kw return | 281 | kw return |
277 | kw static | 282 | kw static |
278 | kw trait | 283 | kw trait |
279 | kw type | 284 | kw type |
280 | kw unsafe | 285 | kw unsafe |
281 | kw use | 286 | kw use |
282 | kw while | 287 | kw while |
283 | "### | 288 | "#]], |
284 | ); | 289 | ); |
285 | } | 290 | } |
286 | 291 | ||
287 | #[test] | 292 | #[test] |
288 | fn test_keywords_after_if() { | 293 | fn test_keywords_after_if() { |
289 | assert_snapshot!( | 294 | check( |
290 | get_keyword_completions( | 295 | r#"fn quux() { if true { () } <|> }"#, |
291 | r" | 296 | expect![[r#" |
292 | fn quux() { | 297 | kw const |
293 | if true { | 298 | kw else |
294 | () | 299 | kw else if |
295 | } <|> | 300 | kw extern |
296 | } | 301 | kw fn |
297 | ", | 302 | kw if |
298 | ), | 303 | kw if let |
299 | @r###" | 304 | kw impl |
300 | kw const | 305 | kw let |
301 | kw else | 306 | kw loop |
302 | kw else if | 307 | kw match |
303 | kw extern | 308 | kw mod |
304 | kw fn | 309 | kw return |
305 | kw if | 310 | kw static |
306 | kw if let | 311 | kw trait |
307 | kw impl | 312 | kw type |
308 | kw let | 313 | kw unsafe |
309 | kw loop | 314 | kw use |
310 | kw match | 315 | kw while |
311 | kw mod | 316 | "#]], |
312 | kw return | 317 | ); |
313 | kw static | 318 | check_edit( |
314 | kw trait | 319 | "else", |
315 | kw type | 320 | r#"fn quux() { if true { () } <|> }"#, |
316 | kw unsafe | 321 | r#"fn quux() { if true { () } else {$0} }"#, |
317 | kw use | ||
318 | kw while | ||
319 | "### | ||
320 | ); | 322 | ); |
321 | } | 323 | } |
322 | 324 | ||
323 | #[test] | 325 | #[test] |
324 | fn test_keywords_in_match_arm() { | 326 | fn test_keywords_in_match_arm() { |
325 | assert_snapshot!( | 327 | check( |
326 | get_keyword_completions( | 328 | r#" |
327 | r" | 329 | fn quux() -> i32 { |
328 | fn quux() -> i32 { | 330 | match () { |
329 | match () { | 331 | () => <|> |
330 | () => <|> | 332 | } |
331 | } | 333 | } |
332 | } | 334 | "#, |
333 | ", | 335 | expect![[r#" |
334 | ), | 336 | kw if |
335 | @r###" | 337 | kw if let |
336 | kw if | 338 | kw loop |
337 | kw if let | 339 | kw match |
338 | kw loop | 340 | kw return |
339 | kw match | 341 | kw unsafe |
340 | kw return | 342 | "#]], |
341 | kw unsafe | ||
342 | "### | ||
343 | ); | 343 | ); |
344 | } | 344 | } |
345 | 345 | ||
346 | #[test] | 346 | #[test] |
347 | fn test_keywords_in_trait_def() { | 347 | fn test_keywords_in_trait_def() { |
348 | assert_snapshot!( | 348 | check( |
349 | get_keyword_completions(r"trait My { <|> }"), | 349 | r"trait My { <|> }", |
350 | @r###" | 350 | expect![[r#" |
351 | kw const | 351 | kw const |
352 | kw fn | 352 | kw fn |
353 | kw type | 353 | kw type |
354 | kw unsafe | 354 | kw unsafe |
355 | "### | 355 | "#]], |
356 | ); | 356 | ); |
357 | } | 357 | } |
358 | 358 | ||
359 | #[test] | 359 | #[test] |
360 | fn test_keywords_in_impl_def() { | 360 | fn test_keywords_in_impl_def() { |
361 | assert_snapshot!( | 361 | check( |
362 | get_keyword_completions(r"impl My { <|> }"), | 362 | r"impl My { <|> }", |
363 | @r###" | 363 | expect![[r#" |
364 | kw const | 364 | kw const |
365 | kw fn | 365 | kw fn |
366 | kw pub | 366 | kw pub |
367 | kw type | 367 | kw type |
368 | kw unsafe | 368 | kw unsafe |
369 | "### | 369 | "#]], |
370 | ); | 370 | ); |
371 | } | 371 | } |
372 | 372 | ||
373 | #[test] | 373 | #[test] |
374 | fn test_keywords_in_loop() { | 374 | fn test_keywords_in_loop() { |
375 | assert_snapshot!( | 375 | check( |
376 | get_keyword_completions(r"fn my() { loop { <|> } }"), | 376 | r"fn my() { loop { <|> } }", |
377 | @r###" | 377 | expect![[r#" |
378 | kw break | 378 | kw break |
379 | kw const | 379 | kw const |
380 | kw continue | 380 | kw continue |
381 | kw extern | 381 | kw extern |
382 | kw fn | 382 | kw fn |
383 | kw if | 383 | kw if |
384 | kw if let | 384 | kw if let |
385 | kw impl | 385 | kw impl |
386 | kw let | 386 | kw let |
387 | kw loop | 387 | kw loop |
388 | kw match | 388 | kw match |
389 | kw mod | 389 | kw mod |
390 | kw return | 390 | kw return |
391 | kw static | 391 | kw static |
392 | kw trait | 392 | kw trait |
393 | kw type | 393 | kw type |
394 | kw unsafe | 394 | kw unsafe |
395 | kw use | 395 | kw use |
396 | kw while | 396 | kw while |
397 | "### | 397 | "#]], |
398 | ); | 398 | ); |
399 | } | 399 | } |
400 | 400 | ||
401 | #[test] | 401 | #[test] |
402 | fn test_keywords_after_unsafe_in_item_list() { | 402 | fn test_keywords_after_unsafe_in_item_list() { |
403 | assert_snapshot!( | 403 | check( |
404 | get_keyword_completions(r"unsafe <|>"), | 404 | r"unsafe <|>", |
405 | @r###" | 405 | expect![[r#" |
406 | kw fn | 406 | kw fn |
407 | kw impl | 407 | kw impl |
408 | kw trait | 408 | kw trait |
409 | "### | 409 | "#]], |
410 | ); | 410 | ); |
411 | } | 411 | } |
412 | 412 | ||
413 | #[test] | 413 | #[test] |
414 | fn test_keywords_after_unsafe_in_block_expr() { | 414 | fn test_keywords_after_unsafe_in_block_expr() { |
415 | assert_snapshot!( | 415 | check( |
416 | get_keyword_completions(r"fn my_fn() { unsafe <|> }"), | 416 | r"fn my_fn() { unsafe <|> }", |
417 | @r###" | 417 | expect![[r#" |
418 | kw fn | 418 | kw fn |
419 | kw impl | 419 | kw impl |
420 | kw trait | 420 | kw trait |
421 | "### | 421 | "#]], |
422 | ); | 422 | ); |
423 | } | 423 | } |
424 | 424 | ||
425 | #[test] | 425 | #[test] |
426 | fn test_mut_in_ref_and_in_fn_parameters_list() { | 426 | fn test_mut_in_ref_and_in_fn_parameters_list() { |
427 | assert_snapshot!( | 427 | check( |
428 | get_keyword_completions(r"fn my_fn(&<|>) {}"), | 428 | r"fn my_fn(&<|>) {}", |
429 | @r###" | 429 | expect![[r#" |
430 | kw mut | 430 | kw mut |
431 | "### | 431 | "#]], |
432 | ); | 432 | ); |
433 | assert_snapshot!( | 433 | check( |
434 | get_keyword_completions(r"fn my_fn(<|>) {}"), | 434 | r"fn my_fn(<|>) {}", |
435 | @r###" | 435 | expect![[r#" |
436 | kw mut | 436 | kw mut |
437 | "### | 437 | "#]], |
438 | ); | 438 | ); |
439 | assert_snapshot!( | 439 | check( |
440 | get_keyword_completions(r"fn my_fn() { let &<|> }"), | 440 | r"fn my_fn() { let &<|> }", |
441 | @r###" | 441 | expect![[r#" |
442 | kw mut | 442 | kw mut |
443 | "### | 443 | "#]], |
444 | ); | 444 | ); |
445 | } | 445 | } |
446 | 446 | ||
447 | #[test] | 447 | #[test] |
448 | fn test_where_keyword() { | 448 | fn test_where_keyword() { |
449 | assert_snapshot!( | 449 | check( |
450 | get_keyword_completions(r"trait A <|>"), | 450 | r"trait A <|>", |
451 | @r###" | 451 | expect![[r#" |
452 | kw where | 452 | kw where |
453 | "### | 453 | "#]], |
454 | ); | 454 | ); |
455 | assert_snapshot!( | 455 | check( |
456 | get_keyword_completions(r"impl A <|>"), | 456 | r"impl A <|>", |
457 | @r###" | 457 | expect![[r#" |
458 | kw where | 458 | kw where |
459 | "### | 459 | "#]], |
460 | ); | 460 | ); |
461 | } | 461 | } |
462 | } | 462 | } |