github.com/v2fly/tools@v0.100.0/internal/lsp/cmd/test/suggested_fix.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/tests"
    12  	"github.com/v2fly/tools/internal/span"
    13  )
    14  
    15  func (r *runner) SuggestedFix(t *testing.T, spn span.Span, actionKinds []string, expectedActions int) {
    16  	uri := spn.URI()
    17  	filename := uri.Filename()
    18  	args := []string{"fix", "-a", fmt.Sprintf("%s", spn)}
    19  	for _, kind := range actionKinds {
    20  		if kind == "refactor.rewrite" {
    21  			t.Skip("refactor.rewrite is not yet supported on the command line")
    22  		}
    23  	}
    24  	args = append(args, actionKinds...)
    25  	got, stderr := r.NormalizeGoplsCmd(t, args...)
    26  	if stderr == "ExecuteCommand is not yet supported on the command line" {
    27  		t.Skipf(stderr)
    28  	}
    29  	want := string(r.data.Golden("suggestedfix_"+tests.SpanName(spn), filename, func() ([]byte, error) {
    30  		return []byte(got), nil
    31  	}))
    32  	if want != got {
    33  		t.Errorf("suggested fixes failed for %s:\n%s", filename, tests.Diff(t, want, got))
    34  	}
    35  }