Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools@v0.0.0-20201028153306-37f0764111ff / internal / lsp / cmd / test / references.go
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         "fmt"
9         "sort"
10         "testing"
11
12         "golang.org/x/tools/internal/span"
13 )
14
15 func (r *runner) References(t *testing.T, spn span.Span, itemList []span.Span) {
16         for _, includeDeclaration := range []bool{true, false} {
17                 t.Run(fmt.Sprintf("refs-declaration-%v", includeDeclaration), func(t *testing.T) {
18                         var itemStrings []string
19                         for i, s := range itemList {
20                                 // We don't want the first result if we aren't including the declaration.
21                                 if i == 0 && !includeDeclaration {
22                                         continue
23                                 }
24                                 itemStrings = append(itemStrings, fmt.Sprint(s))
25                         }
26                         sort.Strings(itemStrings)
27                         var expect string
28                         for _, s := range itemStrings {
29                                 expect += s + "\n"
30                         }
31                         expect = r.Normalize(expect)
32
33                         uri := spn.URI()
34                         filename := uri.Filename()
35                         target := filename + fmt.Sprintf(":%v:%v", spn.Start().Line(), spn.Start().Column())
36                         args := []string{"references"}
37                         if includeDeclaration {
38                                 args = append(args, "-d")
39                         }
40                         args = append(args, target)
41                         got, stderr := r.NormalizeGoplsCmd(t, args...)
42                         if stderr != "" {
43                                 t.Errorf("references failed for %s: %s", target, stderr)
44                         } else if expect != got {
45                                 t.Errorf("references failed for %s expected:\n%s\ngot:\n%s", target, expect, got)
46                         }
47                 })
48         }
49 }