1 // Copyright 2020 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.
10 . "golang.org/x/tools/gopls/internal/regtest"
12 "golang.org/x/tools/internal/lsp/protocol"
13 "golang.org/x/tools/internal/lsp/tests"
16 // A basic test for fillstruct, now that it uses a command.
17 func TestFillStruct(t *testing.T) {
27 WordCounts map[string]int
35 Run(t, basic, func(t *testing.T, env *Env) {
36 env.OpenFile("main.go")
37 pos := env.RegexpSearch("main.go", "Info{}").ToProtocolPosition()
38 if err := env.Editor.RefactorRewrite(env.Ctx, "main.go", &protocol.Range{
47 WordCounts map[string]int
53 WordCounts: map[string]int{},
58 if got := env.Editor.BufferText("main.go"); got != want {
59 t.Fatalf("TestFillStruct failed:\n%s", tests.Diff(t, want, got))
64 func TestFillReturns(t *testing.T) {
77 Run(t, files, func(t *testing.T, env *Env) {
78 env.OpenFile("main.go")
79 var d protocol.PublishDiagnosticsParams
81 env.DiagnosticAtRegexpWithMessage("main.go", `return`, "wrong number of return values"),
82 ReadDiagnostics("main.go", &d),
84 env.ApplyQuickFixes("main.go", d.Diagnostics)
85 env.Await(EmptyDiagnostics("main.go"))