Debian Codegraph @

gopls/internal/test/integration/inlayhints/inlayhints_test.go

raw symbols SCIP
1 // Copyright 2022 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 package inlayhint
5
6 import (
7 "os"
8 "testing"
9
10 "golang.org/x/tools/gopls/internal/settings"
11 . "golang.org/x/tools/gopls/internal/test/integration"
12 "golang.org/x/tools/gopls/internal/util/bug"
13 )
14
15 func TestMain(m *testing.M) {
16 bug.PanicOnBugs = true
17 os.Exit(Main(m))
18 }
19
20 func TestEnablingInlayHints(t *testing.T) {
21 const workspace = `
22 -- go.mod --
23 module inlayHint.test
24 go 1.12
25 -- lib.go --
26 package lib
27 type Number int
28 const (
29 Zero Number = iota
30 One
31 Two
32 )
33 `
34 tests := []struct {
35 label string
36 enabled map[string]bool
37 wantInlayHint bool
38 }{
39 {
40 label: "default",
41 wantInlayHint: false,
42 },
43 {
44 label: "enable const",
45 enabled: map[string]bool{string(settings.ConstantValues): true},
46 wantInlayHint: true,
47 },
48 {
49 label: "enable parameter names",
50 enabled: map[string]bool{string(settings.ParameterNames): true},
51 wantInlayHint: false,
52 },
53 }
54 for _, test := range tests {
55 t.Run(test.label, func(t *testing.T) {
56 WithOptions(
57 Settings{
58 "hints": test.enabled,
59 },
60 ).Run(t, workspace, func(t *testing.T, env *Env) {
61 env.OpenFile("lib.go")
62 lens := env.InlayHints("lib.go")
63 if gotInlayHint := len(lens) > 0; gotInlayHint != test.wantInlayHint {
64 t.Errorf("got inlayHint: %t, want %t", gotInlayHint, test.wantInlayHint)
65 }
66 })
67 })
68 }
69 }