Skip to content

Commit

Permalink
test:add gop_autogen for package data
Browse files Browse the repository at this point in the history
  • Loading branch information
luoliwoshang committed May 27, 2024
1 parent 1dbed86 commit 47c7782
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions gopls/internal/regtest/misc/definition_gox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const overloadDefinition1 = `
-- go.mod --
module mod.com
go 1.21.4
go 1.19
-- def.gop --
func add = (
func(a, b int) int {
Expand Down Expand Up @@ -43,7 +43,7 @@ const overloadDefinition2 = `
-- go.mod --
module mod.com
go 1.21.4
go 1.19
-- def.gop --
func mulInt(a, b int) int {
return a * b
Expand All @@ -55,6 +55,9 @@ func mulFloat(a, b float64) float64 {
func mul = (
mulInt
func(a, b string) string {
return a + b
}
mulFloat
)
-- test.gop --
Expand All @@ -80,7 +83,7 @@ const overloadDefinition3 = `
-- go.mod --
module mod.com
go 1.21.4
go 1.19
-- def.gop --
type foo struct {
}
Expand Down Expand Up @@ -121,29 +124,43 @@ const overloadDefinition4 = `
-- go.mod --
module mod.com
go 1.21.4
go 1.19
-- def.go --
package main
type foo struct {
const GopPackage = true
type N struct {
}
func (m *N) OnKey__0(a string, fn func()) {
fn()
}
func (f *foo) Broadcast__0(msg string) bool {
return true
func (m *N) OnKey__1(a string, fn func(key string)) {
fn(a)
}
func (m *N) OnKey__2(a []string, fn func()) {
fn()
}
-- test.gop --
var a *foo
a.Broadcast("hhh")
n := &N{}
n.onKey("hello", func() {
println("hello world")
})
`

func TestOverloadDefinition4(t *testing.T) {
Run(t, overloadDefinition4, func(t *testing.T, env *Env) {
env.OpenFile("test.gop")
loc := env.GoToDefinition(env.RegexpSearch("test.gop", "Broadcast"))
loc := env.GoToDefinition(env.RegexpSearch("test.gop", "onKey"))
name := env.Sandbox.Workdir.URIToPath(loc.URI)
if want := "def.go"; name != want {
t.Errorf("GoToDefinition: got file %q, want %q", name, want)
}
if want := env.RegexpSearch("def.go", `Broadcast__0`); loc != want {
if want := env.RegexpSearch("def.go", `OnKey__0`); loc != want {
t.Errorf("GoToDefinition: got location %v, want %v", loc, want)
}
})
Expand Down

0 comments on commit 47c7782

Please sign in to comment.