github.com/v2fly/tools@v0.100.0/internal/lsp/cmd/test/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/span"
    12  )
    13  
    14  func (r *runner) Rename(t *testing.T, spn span.Span, newText string) {
    15  	filename := spn.URI().Filename()
    16  	goldenTag := newText + "-rename"
    17  	loc := fmt.Sprintf("%v", spn)
    18  	got, err := r.NormalizeGoplsCmd(t, "rename", loc, newText)
    19  	got += err
    20  	expect := string(r.data.Golden(goldenTag, filename, func() ([]byte, error) {
    21  		return []byte(got), nil
    22  	}))
    23  	if expect != got {
    24  		t.Errorf("rename failed with %v %v\nexpected:\n%s\ngot:\n%s", loc, newText, expect, got)
    25  	}
    26  	// now check we can build a valid unified diff
    27  	unified, _ := r.NormalizeGoplsCmd(t, "rename", "-d", loc, newText)
    28  	checkUnified(t, filename, expect, unified)
    29  }