2019-10-19 15:26:56 -06:00
|
|
|
// Copyright 2019 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 (
|
|
|
|
"fmt"
|
2019-11-12 18:16:00 -07:00
|
|
|
"sort"
|
|
|
|
"testing"
|
|
|
|
|
2019-10-19 15:26:56 -06:00
|
|
|
"golang.org/x/tools/internal/span"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (r *runner) References(t *testing.T, spn span.Span, itemList []span.Span) {
|
2020-01-21 23:44:33 -07:00
|
|
|
for _, includeDeclaration := range []bool{true, false} {
|
|
|
|
t.Run(fmt.Sprintf("refs-declaration-%v", includeDeclaration), func(t *testing.T) {
|
|
|
|
var itemStrings []string
|
|
|
|
for i, s := range itemList {
|
|
|
|
// We don't want the first result if we aren't including the declaration.
|
|
|
|
if i == 0 && !includeDeclaration {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
itemStrings = append(itemStrings, fmt.Sprint(s))
|
|
|
|
}
|
|
|
|
sort.Strings(itemStrings)
|
|
|
|
var expect string
|
|
|
|
for _, s := range itemStrings {
|
|
|
|
expect += s + "\n"
|
|
|
|
}
|
|
|
|
expect = r.Normalize(expect)
|
2019-10-19 15:26:56 -06:00
|
|
|
|
2020-01-21 23:44:33 -07:00
|
|
|
uri := spn.URI()
|
|
|
|
filename := uri.Filename()
|
|
|
|
target := filename + fmt.Sprintf(":%v:%v", spn.Start().Line(), spn.Start().Column())
|
|
|
|
args := []string{"references"}
|
|
|
|
if includeDeclaration {
|
|
|
|
args = append(args, "-d")
|
|
|
|
}
|
|
|
|
args = append(args, target)
|
|
|
|
got, stderr := r.NormalizeGoplsCmd(t, args...)
|
|
|
|
if stderr != "" {
|
|
|
|
t.Errorf("references failed for %s: %s", target, stderr)
|
|
|
|
} else if expect != got {
|
|
|
|
t.Errorf("references failed for %s expected:\n%s\ngot:\n%s", target, expect, got)
|
|
|
|
}
|
|
|
|
})
|
2019-10-19 15:26:56 -06:00
|
|
|
}
|
|
|
|
}
|