aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-07-03 17:35:43 +0100
committerAleksey Kladov <[email protected]>2020-07-03 17:35:43 +0100
commit2656c415c893020331587d2771f10019e9165dce (patch)
tree5c31759dd331957f9b02319676680c2b8cc41a34 /crates
parentee7ab0104d7d46e4ffc9933a53c6597160a1533c (diff)
Use expect for rename tests
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide/src/references/rename.rs250
1 files changed, 57 insertions, 193 deletions
diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs
index f4b11cbd0..fbc10d3bb 100644
--- a/crates/ra_ide/src/references/rename.rs
+++ b/crates/ra_ide/src/references/rename.rs
@@ -271,7 +271,7 @@ fn rename_reference(
271 271
272#[cfg(test)] 272#[cfg(test)]
273mod tests { 273mod tests {
274 use insta::assert_debug_snapshot; 274 use expect::{expect, Expect};
275 use ra_text_edit::TextEditBuilder; 275 use ra_text_edit::TextEditBuilder;
276 use stdx::trim_indent; 276 use stdx::trim_indent;
277 use test_utils::{assert_eq_text, mark}; 277 use test_utils::{assert_eq_text, mark};
@@ -297,6 +297,12 @@ mod tests {
297 assert_eq_text!(ra_fixture_after, &*result); 297 assert_eq_text!(ra_fixture_after, &*result);
298 } 298 }
299 299
300 fn check_expect(new_name: &str, ra_fixture: &str, expect: Expect) {
301 let (analysis, position) = analysis_and_position(ra_fixture);
302 let source_change = analysis.rename(position, new_name).unwrap().unwrap();
303 expect.assert_debug_eq(&source_change)
304 }
305
300 #[test] 306 #[test]
301 fn test_rename_to_underscore() { 307 fn test_rename_to_underscore() {
302 check( 308 check(
@@ -650,7 +656,8 @@ fn baz(j: i32) -> Self {
650 656
651 #[test] 657 #[test]
652 fn test_rename_mod() { 658 fn test_rename_mod() {
653 let (analysis, position) = analysis_and_position( 659 check_expect(
660 "foo2",
654 r#" 661 r#"
655//- /lib.rs 662//- /lib.rs
656mod bar; 663mod bar;
@@ -659,53 +666,49 @@ mod bar;
659mod foo<|>; 666mod foo<|>;
660 667
661//- /bar/foo.rs 668//- /bar/foo.rs
662// emtpy 669// empty
663 "#, 670"#,
664 ); 671 expect![[r#"
665 let new_name = "foo2"; 672 RangeInfo {
666 let source_change = analysis.rename(position, new_name).unwrap(); 673 range: 4..7,
667 assert_debug_snapshot!(&source_change, 674 info: SourceChange {
668@r###" 675 source_file_edits: [
669 Some( 676 SourceFileEdit {
670 RangeInfo { 677 file_id: FileId(
671 range: 4..7, 678 2,
672 info: SourceChange { 679 ),
673 source_file_edits: [ 680 edit: TextEdit {
674 SourceFileEdit { 681 indels: [
675 file_id: FileId( 682 Indel {
676 2, 683 insert: "foo2",
677 ), 684 delete: 4..7,
678 edit: TextEdit { 685 },
679 indels: [ 686 ],
680 Indel { 687 },
681 insert: "foo2",
682 delete: 4..7,
683 },
684 ],
685 }, 688 },
686 }, 689 ],
687 ], 690 file_system_edits: [
688 file_system_edits: [ 691 MoveFile {
689 MoveFile { 692 src: FileId(
690 src: FileId( 693 3,
691 3, 694 ),
692 ), 695 anchor: FileId(
693 anchor: FileId( 696 2,
694 2, 697 ),
695 ), 698 dst: "foo2.rs",
696 dst: "foo2.rs", 699 },
697 }, 700 ],
698 ], 701 is_snippet: false,
699 is_snippet: false, 702 },
700 }, 703 }
701 }, 704 "#]],
702 ) 705 );
703 "###);
704 } 706 }
705 707
706 #[test] 708 #[test]
707 fn test_rename_mod_in_use_tree() { 709 fn test_rename_mod_in_use_tree() {
708 let (analysis, position) = analysis_and_position( 710 check_expect(
711 "quux",
709 r#" 712 r#"
710//- /main.rs 713//- /main.rs
711pub mod foo; 714pub mod foo;
@@ -717,112 +720,23 @@ pub struct FooContent;
717 720
718//- /bar.rs 721//- /bar.rs
719use crate::foo<|>::FooContent; 722use crate::foo<|>::FooContent;
720 "#, 723"#,
724 expect![[]],
721 ); 725 );
722 let new_name = "qux";
723 let source_change = analysis.rename(position, new_name).unwrap();
724 assert_debug_snapshot!(&source_change,
725@r###"
726 Some(
727 RangeInfo {
728 range: 11..14,
729 info: SourceChange {
730 source_file_edits: [
731 SourceFileEdit {
732 file_id: FileId(
733 1,
734 ),
735 edit: TextEdit {
736 indels: [
737 Indel {
738 insert: "qux",
739 delete: 8..11,
740 },
741 ],
742 },
743 },
744 SourceFileEdit {
745 file_id: FileId(
746 3,
747 ),
748 edit: TextEdit {
749 indels: [
750 Indel {
751 insert: "qux",
752 delete: 11..14,
753 },
754 ],
755 },
756 },
757 ],
758 file_system_edits: [
759 MoveFile {
760 src: FileId(
761 2,
762 ),
763 anchor: FileId(
764 3,
765 ),
766 dst: "qux.rs",
767 },
768 ],
769 is_snippet: false,
770 },
771 },
772 )
773 "###);
774 } 726 }
775 727
776 #[test] 728 #[test]
777 fn test_rename_mod_in_dir() { 729 fn test_rename_mod_in_dir() {
778 let (analysis, position) = analysis_and_position( 730 check_expect(
731 "foo2",
779 r#" 732 r#"
780//- /lib.rs 733//- /lib.rs
781mod fo<|>o; 734mod fo<|>o;
782//- /foo/mod.rs 735//- /foo/mod.rs
783// emtpy 736// emtpy
784 "#, 737"#,
738 expect![[]],
785 ); 739 );
786 let new_name = "foo2";
787 let source_change = analysis.rename(position, new_name).unwrap();
788 assert_debug_snapshot!(&source_change,
789 @r###"
790 Some(
791 RangeInfo {
792 range: 4..7,
793 info: SourceChange {
794 source_file_edits: [
795 SourceFileEdit {
796 file_id: FileId(
797 1,
798 ),
799 edit: TextEdit {
800 indels: [
801 Indel {
802 insert: "foo2",
803 delete: 4..7,
804 },
805 ],
806 },
807 },
808 ],
809 file_system_edits: [
810 MoveFile {
811 src: FileId(
812 2,
813 ),
814 anchor: FileId(
815 1,
816 ),
817 dst: "../foo2/mod.rs",
818 },
819 ],
820 is_snippet: false,
821 },
822 },
823 )
824 "###
825 );
826 } 740 }
827 741
828 #[test] 742 #[test]
@@ -852,7 +766,8 @@ fn main() {
852 766
853 #[test] 767 #[test]
854 fn test_rename_mod_filename_and_path() { 768 fn test_rename_mod_filename_and_path() {
855 let (analysis, position) = analysis_and_position( 769 check_expect(
770 "foo2",
856 r#" 771 r#"
857//- /lib.rs 772//- /lib.rs
858mod bar; 773mod bar;
@@ -865,60 +780,9 @@ pub mod foo<|>;
865 780
866//- /bar/foo.rs 781//- /bar/foo.rs
867// pub fn fun() {} 782// pub fn fun() {}
868 "#, 783"#,
784 expect![[]],
869 ); 785 );
870 let new_name = "foo2";
871 let source_change = analysis.rename(position, new_name).unwrap();
872 assert_debug_snapshot!(&source_change,
873@r###"
874 Some(
875 RangeInfo {
876 range: 8..11,
877 info: SourceChange {
878 source_file_edits: [
879 SourceFileEdit {
880 file_id: FileId(
881 2,
882 ),
883 edit: TextEdit {
884 indels: [
885 Indel {
886 insert: "foo2",
887 delete: 8..11,
888 },
889 ],
890 },
891 },
892 SourceFileEdit {
893 file_id: FileId(
894 1,
895 ),
896 edit: TextEdit {
897 indels: [
898 Indel {
899 insert: "foo2",
900 delete: 27..30,
901 },
902 ],
903 },
904 },
905 ],
906 file_system_edits: [
907 MoveFile {
908 src: FileId(
909 3,
910 ),
911 anchor: FileId(
912 2,
913 ),
914 dst: "foo2.rs",
915 },
916 ],
917 is_snippet: false,
918 },
919 },
920 )
921 "###);
922 } 786 }
923 787
924 #[test] 788 #[test]