@@ -865,6 +865,65 @@ const A = 1 + nested.B
865
865
})
866
866
}
867
867
868
+ func TestRenamePackage_InternalPackage (t * testing.T ) {
869
+ testenv .NeedsGo1Point (t , 17 )
870
+ const files = `
871
+ -- go.mod --
872
+ module mod.com
873
+
874
+ go 1.18
875
+ -- lib/a.go --
876
+ package lib
877
+
878
+ import (
879
+ "fmt"
880
+ "mod.com/lib/internal/x"
881
+ )
882
+
883
+ const A = 1
884
+
885
+ func print() {
886
+ fmt.Println(x.B)
887
+ }
888
+
889
+ -- lib/internal/x/a.go --
890
+ package x
891
+
892
+ const B = 1
893
+
894
+ -- main.go --
895
+ package main
896
+
897
+ import "mod.com/lib"
898
+
899
+ func main() {
900
+ lib.print()
901
+ }
902
+ `
903
+ Run (t , files , func (t * testing.T , env * Env ) {
904
+ env .OpenFile ("lib/internal/x/a.go" )
905
+ pos := env .RegexpSearch ("lib/internal/x/a.go" , "x" )
906
+ env .Rename ("lib/internal/x/a.go" , pos , "utils" )
907
+
908
+ // Check if the new package name exists.
909
+ env .RegexpSearch ("lib/a.go" , "mod.com/lib/internal/utils" )
910
+ env .RegexpSearch ("lib/a.go" , "utils.B" )
911
+
912
+ // Check if the test package is renamed
913
+ env .RegexpSearch ("lib/internal/utils/a.go" , "package utils" )
914
+
915
+ env .OpenFile ("lib/a.go" )
916
+ pos = env .RegexpSearch ("lib/a.go" , "lib" )
917
+ env .Rename ("lib/a.go" , pos , "lib1" )
918
+
919
+ // Check if the new package name exists.
920
+ env .RegexpSearch ("lib1/a.go" , "package lib1" )
921
+ env .RegexpSearch ("lib1/a.go" , "mod.com/lib1/internal/utils" )
922
+ env .RegexpSearch ("main.go" , `import "mod.com/lib1"` )
923
+ env .RegexpSearch ("main.go" , "lib1.print()" )
924
+ })
925
+ }
926
+
868
927
// checkTestdata checks that current buffer contents match their corresponding
869
928
// expected content in the testdata directory.
870
929
func checkTestdata (t * testing.T , env * Env ) {
0 commit comments