| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package hover |
| 6 |
|
| 7 |
import ( |
| 8 |
"os" |
| 9 |
"strings" |
| 10 |
"testing" |
| 11 |
|
| 12 |
. "golang.org/x/tools/gopls/internal/test/integration" |
| 13 |
"golang.org/x/tools/gopls/internal/util/bug" |
| 14 |
) |
| 15 |
|
| 16 |
func TestMain(m *testing.M) { |
| 17 |
bug.PanicOnBugs = true |
| 18 |
os.Exit(Main(m)) |
| 19 |
} |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
func TestIssue77675(t *testing.T) { |
| 24 |
const src = ` |
| 25 |
-- go.mod -- |
| 26 |
module mod.com |
| 27 |
|
| 28 |
go 1.20 |
| 29 |
|
| 30 |
-- main.go -- |
| 31 |
package main |
| 32 |
|
| 33 |
func _() { |
| 34 |
_ = ` + "`" + `foo |
| 35 |
|
| 36 |
bar |
| 37 |
baz` + "`" + ` |
| 38 |
} |
| 39 |
` |
| 40 |
WithOptions( |
| 41 |
WindowsLineEndings(), |
| 42 |
).Run(t, src, func(t *testing.T, env *Env) { |
| 43 |
env.OpenFile("main.go") |
| 44 |
env.Await(env.DoneWithOpen()) |
| 45 |
loc := env.RegexpSearch("main.go", "baz()") |
| 46 |
content, l := env.Hover(loc) |
| 47 |
if !l.Empty() { |
| 48 |
t.Errorf("hover expect empty range got: %v", l) |
| 49 |
} |
| 50 |
if content != nil { |
| 51 |
t.Errorf("hover expect empty result got: %v", content) |
| 52 |
} |
| 53 |
}) |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
func TestIssue79146(t *testing.T) { |
| 59 |
const src = ` |
| 60 |
-- go.mod -- |
| 61 |
module mod.com |
| 62 |
|
| 63 |
go 1.20 |
| 64 |
|
| 65 |
-- main.go -- |
| 66 |
package main |
| 67 |
|
| 68 |
// Foo comment |
| 69 |
func Foo() { |
| 70 |
x := 1 |
| 71 |
_ = x |
| 72 |
} |
| 73 |
|
| 74 |
// F comment |
| 75 |
func F() {} |
| 76 |
` |
| 77 |
Run(t, src, func(t *testing.T, env *Env) { |
| 78 |
env.OpenFile("main.go") |
| 79 |
env.Await(env.DoneWithOpen()) |
| 80 |
loc := env.RegexpSearch("main.go", "x") |
| 81 |
content, _ := env.Hover(loc) |
| 82 |
if content == nil { |
| 83 |
t.Fatal("hover returned nil") |
| 84 |
} |
| 85 |
if strings.Contains(content.Value, "F") || strings.Contains(content.Value, "Foo") { |
| 86 |
t.Errorf("hover result incorrectly includes irrelevant comment :\n%s", content.Value) |
| 87 |
} |
| 88 |
}) |
| 89 |
} |