Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
internal/lsp: add InlayHint regtests
Add regtests for inlay hints to verify we can turn on and off different inlay hints. Change-Id: Id88450c40c048b6c2544d22a0d3eadb57b70a723 Reviewed-on: https://go-review.googlesource.com/c/tools/+/411911 Reviewed-by: Robert Findley <rfindley@google.com> Reviewed-by: Jamal Carvalho <jamal@golang.org> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Suzy Mueller <suzmue@golang.org>
- Loading branch information
Showing
3 changed files
with
104 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright 2022 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 inlayHint | ||
|
||
import ( | ||
"testing" | ||
|
||
"golang.org/x/tools/gopls/internal/hooks" | ||
"golang.org/x/tools/internal/lsp/bug" | ||
. "golang.org/x/tools/internal/lsp/regtest" | ||
"golang.org/x/tools/internal/lsp/source" | ||
"golang.org/x/tools/internal/testenv" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
bug.PanicOnBugs = true | ||
Main(m, hooks.Options) | ||
} | ||
func TestEnablingInlayHints(t *testing.T) { | ||
testenv.NeedsGo1Point(t, 14) // Test fails on 1.13. | ||
const workspace = ` | ||
-- go.mod -- | ||
module inlayHint.test | ||
go 1.12 | ||
-- lib.go -- | ||
package lib | ||
type Number int | ||
const ( | ||
Zero Number = iota | ||
One | ||
Two | ||
) | ||
` | ||
tests := []struct { | ||
label string | ||
enabled map[string]bool | ||
wantInlayHint bool | ||
}{ | ||
{ | ||
label: "default", | ||
wantInlayHint: false, | ||
}, | ||
{ | ||
label: "enable const", | ||
enabled: map[string]bool{source.ConstantValues: true}, | ||
wantInlayHint: true, | ||
}, | ||
{ | ||
label: "enable parameter names", | ||
enabled: map[string]bool{source.ParameterNames: true}, | ||
wantInlayHint: false, | ||
}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.label, func(t *testing.T) { | ||
WithOptions( | ||
EditorConfig{ | ||
Settings: map[string]interface{}{ | ||
"hints": test.enabled, | ||
}, | ||
}, | ||
).Run(t, workspace, func(t *testing.T, env *Env) { | ||
env.OpenFile("lib.go") | ||
lens := env.InlayHints("lib.go") | ||
if gotInlayHint := len(lens) > 0; gotInlayHint != test.wantInlayHint { | ||
t.Errorf("got inlayHint: %t, want %t", gotInlayHint, test.wantInlayHint) | ||
} | ||
}) | ||
}) | ||
} | ||
} |
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
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