Skip to content

Commit

Permalink
gopls/internal/regtest: add a test for the case when the renaming pac…
Browse files Browse the repository at this point in the history
…kage'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 <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
  • Loading branch information
Dung Le committed Dec 5, 2022
1 parent bf5db81 commit c9ea9a7
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions gopls/internal/regtest/misc/rename_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit c9ea9a7

Please sign in to comment.