Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools@v0.0.0-20201105173854-bc9fc8d8c4bc / internal / lsp / cmd / test / workspace_symbol.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 cmdtest
6
7 import (
8         "path"
9         "sort"
10         "strings"
11         "testing"
12
13         "golang.org/x/tools/internal/lsp/protocol"
14         "golang.org/x/tools/internal/lsp/tests"
15 )
16
17 func (r *runner) WorkspaceSymbols(t *testing.T, query string, expectedSymbols []protocol.SymbolInformation, dirs map[string]struct{}) {
18         r.runWorkspaceSymbols(t, "caseInsensitive", query, dirs)
19 }
20
21 func (r *runner) FuzzyWorkspaceSymbols(t *testing.T, query string, expectedSymbols []protocol.SymbolInformation, dirs map[string]struct{}) {
22         r.runWorkspaceSymbols(t, "fuzzy", query, dirs)
23 }
24
25 func (r *runner) CaseSensitiveWorkspaceSymbols(t *testing.T, query string, expectedSymbols []protocol.SymbolInformation, dirs map[string]struct{}) {
26         r.runWorkspaceSymbols(t, "caseSensitive", query, dirs)
27 }
28
29 func (r *runner) runWorkspaceSymbols(t *testing.T, matcher, query string, dirs map[string]struct{}) {
30         t.Helper()
31
32         out, _ := r.runGoplsCmd(t, "workspace_symbol", "-matcher", matcher, query)
33         var filtered []string
34         for _, line := range strings.Split(out, "\n") {
35                 for dir := range dirs {
36                         if strings.HasPrefix(line, dir) {
37                                 filtered = append(filtered, line)
38                                 break
39                         }
40                 }
41         }
42         sort.Strings(filtered)
43         got := r.Normalize(strings.Join(filtered, "\n"))
44
45         expect := string(r.data.Golden("workspace_symbol", workspaceSymbolsGolden(matcher, query), func() ([]byte, error) {
46                 return []byte(got), nil
47         }))
48
49         if expect != got {
50                 t.Errorf("workspace_symbol failed for %s:\n%s", query, tests.Diff(expect, got))
51         }
52 }
53
54 var workspaceSymbolsDir = map[string]string{
55         // TODO: make caseInsensitive test cases consistent with
56         // other matcher.
57         "caseInsensitive": "",
58         "fuzzy":           "fuzzy",
59         "caseSensitive":   "casesensitive",
60 }
61
62 func workspaceSymbolsGolden(matcher, query string) string {
63         dir := []string{"workspacesymbol", workspaceSymbolsDir[matcher]}
64         if query == "" {
65                 return path.Join(append(dir, "EmptyQuery")...)
66         }
67
68         var name []rune
69         for _, r := range query {
70                 if 'A' <= r && r <= 'Z' {
71                         // Escape uppercase to '!' + lowercase for case insensitive file systems.
72                         name = append(name, '!', r+'a'-'A')
73                 } else {
74                         name = append(name, r)
75                 }
76         }
77         return path.Join(append(dir, string(name))...)
78 }