Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools / gopls@v0.5.2 / internal / regtest / symbol_helper_test.go
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 regtest
6
7 import (
8         "encoding/json"
9         "fmt"
10
11         "golang.org/x/tools/internal/lsp/fake"
12         "golang.org/x/tools/internal/lsp/protocol"
13 )
14
15 // expSymbolInformation and the types it references are pointer-based versions
16 // of fake.SymbolInformation, used to make it easier to partially assert
17 // against values of type fake.SymbolInformation
18
19 // expSymbolInformation is a pointer-based version of fake.SymbolInformation
20 type expSymbolInformation struct {
21         Name     *string
22         Kind     *protocol.SymbolKind
23         Location *expLocation
24 }
25
26 func (e *expSymbolInformation) matchAgainst(sis []fake.SymbolInformation) bool {
27         for _, si := range sis {
28                 if e.match(si) {
29                         return true
30                 }
31         }
32         return false
33 }
34
35 func (e *expSymbolInformation) match(si fake.SymbolInformation) bool {
36         if e.Name != nil && *e.Name != si.Name {
37                 return false
38         }
39         if e.Kind != nil && *e.Kind != si.Kind {
40                 return false
41         }
42         if e.Location != nil && !e.Location.match(si.Location) {
43                 return false
44         }
45         return true
46 }
47
48 func (e *expSymbolInformation) String() string {
49         byts, err := json.MarshalIndent(e, "", "  ")
50         if err != nil {
51                 panic(fmt.Errorf("failed to json.Marshal *expSymbolInformation: %v", err))
52         }
53         return string(byts)
54 }
55
56 // expLocation is a pointer-based version of fake.Location
57 type expLocation struct {
58         Path  *string
59         Range *expRange
60 }
61
62 func (e *expLocation) match(l fake.Location) bool {
63         if e.Path != nil && *e.Path != l.Path {
64                 return false
65         }
66         if e.Range != nil && !e.Range.match(l.Range) {
67                 return false
68         }
69         return true
70 }
71
72 // expRange is a pointer-based version of fake.Range
73 type expRange struct {
74         Start *expPos
75         End   *expPos
76 }
77
78 func (e *expRange) match(l fake.Range) bool {
79         if e.Start != nil && !e.Start.match(l.Start) {
80                 return false
81         }
82         if e.End != nil && !e.End.match(l.End) {
83                 return false
84         }
85         return true
86 }
87
88 // expPos is a pointer-based version of fake.Pos
89 type expPos struct {
90         Line   *int
91         Column *int
92 }
93
94 func (e *expPos) match(l fake.Pos) bool {
95         if e.Line != nil && *e.Line != l.Line {
96                 return false
97         }
98         if e.Column != nil && *e.Column != l.Column {
99                 return false
100         }
101         return true
102 }
103
104 func pString(s string) *string {
105         return &s
106 }
107
108 func pInt(i int) *int {
109         return &i
110 }
111
112 func pKind(k protocol.SymbolKind) *protocol.SymbolKind {
113         return &k
114 }