From c9ea9a72c54987217e6af00e7a6a29f26a316d0a Mon Sep 17 00:00:00 2001 From: Dung Le Date: Tue, 15 Nov 2022 03:31:39 -0500 Subject: [PATCH] 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 TryBot-Result: Gopher Robot Reviewed-by: Robert Findley --- gopls/internal/regtest/misc/rename_test.go | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/gopls/internal/regtest/misc/rename_test.go b/gopls/internal/regtest/misc/rename_test.go index a9fd920317f..a772770562e 100644 --- a/gopls/internal/regtest/misc/rename_test.go +++ b/gopls/internal/regtest/misc/rename_test.go @@ -865,6 +865,65 @@ const A = 1 + nested.B }) } +func TestRenamePackage_InternalPackage(t *testing.T) { + testenv.NeedsGo1Point(t, 17) + const files = ` +-- go.mod -- +module mod.com + +go 1.18 +-- lib/a.go -- +package lib + +import ( + "fmt" + "mod.com/lib/internal/x" +) + +const A = 1 + +func print() { + fmt.Println(x.B) +} + +-- lib/internal/x/a.go -- +package x + +const B = 1 + +-- main.go -- +package main + +import "mod.com/lib" + +func main() { + lib.print() +} +` + Run(t, files, func(t *testing.T, env *Env) { + env.OpenFile("lib/internal/x/a.go") + pos := env.RegexpSearch("lib/internal/x/a.go", "x") + env.Rename("lib/internal/x/a.go", pos, "utils") + + // Check if the new package name exists. + env.RegexpSearch("lib/a.go", "mod.com/lib/internal/utils") + env.RegexpSearch("lib/a.go", "utils.B") + + // Check if the test package is renamed + env.RegexpSearch("lib/internal/utils/a.go", "package utils") + + env.OpenFile("lib/a.go") + pos = env.RegexpSearch("lib/a.go", "lib") + env.Rename("lib/a.go", pos, "lib1") + + // Check if the new package name exists. + env.RegexpSearch("lib1/a.go", "package lib1") + env.RegexpSearch("lib1/a.go", "mod.com/lib1/internal/utils") + env.RegexpSearch("main.go", `import "mod.com/lib1"`) + env.RegexpSearch("main.go", "lib1.print()") + }) +} + // checkTestdata checks that current buffer contents match their corresponding // expected content in the testdata directory. func checkTestdata(t *testing.T, env *Env) {