From 47c7782a54a70a00cfafd7ae7bbbc10b9ce45331 Mon Sep 17 00:00:00 2001 From: luoliwoshang <2643523683@qq.com> Date: Mon, 27 May 2024 11:48:21 +0800 Subject: [PATCH] test:add gop_autogen for package data --- .../regtest/misc/definition_gox_test.go | 39 +++++++++++++------ 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/gopls/internal/regtest/misc/definition_gox_test.go b/gopls/internal/regtest/misc/definition_gox_test.go index 63a45fc7c0a..21aa3b6d6b2 100644 --- a/gopls/internal/regtest/misc/definition_gox_test.go +++ b/gopls/internal/regtest/misc/definition_gox_test.go @@ -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 { @@ -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 @@ -55,6 +55,9 @@ func mulFloat(a, b float64) float64 { func mul = ( mulInt + func(a, b string) string { + return a + b + } mulFloat ) -- test.gop -- @@ -80,7 +83,7 @@ const overloadDefinition3 = ` -- go.mod -- module mod.com -go 1.21.4 +go 1.19 -- def.gop -- type foo struct { } @@ -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) } })