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 0553172
Showing 1 changed file with 95 additions and 11 deletions.
106 changes: 95 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 All @@ -22,6 +22,21 @@ func add = (
)
-- test.gop --
println add(100, 7)
-- gop_autogen.go --
package main
import "fmt"
const _ = true
func add__0(a int, b int) int {
return a + b
}
func add__1(a string, b string) string {
return a + b
}
func main() {
fmt.Println(add__0(100, 7))
}
`

func TestOverloadDefinition1(t *testing.T) {
Expand All @@ -43,7 +58,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,10 +70,32 @@ func mulFloat(a, b float64) float64 {
func mul = (
mulInt
func(a, b string) string {
return a + b
}
mulFloat
)
-- test.gop --
println mul(100, 7)
-- gop_autogen.go --
package main
import "fmt"
const _ = true
const Gopo_mul = "mulInt,,mulFloat"
func mulInt(a int, b int) int {
return a * b
}
func mul__1(a string, b string) string {
return a + b
}
func mulFloat(a float64, b float64) float64 {
return a * b
}
func main() {
fmt.Println(mulInt(100, 7))
}
`

func TestOverloadDefinition2(t *testing.T) {
Expand All @@ -80,7 +117,7 @@ const overloadDefinition3 = `
-- go.mod --
module mod.com
go 1.21.4
go 1.19
-- def.gop --
type foo struct {
}
Expand All @@ -100,6 +137,27 @@ func (foo).mul = (
-- test.gop --
var a *foo
var c = a.mul(100)
-- gop_autogen.go --
package main
const _ = true
type foo struct {
}
const Gopo_foo_mul = ".mulInt,.mulFoo"
func (a *foo) mulInt(b int) *foo {
return a
}
func (a *foo) mulFoo(b *foo) *foo {
return a
}
var a *foo
var c = a.mulInt(100)
func main() {
}
`

func TestOverloadDefinition3(t *testing.T) {
Expand All @@ -121,29 +179,55 @@ 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 (f *foo) Broadcast__0(msg string) bool {
return true
func (m *N) OnKey__0(a string, fn func()) {
fn()
}
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")
})
-- gop_autogen.go --
package main
import "fmt"
const _ = true
func main() {
n := &N{}
n.OnKey__0("hello", func() {
fmt.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 0553172

Please sign in to comment.