Skip to content

Commit 47c7782

Browse files
committed
test:add gop_autogen for package data
1 parent 1dbed86 commit 47c7782

1 file changed

Lines changed: 28 additions & 11 deletions

File tree

gopls/internal/regtest/misc/definition_gox_test.go

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const overloadDefinition1 = `
1010
-- go.mod --
1111
module mod.com
1212
13-
go 1.21.4
13+
go 1.19
1414
-- def.gop --
1515
func add = (
1616
func(a, b int) int {
@@ -43,7 +43,7 @@ const overloadDefinition2 = `
4343
-- go.mod --
4444
module mod.com
4545
46-
go 1.21.4
46+
go 1.19
4747
-- def.gop --
4848
func mulInt(a, b int) int {
4949
return a * b
@@ -55,6 +55,9 @@ func mulFloat(a, b float64) float64 {
5555
5656
func mul = (
5757
mulInt
58+
func(a, b string) string {
59+
return a + b
60+
}
5861
mulFloat
5962
)
6063
-- test.gop --
@@ -80,7 +83,7 @@ const overloadDefinition3 = `
8083
-- go.mod --
8184
module mod.com
8285
83-
go 1.21.4
86+
go 1.19
8487
-- def.gop --
8588
type foo struct {
8689
}
@@ -121,29 +124,43 @@ const overloadDefinition4 = `
121124
-- go.mod --
122125
module mod.com
123126
124-
go 1.21.4
127+
go 1.19
125128
-- def.go --
126129
package main
127-
type foo struct {
130+
131+
const GopPackage = true
132+
133+
type N struct {
134+
}
135+
136+
func (m *N) OnKey__0(a string, fn func()) {
137+
fn()
128138
}
129139
130-
func (f *foo) Broadcast__0(msg string) bool {
131-
return true
140+
func (m *N) OnKey__1(a string, fn func(key string)) {
141+
fn(a)
142+
}
143+
144+
func (m *N) OnKey__2(a []string, fn func()) {
145+
fn()
132146
}
133147
-- test.gop --
134-
var a *foo
135-
a.Broadcast("hhh")
148+
n := &N{}
149+
150+
n.onKey("hello", func() {
151+
println("hello world")
152+
})
136153
`
137154

138155
func TestOverloadDefinition4(t *testing.T) {
139156
Run(t, overloadDefinition4, func(t *testing.T, env *Env) {
140157
env.OpenFile("test.gop")
141-
loc := env.GoToDefinition(env.RegexpSearch("test.gop", "Broadcast"))
158+
loc := env.GoToDefinition(env.RegexpSearch("test.gop", "onKey"))
142159
name := env.Sandbox.Workdir.URIToPath(loc.URI)
143160
if want := "def.go"; name != want {
144161
t.Errorf("GoToDefinition: got file %q, want %q", name, want)
145162
}
146-
if want := env.RegexpSearch("def.go", `Broadcast__0`); loc != want {
163+
if want := env.RegexpSearch("def.go", `OnKey__0`); loc != want {
147164
t.Errorf("GoToDefinition: got location %v, want %v", loc, want)
148165
}
149166
})

0 commit comments

Comments
 (0)