@@ -781,3 +781,246 @@ def test_Subcommands_RefactorRename_Module( self, app ):
781
781
} )
782
782
)
783
783
} ) )
784
+
785
+
786
+ @SharedYcmd
787
+ def test_Subcommands_RefactorInline ( self , app ):
788
+ one = PathToTestFile ( 'rename' , 'one.py' )
789
+ contents = ReadFile ( one )
790
+
791
+ command_data = BuildRequest ( filepath = one ,
792
+ filetype = 'python' ,
793
+ line_num = 8 ,
794
+ column_num = 10 ,
795
+ contents = contents ,
796
+ command_arguments = [ 'RefactorInline' ] )
797
+
798
+ response = app .post_json ( '/run_completer_command' ,
799
+ command_data ).json
800
+
801
+ assert_that ( response , has_entries ( {
802
+ 'fixits' : contains_exactly (
803
+ has_entries ( {
804
+ 'text' : '' ,
805
+ 'chunks' : contains_exactly (
806
+ ChunkMatcher ( '' ,
807
+ LocationMatcher ( one , 8 , 10 ),
808
+ LocationMatcher ( one , 9 , 10 ) ),
809
+ ChunkMatcher ( '' ,
810
+ LocationMatcher ( one , 9 , 61 ),
811
+ LocationMatcher ( one , 9 , 66 ) ),
812
+ ChunkMatcher ( ' + MODULE' ,
813
+ LocationMatcher ( one , 9 , 74 ),
814
+ LocationMatcher ( one , 9 , 74 ) ),
815
+ ChunkMatcher ( 'SCOPE' ,
816
+ LocationMatcher ( one , 9 , 75 ),
817
+ LocationMatcher ( one , 9 , 75 ) )
818
+ )
819
+ } )
820
+ )
821
+ } ) )
822
+
823
+
824
+ @SharedYcmd
825
+ def test_Subcommands_RefactorExtractVariable_NoNewName ( self , app ):
826
+ filepath = PathToTestFile ( 'basic.py' )
827
+ contents = ReadFile ( filepath )
828
+ command_data = BuildRequest ( filepath = filepath ,
829
+ filetype = 'python' ,
830
+ line_num = 3 ,
831
+ column_num = 10 ,
832
+ contents = contents ,
833
+ command_arguments = [
834
+ 'RefactorExtractVariable'
835
+ ] )
836
+
837
+ response = app .post_json ( '/run_completer_command' ,
838
+ command_data ,
839
+ expect_errors = True )
840
+
841
+ assert_that ( response .status_code ,
842
+ equal_to ( requests .codes .internal_server_error ) )
843
+ assert_that ( response .json ,
844
+ ErrorMatcher ( RuntimeError , 'Must specify a new name' ) )
845
+
846
+
847
+ @SharedYcmd
848
+ def test_Subcommands_RefactorExtractVariable_Same ( self , app ):
849
+ filepath = PathToTestFile ( 'basic.py' )
850
+ contents = ReadFile ( filepath )
851
+
852
+ command_data = BuildRequest ( filepath = filepath ,
853
+ filetype = 'python' ,
854
+ line_num = 3 ,
855
+ column_num = 14 ,
856
+ contents = contents ,
857
+ command_arguments = [
858
+ 'RefactorExtractVariable' ,
859
+ 'c'
860
+ ] )
861
+
862
+ response = app .post_json ( '/run_completer_command' ,
863
+ command_data ).json
864
+
865
+ assert_that ( response , has_entries ( {
866
+ 'fixits' : contains_exactly (
867
+ has_entries ( {
868
+ 'text' : '' ,
869
+ 'chunks' : contains_exactly (
870
+ ChunkMatcher ( 'c = 1\n ' ,
871
+ LocationMatcher ( filepath , 3 , 5 ),
872
+ LocationMatcher ( filepath , 3 , 5 ) ),
873
+ ChunkMatcher ( 'c' ,
874
+ LocationMatcher ( filepath , 3 , 14 ),
875
+ LocationMatcher ( filepath , 3 , 15 ) )
876
+ )
877
+ } )
878
+ )
879
+ } ) )
880
+
881
+
882
+ @SharedYcmd
883
+ def test_Subcommands_RefactorExtractVariable_Until ( self , app ):
884
+ filepath = PathToTestFile ( 'signature_help.py' )
885
+ contents = ReadFile ( filepath )
886
+
887
+ command_data = BuildRequest ( filepath = filepath ,
888
+ filetype = 'python' ,
889
+ line_num = 14 ,
890
+ column_num = 24 ,
891
+ range = {
892
+ 'end' : {
893
+ 'line_num' : 14 ,
894
+ 'column_num' : 36
895
+ }
896
+ },
897
+ contents = contents ,
898
+ command_arguments = [
899
+ 'RefactorExtractVariable' ,
900
+ 'c'
901
+ ] )
902
+
903
+ response = app .post_json ( '/run_completer_command' ,
904
+ command_data ).json
905
+
906
+ assert_that ( response , has_entries ( {
907
+ 'fixits' : contains_exactly (
908
+ has_entries ( {
909
+ 'text' : '' ,
910
+ 'chunks' : contains_exactly (
911
+ ChunkMatcher ( "c = 'test'.center\n " ,
912
+ LocationMatcher ( filepath , 14 , 5 ),
913
+ LocationMatcher ( filepath , 14 , 5 ) ),
914
+ ChunkMatcher ( '' ,
915
+ LocationMatcher ( filepath , 14 , 24 ),
916
+ LocationMatcher ( filepath , 14 , 31 ) ),
917
+ ChunkMatcher ( '' ,
918
+ LocationMatcher ( filepath , 14 , 32 ),
919
+ LocationMatcher ( filepath , 14 , 37 ) ),
920
+ )
921
+ } )
922
+ )
923
+ } ) )
924
+ @SharedYcmd
925
+ def test_Subcommands_RefactorExtractFunction_NoNewName ( self , app ):
926
+ filepath = PathToTestFile ( 'basic.py' )
927
+ contents = ReadFile ( filepath )
928
+ command_data = BuildRequest ( filepath = filepath ,
929
+ filetype = 'python' ,
930
+ line_num = 3 ,
931
+ column_num = 10 ,
932
+ contents = contents ,
933
+ command_arguments = [
934
+ 'RefactorExtractFunction' ,
935
+ ] )
936
+
937
+ response = app .post_json ( '/run_completer_command' ,
938
+ command_data ,
939
+ expect_errors = True )
940
+
941
+ assert_that ( response .status_code ,
942
+ equal_to ( requests .codes .internal_server_error ) )
943
+ assert_that ( response .json ,
944
+ ErrorMatcher ( RuntimeError , 'Must specify a new name' ) )
945
+
946
+
947
+ @SharedYcmd
948
+ def test_Subcommands_RefactorExtractFunction_Same ( self , app ):
949
+ filepath = PathToTestFile ( 'basic.py' )
950
+ contents = ReadFile ( filepath )
951
+
952
+ command_data = BuildRequest ( filepath = filepath ,
953
+ filetype = 'python' ,
954
+ line_num = 3 ,
955
+ column_num = 14 ,
956
+ contents = contents ,
957
+ command_arguments = [
958
+ 'RefactorExtractFunction' ,
959
+ 'c'
960
+ ] )
961
+
962
+ response = app .post_json ( '/run_completer_command' ,
963
+ command_data ).json
964
+
965
+ assert_that ( response , has_entries ( {
966
+ 'fixits' : contains_exactly (
967
+ has_entries ( {
968
+ 'text' : '' ,
969
+ 'chunks' : contains_exactly (
970
+ ChunkMatcher ( '\n def c(self):\n return 1\n ' ,
971
+ LocationMatcher ( filepath , 1 , 19 ),
972
+ LocationMatcher ( filepath , 1 , 19 ) ),
973
+ ChunkMatcher ( 'self.c()' ,
974
+ LocationMatcher ( filepath , 3 , 14 ),
975
+ LocationMatcher ( filepath , 3 , 15 ) )
976
+ )
977
+ } )
978
+ )
979
+ } ) )
980
+
981
+
982
+ @SharedYcmd
983
+ def test_Subcommands_RefactorExtractFunction_Until ( self , app ):
984
+ filepath = PathToTestFile ( 'signature_help.py' )
985
+ contents = ReadFile ( filepath )
986
+
987
+ command_data = BuildRequest ( filepath = filepath ,
988
+ filetype = 'python' ,
989
+ line_num = 14 ,
990
+ column_num = 24 ,
991
+ range = {
992
+ 'end' : {
993
+ 'line_num' : 14 ,
994
+ 'column_num' : 36
995
+ }
996
+ },
997
+ contents = contents ,
998
+ command_arguments = [
999
+ 'RefactorExtractFunction' ,
1000
+ 'c'
1001
+ ] )
1002
+
1003
+ response = app .post_json ( '/run_completer_command' ,
1004
+ command_data ).json
1005
+
1006
+ assert_that ( response , has_entries ( {
1007
+ 'fixits' : contains_exactly (
1008
+ has_entries ( {
1009
+ 'text' : '' ,
1010
+ 'chunks' : contains_exactly (
1011
+ ChunkMatcher ( "\n def c(self):\n return 'test'.center\n " ,
1012
+ LocationMatcher ( filepath , 9 , 13 ),
1013
+ LocationMatcher ( filepath , 9 , 13 ) ),
1014
+ ChunkMatcher ( 's' ,
1015
+ LocationMatcher ( filepath , 14 , 24 ),
1016
+ LocationMatcher ( filepath , 14 , 26 ) ),
1017
+ ChunkMatcher ( 'lf' ,
1018
+ LocationMatcher ( filepath , 14 , 27 ),
1019
+ LocationMatcher ( filepath , 14 , 30 ) ),
1020
+ ChunkMatcher ( '()' ,
1021
+ LocationMatcher ( filepath , 14 , 32 ),
1022
+ LocationMatcher ( filepath , 14 , 37 ) ),
1023
+ )
1024
+ } )
1025
+ )
1026
+ } ) )
0 commit comments