github.com/v2fly/tools@v0.100.0/internal/lsp/cmd/test/prepare_rename.go (about) 1 // Copyright 2019 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. 4 5 package cmdtest 6 7 import ( 8 "fmt" 9 "testing" 10 11 "github.com/v2fly/tools/internal/lsp/cmd" 12 "github.com/v2fly/tools/internal/lsp/protocol" 13 "github.com/v2fly/tools/internal/lsp/source" 14 "github.com/v2fly/tools/internal/span" 15 ) 16 17 func (r *runner) PrepareRename(t *testing.T, src span.Span, want *source.PrepareItem) { 18 m, err := r.data.Mapper(src.URI()) 19 if err != nil { 20 t.Errorf("prepare_rename failed: %v", err) 21 } 22 23 var ( 24 target = fmt.Sprintf("%v", src) 25 args = []string{"prepare_rename", target} 26 stdOut, stdErr = r.NormalizeGoplsCmd(t, args...) 27 expect string 28 ) 29 30 if want.Text == "" { 31 if stdErr != "" && stdErr != cmd.ErrInvalidRenamePosition.Error() { 32 t.Errorf("prepare_rename failed for %s,\nexpected:\n`%v`\ngot:\n`%v`", target, expect, stdErr) 33 } 34 return 35 } 36 37 ws, err := m.Span(protocol.Location{Range: want.Range}) 38 if err != nil { 39 t.Errorf("prepare_rename failed: %v", err) 40 } 41 42 expect = r.Normalize(fmt.Sprintln(ws)) 43 if expect != stdOut { 44 t.Errorf("prepare_rename failed for %s expected:\n`%s`\ngot:\n`%s`\n", target, expect, stdOut) 45 } 46 }