@@ -271,7 +271,7 @@ fn rename_reference(
271271
272272#[ cfg( test) ]
273273mod tests {
274- use insta :: assert_debug_snapshot ;
274+ use expect :: { expect , Expect } ;
275275 use ra_text_edit:: TextEditBuilder ;
276276 use stdx:: trim_indent;
277277 use test_utils:: { assert_eq_text, mark} ;
@@ -297,6 +297,12 @@ mod tests {
297297 assert_eq_text ! ( ra_fixture_after, & * result) ;
298298 }
299299
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+
300306 #[ test]
301307 fn test_rename_to_underscore ( ) {
302308 check (
@@ -650,7 +656,8 @@ fn baz(j: i32) -> Self {
650656
651657 #[ test]
652658 fn test_rename_mod ( ) {
653- let ( analysis, position) = analysis_and_position (
659+ check_expect (
660+ "foo2" ,
654661 r#"
655662//- /lib.rs
656663mod bar;
@@ -659,53 +666,49 @@ mod bar;
659666mod foo<|>;
660667
661668//- /bar/foo.rs
662- // emtpy
663- "# ,
664- ) ;
665- let new_name = "foo2" ;
666- let source_change = analysis. rename ( position, new_name) . unwrap ( ) ;
667- assert_debug_snapshot ! ( & source_change,
668- @r###"
669- Some(
670- RangeInfo {
671- range: 4..7,
672- info: SourceChange {
673- source_file_edits: [
674- SourceFileEdit {
675- file_id: FileId(
676- 2,
677- ),
678- edit: TextEdit {
679- indels: [
680- Indel {
681- insert: "foo2",
682- delete: 4..7,
683- },
684- ],
669+ // empty
670+ "# ,
671+ expect ! [ [ r#"
672+ RangeInfo {
673+ range: 4..7,
674+ info: SourceChange {
675+ source_file_edits: [
676+ SourceFileEdit {
677+ file_id: FileId(
678+ 2,
679+ ),
680+ edit: TextEdit {
681+ indels: [
682+ Indel {
683+ insert: "foo2",
684+ delete: 4..7,
685+ },
686+ ],
687+ },
685688 },
686- },
687- ],
688- file_system_edits: [
689- MoveFile {
690- src: FileId(
691- 3,
692- ),
693- anchor: FileId(
694- 2,
695- ),
696- dst: "foo2.rs",
697- },
698- ],
699- is_snippet: false,
700- },
701- },
702- )
703- "### ) ;
689+ ],
690+ file_system_edits: [
691+ MoveFile {
692+ src: FileId(
693+ 3,
694+ ),
695+ anchor: FileId(
696+ 2,
697+ ),
698+ dst: "foo2.rs",
699+ },
700+ ],
701+ is_snippet: false,
702+ },
703+ }
704+ "# ] ] ,
705+ ) ;
704706 }
705707
706708 #[ test]
707709 fn test_rename_mod_in_use_tree ( ) {
708- let ( analysis, position) = analysis_and_position (
710+ check_expect (
711+ "quux" ,
709712 r#"
710713//- /main.rs
711714pub mod foo;
@@ -717,112 +720,23 @@ pub struct FooContent;
717720
718721//- /bar.rs
719722use crate::foo<|>::FooContent;
720- "# ,
723+ "# ,
724+ expect ! [ [ ] ] ,
721725 ) ;
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- "### ) ;
774726 }
775727
776728 #[ test]
777729 fn test_rename_mod_in_dir ( ) {
778- let ( analysis, position) = analysis_and_position (
730+ check_expect (
731+ "foo2" ,
779732 r#"
780733//- /lib.rs
781734mod fo<|>o;
782735//- /foo/mod.rs
783736// emtpy
784- "# ,
737+ "# ,
738+ expect ! [ [ ] ] ,
785739 ) ;
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- ) ;
826740 }
827741
828742 #[ test]
@@ -852,7 +766,8 @@ fn main() {
852766
853767 #[ test]
854768 fn test_rename_mod_filename_and_path ( ) {
855- let ( analysis, position) = analysis_and_position (
769+ check_expect (
770+ "foo2" ,
856771 r#"
857772//- /lib.rs
858773mod bar;
@@ -865,60 +780,9 @@ pub mod foo<|>;
865780
866781//- /bar/foo.rs
867782// pub fn fun() {}
868- "# ,
783+ "# ,
784+ expect ! [ [ ] ] ,
869785 ) ;
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- "### ) ;
922786 }
923787
924788 #[ test]
0 commit comments