mirror of
https://github.com/golang/go
synced 2024-11-19 03:04:42 -07:00
a0897bacdd
This change adds support for passing a span to cmd/suggested_fix.go, originally it would just take the filename and apply all the fixes for that file. Now, it can also take just a span within that file and only apply the fixes relevant to that span. The //@suggestedfix marker now contains an extra parameter to specify which type of codeaction is expected. Change-Id: I4e94b8dad719f990dc2d0ef3c50816f70f59f737 Reviewed-on: https://go-review.googlesource.com/c/tools/+/222137 Run-TryBot: Rohan Challa <rohan@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
28 lines
795 B
Go
28 lines
795 B
Go
// Copyright 2019 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 cmdtest
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"golang.org/x/tools/internal/lsp/tests"
|
|
"golang.org/x/tools/internal/span"
|
|
)
|
|
|
|
func (r *runner) SuggestedFix(t *testing.T, spn span.Span, actionKinds []string) {
|
|
uri := spn.URI()
|
|
filename := uri.Filename()
|
|
args := []string{"fix", "-a", fmt.Sprintf("%s", spn)}
|
|
args = append(args, actionKinds...)
|
|
got, _ := r.NormalizeGoplsCmd(t, args...)
|
|
want := string(r.data.Golden("suggestedfix_"+tests.SpanName(spn), filename, func() ([]byte, error) {
|
|
return []byte(got), nil
|
|
}))
|
|
if want != got {
|
|
t.Errorf("suggested fixes failed for %s, expected:\n%v\ngot:\n%v", filename, want, got)
|
|
}
|
|
}
|