diff options
Diffstat (limited to 'crates/ra_hir_ty/src')
-rw-r--r-- | crates/ra_hir_ty/src/expr.rs | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/crates/ra_hir_ty/src/expr.rs b/crates/ra_hir_ty/src/expr.rs index 53828d29d..e9f785383 100644 --- a/crates/ra_hir_ty/src/expr.rs +++ b/crates/ra_hir_ty/src/expr.rs | |||
@@ -386,3 +386,132 @@ pub fn record_pattern_missing_fields( | |||
386 | } | 386 | } |
387 | Some((variant_def, missed_fields, exhaustive)) | 387 | Some((variant_def, missed_fields, exhaustive)) |
388 | } | 388 | } |
389 | |||
390 | #[cfg(test)] | ||
391 | mod tests { | ||
392 | use insta::assert_snapshot; | ||
393 | use ra_db::fixture::WithFixture; | ||
394 | |||
395 | use crate::{diagnostics::MismatchedArgCount, test_db::TestDB}; | ||
396 | |||
397 | fn check_diagnostic_message(ra_fixture: &str) -> String { | ||
398 | TestDB::with_single_file(ra_fixture).0.diagnostic::<MismatchedArgCount>().0 | ||
399 | } | ||
400 | |||
401 | fn check_no_diagnostic(ra_fixture: &str) { | ||
402 | let (s, diagnostic_count) = | ||
403 | TestDB::with_single_file(ra_fixture).0.diagnostic::<MismatchedArgCount>(); | ||
404 | |||
405 | assert_eq!(0, diagnostic_count, "expected no diagnostic, found one: {}", s); | ||
406 | } | ||
407 | |||
408 | #[test] | ||
409 | fn simple_free_fn_zero() { | ||
410 | assert_snapshot!(check_diagnostic_message( | ||
411 | r" | ||
412 | fn zero() {} | ||
413 | |||
414 | fn f() { | ||
415 | zero(1); | ||
416 | } | ||
417 | " | ||
418 | ), | ||
419 | @"\"zero(1)\": Expected 0 arguments, found 1\n"); | ||
420 | |||
421 | check_no_diagnostic( | ||
422 | r" | ||
423 | fn zero() {} | ||
424 | |||
425 | fn f() { | ||
426 | zero(); | ||
427 | } | ||
428 | ", | ||
429 | ); | ||
430 | } | ||
431 | |||
432 | #[test] | ||
433 | fn simple_free_fn_one() { | ||
434 | assert_snapshot!(check_diagnostic_message( | ||
435 | r" | ||
436 | fn one(arg: u8) {} | ||
437 | |||
438 | fn f() { | ||
439 | one(); | ||
440 | } | ||
441 | " | ||
442 | ), | ||
443 | @"\"one()\": Expected 1 argument, found 0\n"); | ||
444 | |||
445 | check_no_diagnostic( | ||
446 | r" | ||
447 | fn one(arg: u8) {} | ||
448 | |||
449 | fn f() { | ||
450 | one(1); | ||
451 | } | ||
452 | ", | ||
453 | ); | ||
454 | } | ||
455 | |||
456 | #[test] | ||
457 | fn method_as_fn() { | ||
458 | assert_snapshot!(check_diagnostic_message( | ||
459 | r" | ||
460 | struct S; | ||
461 | impl S { | ||
462 | fn method(&self) {} | ||
463 | } | ||
464 | |||
465 | fn f() { | ||
466 | S::method(); | ||
467 | } | ||
468 | " | ||
469 | ), | ||
470 | @"\"S::method()\": Expected 1 argument, found 0\n"); | ||
471 | |||
472 | check_no_diagnostic( | ||
473 | r" | ||
474 | struct S; | ||
475 | impl S { | ||
476 | fn method(&self) {} | ||
477 | } | ||
478 | |||
479 | fn f() { | ||
480 | S::method(&S); | ||
481 | S.method(); | ||
482 | } | ||
483 | ", | ||
484 | ); | ||
485 | } | ||
486 | |||
487 | #[test] | ||
488 | fn method_with_arg() { | ||
489 | assert_snapshot!(check_diagnostic_message( | ||
490 | r" | ||
491 | struct S; | ||
492 | impl S { | ||
493 | fn method(&self, arg: u8) {} | ||
494 | } | ||
495 | |||
496 | fn f() { | ||
497 | S.method(); | ||
498 | } | ||
499 | " | ||
500 | ), | ||
501 | @"\"S.method()\": Expected 1 argument, found 0\n"); | ||
502 | |||
503 | check_no_diagnostic( | ||
504 | r" | ||
505 | struct S; | ||
506 | impl S { | ||
507 | fn method(&self, arg: u8) {} | ||
508 | } | ||
509 | |||
510 | fn f() { | ||
511 | S::method(&S, 0); | ||
512 | S.method(1); | ||
513 | } | ||
514 | ", | ||
515 | ); | ||
516 | } | ||
517 | } | ||