1
0
mirror of https://github.com/golang/go synced 2024-11-05 18:46:11 -07:00
go/internal/lsp/cmd/test/references.go
Rebecca Stambler ba161d9e22 internal/lsp: add tests for references includeDeclaration setting
Make sure to test both modes, as this is the second time we've
accidentally broken this.

Fixes golang/go#36598.

Change-Id: I3993af3d106b18c76c44ada558b2c6cd9cbfcf17
Reviewed-on: https://go-review.googlesource.com/c/tools/+/215777
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-01-23 01:39:50 +00:00

50 lines
1.4 KiB
Go

// 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"
"sort"
"testing"
"golang.org/x/tools/internal/span"
)
func (r *runner) References(t *testing.T, spn span.Span, itemList []span.Span) {
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)
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)
}
})
}
}