github.com/v2fly/tools@v0.100.0/internal/lsp/cmd/test/semanticdriver.go (about) 1 // Copyright 2020 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 "strings" 9 "testing" 10 11 "github.com/v2fly/tools/internal/span" 12 ) 13 14 func (r *runner) SemanticTokens(t *testing.T, spn span.Span) { 15 uri := spn.URI() 16 filename := uri.Filename() 17 got, stderr := r.NormalizeGoplsCmd(t, "semtok", filename) 18 if stderr != "" { 19 t.Fatalf("%s: %q", filename, stderr) 20 } 21 want := string(r.data.Golden("semantic", filename, func() ([]byte, error) { 22 return []byte(got), nil 23 })) 24 if want != got { 25 lwant := strings.Split(want, "\n") 26 lgot := strings.Split(got, "\n") 27 t.Errorf("want(%d-%d) != got(%d-%d) for %s", len(want), len(lwant), len(got), len(lgot), r.Normalize(filename)) 28 for i := 0; i < len(lwant) && i < len(lgot); i++ { 29 if lwant[i] != lgot[i] { 30 t.Errorf("line %d:\nwant%q\ngot %q\n", i, lwant[i], lgot[i]) 31 } 32 } 33 } 34 }