forked from golang/tools
/
semanticdriver.go
34 lines (30 loc) · 949 Bytes
/
semanticdriver.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package cmdtest
import (
"strings"
"testing"
"golang.org/x/tools/internal/span"
)
func (r *runner) SemanticTokens(t *testing.T, spn span.Span) {
uri := spn.URI()
filename := uri.Filename()
got, stderr := r.NormalizeGoplsCmd(t, "semtok", filename)
if stderr != "" {
t.Fatalf("%s: %q", filename, stderr)
}
want := string(r.data.Golden("semantic", filename, func() ([]byte, error) {
return []byte(got), nil
}))
if want != got {
lwant := strings.Split(want, "\n")
lgot := strings.Split(got, "\n")
t.Errorf("want(%d-%d) != got(%d-%d) for %s", len(want), len(lwant), len(got), len(lgot), r.Normalize(filename))
for i := 0; i < len(lwant) && i < len(lgot); i++ {
if lwant[i] != lgot[i] {
t.Errorf("line %d:\nwant%q\ngot %q\n", i, lwant[i], lgot[i])
}
}
}
}