diff options
author | Aleksey Kladov <[email protected]> | 2020-06-29 16:22:47 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-06-29 16:23:01 +0100 |
commit | bbc4dc995612916a4c0a99396b5259a5fb1dda80 (patch) | |
tree | fac101a18e111a2a05bce14fbb68981c5bef3bfd /crates/ra_hir_ty/src/tests/macros.rs | |
parent | e805e8c1d5bf26e9716fb855f97d950395129c20 (diff) |
Update the rest of the tests
Diffstat (limited to 'crates/ra_hir_ty/src/tests/macros.rs')
-rw-r--r-- | crates/ra_hir_ty/src/tests/macros.rs | 116 |
1 files changed, 49 insertions, 67 deletions
diff --git a/crates/ra_hir_ty/src/tests/macros.rs b/crates/ra_hir_ty/src/tests/macros.rs index be2b48dcc..45c4e309e 100644 --- a/crates/ra_hir_ty/src/tests/macros.rs +++ b/crates/ra_hir_ty/src/tests/macros.rs | |||
@@ -1,16 +1,13 @@ | |||
1 | use std::fs; | 1 | use std::fs; |
2 | 2 | ||
3 | use insta::assert_snapshot; | 3 | use insta::assert_snapshot; |
4 | use ra_db::fixture::WithFixture; | ||
5 | use test_utils::project_dir; | 4 | use test_utils::project_dir; |
6 | 5 | ||
7 | use crate::test_db::TestDB; | 6 | use super::{check_types, infer}; |
8 | |||
9 | use super::{infer, type_at, type_at_pos}; | ||
10 | 7 | ||
11 | #[test] | 8 | #[test] |
12 | fn cfg_impl_def() { | 9 | fn cfg_impl_def() { |
13 | let (db, pos) = TestDB::with_position( | 10 | check_types( |
14 | r#" | 11 | r#" |
15 | //- /main.rs crate:main deps:foo cfg:test | 12 | //- /main.rs crate:main deps:foo cfg:test |
16 | use foo::S as T; | 13 | use foo::S as T; |
@@ -28,8 +25,8 @@ impl S { | |||
28 | 25 | ||
29 | fn test() { | 26 | fn test() { |
30 | let t = (S.foo1(), S.foo2(), T.foo3(), T.foo4()); | 27 | let t = (S.foo1(), S.foo2(), T.foo3(), T.foo4()); |
31 | t<|>; | 28 | t; |
32 | } | 29 | } //^ (i32, {unknown}, i32, {unknown}) |
33 | 30 | ||
34 | //- /foo.rs crate:foo | 31 | //- /foo.rs crate:foo |
35 | struct S; | 32 | struct S; |
@@ -45,7 +42,6 @@ impl S { | |||
45 | } | 42 | } |
46 | "#, | 43 | "#, |
47 | ); | 44 | ); |
48 | assert_eq!("(i32, {unknown}, i32, {unknown})", type_at_pos(&db, pos)); | ||
49 | } | 45 | } |
50 | 46 | ||
51 | #[test] | 47 | #[test] |
@@ -253,26 +249,24 @@ fn foo() { | |||
253 | 249 | ||
254 | #[test] | 250 | #[test] |
255 | fn processes_impls_generated_by_macros() { | 251 | fn processes_impls_generated_by_macros() { |
256 | let t = type_at( | 252 | check_types( |
257 | r#" | 253 | r#" |
258 | //- /main.rs | ||
259 | macro_rules! m { | 254 | macro_rules! m { |
260 | ($ident:ident) => (impl Trait for $ident {}) | 255 | ($ident:ident) => (impl Trait for $ident {}) |
261 | } | 256 | } |
262 | trait Trait { fn foo(self) -> u128 {} } | 257 | trait Trait { fn foo(self) -> u128 {} } |
263 | struct S; | 258 | struct S; |
264 | m!(S); | 259 | m!(S); |
265 | fn test() { S.foo()<|>; } | 260 | fn test() { S.foo(); } |
261 | //^ u128 | ||
266 | "#, | 262 | "#, |
267 | ); | 263 | ); |
268 | assert_eq!(t, "u128"); | ||
269 | } | 264 | } |
270 | 265 | ||
271 | #[test] | 266 | #[test] |
272 | fn infer_assoc_items_generated_by_macros() { | 267 | fn infer_assoc_items_generated_by_macros() { |
273 | let t = type_at( | 268 | check_types( |
274 | r#" | 269 | r#" |
275 | //- /main.rs | ||
276 | macro_rules! m { | 270 | macro_rules! m { |
277 | () => (fn foo(&self) -> u128 {0}) | 271 | () => (fn foo(&self) -> u128 {0}) |
278 | } | 272 | } |
@@ -281,17 +275,16 @@ impl S { | |||
281 | m!(); | 275 | m!(); |
282 | } | 276 | } |
283 | 277 | ||
284 | fn test() { S.foo()<|>; } | 278 | fn test() { S.foo(); } |
279 | //^ u128 | ||
285 | "#, | 280 | "#, |
286 | ); | 281 | ); |
287 | assert_eq!(t, "u128"); | ||
288 | } | 282 | } |
289 | 283 | ||
290 | #[test] | 284 | #[test] |
291 | fn infer_assoc_items_generated_by_macros_chain() { | 285 | fn infer_assoc_items_generated_by_macros_chain() { |
292 | let t = type_at( | 286 | check_types( |
293 | r#" | 287 | r#" |
294 | //- /main.rs | ||
295 | macro_rules! m_inner { | 288 | macro_rules! m_inner { |
296 | () => {fn foo(&self) -> u128 {0}} | 289 | () => {fn foo(&self) -> u128 {0}} |
297 | } | 290 | } |
@@ -304,21 +297,21 @@ impl S { | |||
304 | m!(); | 297 | m!(); |
305 | } | 298 | } |
306 | 299 | ||
307 | fn test() { S.foo()<|>; } | 300 | fn test() { S.foo(); } |
301 | //^ u128 | ||
308 | "#, | 302 | "#, |
309 | ); | 303 | ); |
310 | assert_eq!(t, "u128"); | ||
311 | } | 304 | } |
312 | 305 | ||
313 | #[test] | 306 | #[test] |
314 | fn infer_macro_with_dollar_crate_is_correct_in_expr() { | 307 | fn infer_macro_with_dollar_crate_is_correct_in_expr() { |
315 | let (db, pos) = TestDB::with_position( | 308 | check_types( |
316 | r#" | 309 | r#" |
317 | //- /main.rs crate:main deps:foo | 310 | //- /main.rs crate:main deps:foo |
318 | fn test() { | 311 | fn test() { |
319 | let x = (foo::foo!(1), foo::foo!(2)); | 312 | let x = (foo::foo!(1), foo::foo!(2)); |
320 | x<|>; | 313 | x; |
321 | } | 314 | } //^ (i32, usize) |
322 | 315 | ||
323 | //- /lib.rs crate:foo | 316 | //- /lib.rs crate:foo |
324 | #[macro_export] | 317 | #[macro_export] |
@@ -335,12 +328,11 @@ macro_rules! bar { | |||
335 | pub fn baz() -> usize { 31usize } | 328 | pub fn baz() -> usize { 31usize } |
336 | "#, | 329 | "#, |
337 | ); | 330 | ); |
338 | assert_eq!("(i32, usize)", type_at_pos(&db, pos)); | ||
339 | } | 331 | } |
340 | 332 | ||
341 | #[test] | 333 | #[test] |
342 | fn infer_macro_with_dollar_crate_is_correct_in_trait_associate_type() { | 334 | fn infer_macro_with_dollar_crate_is_correct_in_trait_associate_type() { |
343 | let (db, pos) = TestDB::with_position( | 335 | check_types( |
344 | r#" | 336 | r#" |
345 | //- /main.rs crate:main deps:foo | 337 | //- /main.rs crate:main deps:foo |
346 | use foo::Trait; | 338 | use foo::Trait; |
@@ -348,7 +340,8 @@ use foo::Trait; | |||
348 | fn test() { | 340 | fn test() { |
349 | let msg = foo::Message(foo::MessageRef); | 341 | let msg = foo::Message(foo::MessageRef); |
350 | let r = msg.deref(); | 342 | let r = msg.deref(); |
351 | r<|>; | 343 | r; |
344 | //^ &MessageRef | ||
352 | } | 345 | } |
353 | 346 | ||
354 | //- /lib.rs crate:foo | 347 | //- /lib.rs crate:foo |
@@ -375,7 +368,6 @@ macro_rules! expand { | |||
375 | expand!(); | 368 | expand!(); |
376 | "#, | 369 | "#, |
377 | ); | 370 | ); |
378 | assert_eq!("&MessageRef", type_at_pos(&db, pos)); | ||
379 | } | 371 | } |
380 | 372 | ||
381 | #[test] | 373 | #[test] |
@@ -429,13 +421,13 @@ fn main() { | |||
429 | 421 | ||
430 | #[test] | 422 | #[test] |
431 | fn infer_local_inner_macros() { | 423 | fn infer_local_inner_macros() { |
432 | let (db, pos) = TestDB::with_position( | 424 | check_types( |
433 | r#" | 425 | r#" |
434 | //- /main.rs crate:main deps:foo | 426 | //- /main.rs crate:main deps:foo |
435 | fn test() { | 427 | fn test() { |
436 | let x = foo::foo!(1); | 428 | let x = foo::foo!(1); |
437 | x<|>; | 429 | x; |
438 | } | 430 | } //^ i32 |
439 | 431 | ||
440 | //- /lib.rs crate:foo | 432 | //- /lib.rs crate:foo |
441 | #[macro_export(local_inner_macros)] | 433 | #[macro_export(local_inner_macros)] |
@@ -450,7 +442,6 @@ macro_rules! bar { | |||
450 | 442 | ||
451 | "#, | 443 | "#, |
452 | ); | 444 | ); |
453 | assert_eq!("i32", type_at_pos(&db, pos)); | ||
454 | } | 445 | } |
455 | 446 | ||
456 | #[test] | 447 | #[test] |
@@ -531,7 +522,7 @@ fn main() { | |||
531 | 522 | ||
532 | #[test] | 523 | #[test] |
533 | fn infer_builtin_macros_include() { | 524 | fn infer_builtin_macros_include() { |
534 | let (db, pos) = TestDB::with_position( | 525 | check_types( |
535 | r#" | 526 | r#" |
536 | //- /main.rs | 527 | //- /main.rs |
537 | #[rustc_builtin_macro] | 528 | #[rustc_builtin_macro] |
@@ -540,14 +531,13 @@ macro_rules! include {() => {}} | |||
540 | include!("foo.rs"); | 531 | include!("foo.rs"); |
541 | 532 | ||
542 | fn main() { | 533 | fn main() { |
543 | bar()<|>; | 534 | bar(); |
544 | } | 535 | } //^ u32 |
545 | 536 | ||
546 | //- /foo.rs | 537 | //- /foo.rs |
547 | fn bar() -> u32 {0} | 538 | fn bar() -> u32 {0} |
548 | "#, | 539 | "#, |
549 | ); | 540 | ); |
550 | assert_eq!("u32", type_at_pos(&db, pos)); | ||
551 | } | 541 | } |
552 | 542 | ||
553 | #[test] | 543 | #[test] |
@@ -565,18 +555,17 @@ macro_rules! include {() => {}} | |||
565 | include!("foo.rs"); | 555 | include!("foo.rs"); |
566 | 556 | ||
567 | fn main() { | 557 | fn main() { |
568 | RegisterBlock { }<|>; | 558 | RegisterBlock { }; |
559 | //^ RegisterBlock | ||
569 | } | 560 | } |
570 | "#; | 561 | "#; |
571 | let fixture = format!("{}\n//- /foo.rs\n{}", fixture, big_file); | 562 | let fixture = format!("{}\n//- /foo.rs\n{}", fixture, big_file); |
572 | 563 | check_types(&fixture); | |
573 | let (db, pos) = TestDB::with_position(&fixture); | ||
574 | assert_eq!("RegisterBlock", type_at_pos(&db, pos)); | ||
575 | } | 564 | } |
576 | 565 | ||
577 | #[test] | 566 | #[test] |
578 | fn infer_builtin_macros_include_concat() { | 567 | fn infer_builtin_macros_include_concat() { |
579 | let (db, pos) = TestDB::with_position( | 568 | check_types( |
580 | r#" | 569 | r#" |
581 | //- /main.rs | 570 | //- /main.rs |
582 | #[rustc_builtin_macro] | 571 | #[rustc_builtin_macro] |
@@ -588,19 +577,18 @@ macro_rules! concat {() => {}} | |||
588 | include!(concat!("f", "oo.rs")); | 577 | include!(concat!("f", "oo.rs")); |
589 | 578 | ||
590 | fn main() { | 579 | fn main() { |
591 | bar()<|>; | 580 | bar(); |
592 | } | 581 | } //^ u32 |
593 | 582 | ||
594 | //- /foo.rs | 583 | //- /foo.rs |
595 | fn bar() -> u32 {0} | 584 | fn bar() -> u32 {0} |
596 | "#, | 585 | "#, |
597 | ); | 586 | ); |
598 | assert_eq!("u32", type_at_pos(&db, pos)); | ||
599 | } | 587 | } |
600 | 588 | ||
601 | #[test] | 589 | #[test] |
602 | fn infer_builtin_macros_include_concat_with_bad_env_should_failed() { | 590 | fn infer_builtin_macros_include_concat_with_bad_env_should_failed() { |
603 | let (db, pos) = TestDB::with_position( | 591 | check_types( |
604 | r#" | 592 | r#" |
605 | //- /main.rs | 593 | //- /main.rs |
606 | #[rustc_builtin_macro] | 594 | #[rustc_builtin_macro] |
@@ -615,32 +603,29 @@ macro_rules! env {() => {}} | |||
615 | include!(concat!(env!("OUT_DIR"), "/foo.rs")); | 603 | include!(concat!(env!("OUT_DIR"), "/foo.rs")); |
616 | 604 | ||
617 | fn main() { | 605 | fn main() { |
618 | bar()<|>; | 606 | bar(); |
619 | } | 607 | } //^ {unknown} |
620 | 608 | ||
621 | //- /foo.rs | 609 | //- /foo.rs |
622 | fn bar() -> u32 {0} | 610 | fn bar() -> u32 {0} |
623 | "#, | 611 | "#, |
624 | ); | 612 | ); |
625 | assert_eq!("{unknown}", type_at_pos(&db, pos)); | ||
626 | } | 613 | } |
627 | 614 | ||
628 | #[test] | 615 | #[test] |
629 | fn infer_builtin_macros_include_itself_should_failed() { | 616 | fn infer_builtin_macros_include_itself_should_failed() { |
630 | let (db, pos) = TestDB::with_position( | 617 | check_types( |
631 | r#" | 618 | r#" |
632 | //- /main.rs | ||
633 | #[rustc_builtin_macro] | 619 | #[rustc_builtin_macro] |
634 | macro_rules! include {() => {}} | 620 | macro_rules! include {() => {}} |
635 | 621 | ||
636 | include!("main.rs"); | 622 | include!("main.rs"); |
637 | 623 | ||
638 | fn main() { | 624 | fn main() { |
639 | 0<|> | 625 | 0 |
640 | } | 626 | } //^ i32 |
641 | "#, | 627 | "#, |
642 | ); | 628 | ); |
643 | assert_eq!("i32", type_at_pos(&db, pos)); | ||
644 | } | 629 | } |
645 | 630 | ||
646 | #[test] | 631 | #[test] |
@@ -686,14 +671,14 @@ fn main() { | |||
686 | 671 | ||
687 | #[test] | 672 | #[test] |
688 | fn infer_derive_clone_simple() { | 673 | fn infer_derive_clone_simple() { |
689 | let (db, pos) = TestDB::with_position( | 674 | check_types( |
690 | r#" | 675 | r#" |
691 | //- /main.rs crate:main deps:core | 676 | //- /main.rs crate:main deps:core |
692 | #[derive(Clone)] | 677 | #[derive(Clone)] |
693 | struct S; | 678 | struct S; |
694 | fn test() { | 679 | fn test() { |
695 | S.clone()<|>; | 680 | S.clone(); |
696 | } | 681 | } //^ S |
697 | 682 | ||
698 | //- /lib.rs crate:core | 683 | //- /lib.rs crate:core |
699 | #[prelude_import] | 684 | #[prelude_import] |
@@ -705,12 +690,11 @@ mod clone { | |||
705 | } | 690 | } |
706 | "#, | 691 | "#, |
707 | ); | 692 | ); |
708 | assert_eq!("S", type_at_pos(&db, pos)); | ||
709 | } | 693 | } |
710 | 694 | ||
711 | #[test] | 695 | #[test] |
712 | fn infer_derive_clone_in_core() { | 696 | fn infer_derive_clone_in_core() { |
713 | let (db, pos) = TestDB::with_position( | 697 | check_types( |
714 | r#" | 698 | r#" |
715 | //- /lib.rs crate:core | 699 | //- /lib.rs crate:core |
716 | #[prelude_import] | 700 | #[prelude_import] |
@@ -726,16 +710,15 @@ pub struct S; | |||
726 | //- /main.rs crate:main deps:core | 710 | //- /main.rs crate:main deps:core |
727 | use core::S; | 711 | use core::S; |
728 | fn test() { | 712 | fn test() { |
729 | S.clone()<|>; | 713 | S.clone(); |
730 | } | 714 | } //^ S |
731 | "#, | 715 | "#, |
732 | ); | 716 | ); |
733 | assert_eq!("S", type_at_pos(&db, pos)); | ||
734 | } | 717 | } |
735 | 718 | ||
736 | #[test] | 719 | #[test] |
737 | fn infer_derive_clone_with_params() { | 720 | fn infer_derive_clone_with_params() { |
738 | let (db, pos) = TestDB::with_position( | 721 | check_types( |
739 | r#" | 722 | r#" |
740 | //- /main.rs crate:main deps:core | 723 | //- /main.rs crate:main deps:core |
741 | #[derive(Clone)] | 724 | #[derive(Clone)] |
@@ -744,7 +727,8 @@ struct S; | |||
744 | struct Wrapper<T>(T); | 727 | struct Wrapper<T>(T); |
745 | struct NonClone; | 728 | struct NonClone; |
746 | fn test() { | 729 | fn test() { |
747 | (Wrapper(S).clone(), Wrapper(NonClone).clone())<|>; | 730 | (Wrapper(S).clone(), Wrapper(NonClone).clone()); |
731 | //^ (Wrapper<S>, {unknown}) | ||
748 | } | 732 | } |
749 | 733 | ||
750 | //- /lib.rs crate:core | 734 | //- /lib.rs crate:core |
@@ -757,13 +741,12 @@ mod clone { | |||
757 | } | 741 | } |
758 | "#, | 742 | "#, |
759 | ); | 743 | ); |
760 | assert_eq!("(Wrapper<S>, {unknown})", type_at_pos(&db, pos)); | ||
761 | } | 744 | } |
762 | 745 | ||
763 | #[test] | 746 | #[test] |
764 | fn infer_custom_derive_simple() { | 747 | fn infer_custom_derive_simple() { |
765 | // FIXME: this test current now do nothing | 748 | // FIXME: this test current now do nothing |
766 | let (db, pos) = TestDB::with_position( | 749 | check_types( |
767 | r#" | 750 | r#" |
768 | //- /main.rs crate:main | 751 | //- /main.rs crate:main |
769 | use foo::Foo; | 752 | use foo::Foo; |
@@ -772,11 +755,10 @@ use foo::Foo; | |||
772 | struct S{} | 755 | struct S{} |
773 | 756 | ||
774 | fn test() { | 757 | fn test() { |
775 | S{}<|>; | 758 | S{}; |
776 | } | 759 | } //^ S |
777 | "#, | 760 | "#, |
778 | ); | 761 | ); |
779 | assert_eq!("S", type_at_pos(&db, pos)); | ||
780 | } | 762 | } |
781 | 763 | ||
782 | #[test] | 764 | #[test] |