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/span"
|
|
|
|
)
|
|
|
|
|
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"
|
|
|
|
loc := fmt.Sprintf("%v", spn)
|
2019-11-21 17:58:38 -07:00
|
|
|
got, err := r.NormalizeGoplsCmd(t, "rename", loc, newText)
|
|
|
|
got += err
|
2019-09-23 20:50:50 -06:00
|
|
|
expect := string(r.data.Golden(goldenTag, filename, func() ([]byte, error) {
|
|
|
|
return []byte(got), nil
|
|
|
|
}))
|
|
|
|
if expect != got {
|
2019-11-21 17:58:38 -07:00
|
|
|
t.Errorf("rename failed with %v %v\nexpected:\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
|
2019-11-21 17:58:38 -07:00
|
|
|
unified, _ := r.NormalizeGoplsCmd(t, "rename", "-d", loc, newText)
|
2019-09-23 20:50:50 -06:00
|
|
|
checkUnified(t, filename, expect, unified)
|
2019-09-20 16:38:42 -06:00
|
|
|
}
|