Skip to content

Commit c9ea9a7

Browse files
author
Dung Le
committed
gopls/internal/regtest: add a test for the case when the renaming package's path contains "internal" as a segment
For golang/go#56184. Change-Id: Id33650adb5befb0a2cdead28425ad6ec8f7d9e0d Reviewed-on: https://go-review.googlesource.com/c/tools/+/450556 gopls-CI: kokoro <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent bf5db81 commit c9ea9a7

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

gopls/internal/regtest/misc/rename_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,65 @@ const A = 1 + nested.B
865865
})
866866
}
867867

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+
868927
// checkTestdata checks that current buffer contents match their corresponding
869928
// expected content in the testdata directory.
870929
func checkTestdata(t *testing.T, env *Env) {

0 commit comments

Comments
 (0)