github.com/v2fly/tools@v0.100.0/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/v2fly/tools/internal/lsp/diff" 11 "github.com/v2fly/tools/internal/lsp/diff/myers" 12 "github.com/v2fly/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, err := myers.ComputeEdits(uri, want, got) 24 if err != nil { 25 t.Fatal(err) 26 } 27 t.Errorf("imports failed for %s, expected:\n%s", filename, diff.ToUnified("want", "got", want, d)) 28 } 29 }