github.com/jd-ly/tools@v0.5.7/internal/lsp/cmd/test/imports.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  	"testing"
     9  
    10  	"github.com/jd-ly/tools/internal/lsp/diff"
    11  	"github.com/jd-ly/tools/internal/lsp/diff/myers"
    12  	"github.com/jd-ly/tools/internal/span"
    13  )
    14  
    15  func (r *runner) Import(t *testing.T, spn span.Span) {
    16  	uri := spn.URI()
    17  	filename := uri.Filename()
    18  	got, _ := r.NormalizeGoplsCmd(t, "imports", filename)
    19  	want := string(r.data.Golden("goimports", filename, func() ([]byte, error) {
    20  		return []byte(got), nil
    21  	}))
    22  	if want != got {
    23  		d := myers.ComputeEdits(uri, want, got)
    24  		t.Errorf("imports failed for %s, expected:\n%s", filename, diff.ToUnified("want", "got", want, d))
    25  	}
    26  }