2019-09-20 16:38:42 -06:00
|
|
|
// 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.
|
|
|
|
|
2019-09-18 21:51:24 -06:00
|
|
|
package cmdtest
|
2019-09-20 16:38:42 -06:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"golang.org/x/tools/internal/lsp/cmd"
|
|
|
|
"golang.org/x/tools/internal/span"
|
|
|
|
"golang.org/x/tools/internal/tool"
|
|
|
|
)
|
|
|
|
|
2019-09-26 11:56:23 -06:00
|
|
|
func (r *runner) Rename(t *testing.T, spn span.Span, newText string) {
|
|
|
|
filename := spn.URI().Filename()
|
2019-09-23 20:50:50 -06:00
|
|
|
goldenTag := newText + "-rename"
|
2019-10-10 18:48:16 -06:00
|
|
|
app := cmd.New("gopls-test", r.data.Config.Dir, r.data.Config.Env, r.options)
|
2019-09-23 20:50:50 -06:00
|
|
|
loc := fmt.Sprintf("%v", spn)
|
|
|
|
var err error
|
|
|
|
got := CaptureStdOut(t, func() {
|
|
|
|
err = tool.Run(r.ctx, app, []string{"-remote=internal", "rename", loc, newText})
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
got = err.Error()
|
|
|
|
}
|
|
|
|
got = normalizePaths(r.data, got)
|
|
|
|
expect := string(r.data.Golden(goldenTag, filename, func() ([]byte, error) {
|
|
|
|
return []byte(got), nil
|
|
|
|
}))
|
|
|
|
if expect != got {
|
|
|
|
t.Errorf("rename failed with %v %v expected:\n%s\ngot:\n%s", loc, newText, expect, got)
|
2019-09-20 16:38:42 -06:00
|
|
|
}
|
2019-09-23 20:50:50 -06:00
|
|
|
// now check we can build a valid unified diff
|
|
|
|
unified := CaptureStdOut(t, func() {
|
|
|
|
_ = tool.Run(r.ctx, app, []string{"-remote=internal", "rename", "-d", loc, newText})
|
|
|
|
})
|
|
|
|
checkUnified(t, filename, expect, unified)
|
2019-09-20 16:38:42 -06:00
|
|
|
}
|