-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gopls/internal/regtest/marker: add missing tests for hover
Add additional tests for hover behavior. These tests would have failed in earlier patchsets of the subsequent CL rewriting hover. Also, add support for the special "env" file to the marker framework. Change-Id: Iecbd4994a6c1261f87163d50793fbbc5f26ea1ba Reviewed-on: https://go-review.googlesource.com/c/tools/+/466135 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Alan Donovan <adonovan@google.com> gopls-CI: kokoro <noreply+kokoro@google.com>
- Loading branch information
Showing
3 changed files
with
181 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
gopls/internal/regtest/marker/testdata/hover/goprivate.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
This test checks that links in hover obey GOPRIVATE. | ||
-- env -- | ||
GOPRIVATE=mod.com | ||
-- go.mod -- | ||
module mod.com | ||
-- p.go -- | ||
package p | ||
|
||
// T should not be linked, as it is private. | ||
type T struct{} //@hover("T", "T", T) | ||
-- lib/lib.go -- | ||
package lib | ||
|
||
// GOPRIVATE should also match nested packages. | ||
type L struct{} //@hover("L", "L", L) | ||
-- @L/hover.md -- | ||
```go | ||
type L struct{} | ||
``` | ||
|
||
GOPRIVATE should also match nested packages. | ||
-- @T/hover.md -- | ||
```go | ||
type T struct{} | ||
``` | ||
|
||
T should not be linked, as it is private. |
123 changes: 123 additions & 0 deletions
123
gopls/internal/regtest/marker/testdata/hover/linkable.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
This test checks that we correctly determine pkgsite links for various | ||
identifiers. | ||
|
||
We should only produce links that work, meaning the object is reachable via the | ||
package's public API. | ||
-- go.mod -- | ||
module mod.com | ||
|
||
go 1.18 | ||
-- p.go -- | ||
package p | ||
|
||
type E struct { | ||
Embed int | ||
} | ||
|
||
// T is in the package scope, and so should be linkable. | ||
type T struct{ //@hover("T", "T", T) | ||
// Only exported fields should be linkable | ||
|
||
f int //@hover("f", "f", f) | ||
F int //@hover("F", "F", F) | ||
|
||
E | ||
|
||
// TODO(rfindley): is the link here correct? It ignores N. | ||
N struct { | ||
// Nested fields should also be linkable. | ||
Nested int //@hover("Nested", "Nested", Nested) | ||
} | ||
} | ||
// M is an exported method, and so should be linkable. | ||
func (T) M() {} | ||
|
||
// m is not exported, and so should not be linkable. | ||
func (T) m() {} | ||
|
||
func _() { | ||
var t T | ||
|
||
// Embedded fields should be linkable. | ||
_ = t.Embed //@hover("Embed", "Embed", Embed) | ||
|
||
// Local variables should not be linkable, even if they are capitalized. | ||
var X int //@hover("X", "X", X) | ||
_ = X | ||
|
||
// Local types should not be linkable, even if they are capitalized. | ||
type Local struct { //@hover("Local", "Local", Local) | ||
E | ||
} | ||
|
||
// But the embedded field should still be linkable. | ||
var l Local | ||
_ = l.Embed //@hover("Embed", "Embed", Embed) | ||
} | ||
-- @Embed/hover.md -- | ||
```go | ||
field Embed int | ||
``` | ||
|
||
[`(p.E).Embed` on pkg.go.dev](https://pkg.go.dev/mod.com#E.Embed) | ||
-- @F/hover.md -- | ||
```go | ||
field F int | ||
``` | ||
|
||
@hover("F", "F", F) | ||
|
||
|
||
[`(p.T).F` on pkg.go.dev](https://pkg.go.dev/mod.com#T.F) | ||
-- @Local/hover.md -- | ||
```go | ||
type Local struct { | ||
E | ||
} | ||
``` | ||
|
||
Local types should not be linkable, even if they are capitalized. | ||
-- @Nested/hover.md -- | ||
```go | ||
field Nested int | ||
``` | ||
|
||
Nested fields should also be linkable. | ||
|
||
|
||
[`(p.T).Nested` on pkg.go.dev](https://pkg.go.dev/mod.com#T.Nested) | ||
-- @T/hover.md -- | ||
```go | ||
type T struct { | ||
f int //@hover("f", "f", f) | ||
F int //@hover("F", "F", F) | ||
|
||
E | ||
|
||
// TODO(rfindley): is the link here correct? It ignores N. | ||
N struct { | ||
// Nested fields should also be linkable. | ||
Nested int //@hover("Nested", "Nested", Nested) | ||
} | ||
} | ||
|
||
func (T).M() | ||
func (T).m() | ||
``` | ||
|
||
T is in the package scope, and so should be linkable. | ||
|
||
|
||
[`p.T` on pkg.go.dev](https://pkg.go.dev/mod.com#T) | ||
-- @X/hover.md -- | ||
```go | ||
var X int | ||
``` | ||
|
||
Local variables should not be linkable, even if they are capitalized. | ||
-- @f/hover.md -- | ||
```go | ||
field f int | ||
``` | ||
|
||
@hover("f", "f", f) |