blob: 79e60e27511f43ef0365eb30e6bd9e2cfcbbe201 [file] [log] [blame]
Rob Findley6da3d7a2021-05-17 16:24:09 -04001// Copyright 2021 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package misc
6
7import (
8 "strings"
9 "testing"
10
11 . "golang.org/x/tools/internal/lsp/regtest"
danishprakash0c506a22021-06-20 12:32:55 +053012 "golang.org/x/tools/internal/testenv"
Rob Findley6da3d7a2021-05-17 16:24:09 -040013)
14
15func TestHoverUnexported(t *testing.T) {
16 const proxy = `
17-- golang.org/x/structs@v1.0.0/go.mod --
18module golang.org/x/structs
19
20go 1.12
21
22-- golang.org/x/structs@v1.0.0/types.go --
23package structs
24
25type Mixed struct {
26 Exported int
27 unexported string
28}
29`
30 const mod = `
31-- go.mod --
32module mod.com
33
34go 1.12
35
36require golang.org/x/structs v1.0.0
37-- go.sum --
38golang.org/x/structs v1.0.0 h1:oxD5q25qV458xBbXf5+QX+Johgg71KFtwuJzt145c9A=
39golang.org/x/structs v1.0.0/go.mod h1:47gkSIdo5AaQaWJS0upVORsxfEr1LL1MWv9dmYF3iq4=
40-- main.go --
41package main
42
43import "golang.org/x/structs"
44
45func main() {
46 var _ structs.Mixed
47}
48`
49 // TODO: use a nested workspace folder here.
50 WithOptions(
51 ProxyFiles(proxy),
52 ).Run(t, mod, func(t *testing.T, env *Env) {
53 env.OpenFile("main.go")
54 got, _ := env.Hover("main.go", env.RegexpSearch("main.go", "Mixed"))
55 if !strings.Contains(got.Value, "unexported") {
56 t.Errorf("Hover: missing expected field 'unexported'. Got:\n%q", got.Value)
57 }
58 })
59}
danishprakash0c506a22021-06-20 12:32:55 +053060
61func TestHoverIntLiteral(t *testing.T) {
62 testenv.NeedsGo1Point(t, 13)
63 const source = `
64-- main.go --
65package main
66
67var (
68 bigBin = 0b1001001
69)
70
71var hex = 0xe34e
72
73func main() {
74}
75`
76 Run(t, source, func(t *testing.T, env *Env) {
77 env.OpenFile("main.go")
78 hexExpected := "58190"
79 got, _ := env.Hover("main.go", env.RegexpSearch("main.go", "hex"))
80 if got != nil && !strings.Contains(got.Value, hexExpected) {
81 t.Errorf("Hover: missing expected field '%s'. Got:\n%q", hexExpected, got.Value)
82 }
83
84 binExpected := "73"
85 got, _ = env.Hover("main.go", env.RegexpSearch("main.go", "bigBin"))
86 if got != nil && !strings.Contains(got.Value, binExpected) {
87 t.Errorf("Hover: missing expected field '%s'. Got:\n%q", binExpected, got.Value)
88 }
89 })
90}