mirror of
https://github.com/golang/go
synced 2024-11-18 15:24:41 -07:00
912958979a
In https://golang.org/cl/225157, I removed the redundant T and Context parameters from the regtest func signature in an effort to reduce confusion. In hindsight, removing the testing.T did not reduce confusion, because there is a T in the test signature anyway (and now it's the wrong T!). Change-Id: I2e84009e9cb33cd51055012cfef9fe4987e1b9bd Reviewed-on: https://go-review.googlesource.com/c/tools/+/228229 Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Paul Jolly <paul@myitcv.org.uk> TryBot-Result: Gobot Gobot <gobot@golang.org>
80 lines
1.7 KiB
Go
80 lines
1.7 KiB
Go
// Copyright 2020 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package regtest
|
|
|
|
import (
|
|
"path"
|
|
"testing"
|
|
)
|
|
|
|
const internalDefinition = `
|
|
-- go.mod --
|
|
module mod.com
|
|
|
|
go 1.12
|
|
-- main.go --
|
|
package main
|
|
|
|
import "fmt"
|
|
|
|
func main() {
|
|
fmt.Println(message)
|
|
}
|
|
-- const.go --
|
|
package main
|
|
|
|
const message = "Hello World."
|
|
`
|
|
|
|
func TestGoToInternalDefinition(t *testing.T) {
|
|
runner.Run(t, internalDefinition, func(t *testing.T, env *Env) {
|
|
env.OpenFile("main.go")
|
|
name, pos := env.GoToDefinition("main.go", env.RegexpSearch("main.go", "message"))
|
|
if want := "const.go"; name != want {
|
|
t.Errorf("GoToDefinition: got file %q, want %q", name, want)
|
|
}
|
|
if want := env.RegexpSearch("const.go", "message"); pos != want {
|
|
t.Errorf("GoToDefinition: got position %v, want %v", pos, want)
|
|
}
|
|
})
|
|
}
|
|
|
|
const stdlibDefinition = `
|
|
-- go.mod --
|
|
module mod.com
|
|
|
|
go 1.12
|
|
-- main.go --
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
func main() {
|
|
fmt.Println(time.Now())
|
|
}`
|
|
|
|
func TestGoToStdlibDefinition_Issue37045(t *testing.T) {
|
|
runner.Run(t, stdlibDefinition, func(t *testing.T, env *Env) {
|
|
env.OpenFile("main.go")
|
|
name, pos := env.GoToDefinition("main.go", env.RegexpSearch("main.go", "Now"))
|
|
if got, want := path.Base(name), "time.go"; got != want {
|
|
t.Errorf("GoToDefinition: got file %q, want %q", name, want)
|
|
}
|
|
|
|
// Test that we can jump to definition from outside our workspace.
|
|
// See golang.org/issues/37045.
|
|
newName, newPos := env.GoToDefinition(name, pos)
|
|
if newName != name {
|
|
t.Errorf("GoToDefinition is not idempotent: got %q, want %q", newName, name)
|
|
}
|
|
if newPos != pos {
|
|
t.Errorf("GoToDefinition is not idempotent: got %v, want %v", newPos, pos)
|
|
}
|
|
})
|
|
}
|