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.
13 "golang.org/x/tools/internal/lsp/protocol"
14 "golang.org/x/tools/internal/lsp/tests"
17 func (r *runner) WorkspaceSymbols(t *testing.T, query string, expectedSymbols []protocol.SymbolInformation, dirs map[string]struct{}) {
18 r.runWorkspaceSymbols(t, "caseInsensitive", query, dirs)
21 func (r *runner) FuzzyWorkspaceSymbols(t *testing.T, query string, expectedSymbols []protocol.SymbolInformation, dirs map[string]struct{}) {
22 r.runWorkspaceSymbols(t, "fuzzy", query, dirs)
25 func (r *runner) CaseSensitiveWorkspaceSymbols(t *testing.T, query string, expectedSymbols []protocol.SymbolInformation, dirs map[string]struct{}) {
26 r.runWorkspaceSymbols(t, "caseSensitive", query, dirs)
29 func (r *runner) runWorkspaceSymbols(t *testing.T, matcher, query string, dirs map[string]struct{}) {
32 out, _ := r.runGoplsCmd(t, "workspace_symbol", "-matcher", matcher, query)
34 for _, line := range strings.Split(out, "\n") {
35 for dir := range dirs {
36 if strings.HasPrefix(line, dir) {
37 filtered = append(filtered, line)
42 sort.Strings(filtered)
43 got := r.Normalize(strings.Join(filtered, "\n"))
45 expect := string(r.data.Golden("workspace_symbol", workspaceSymbolsGolden(matcher, query), func() ([]byte, error) {
46 return []byte(got), nil
50 t.Errorf("workspace_symbol failed for %s:\n%s", query, tests.Diff(expect, got))
54 var workspaceSymbolsDir = map[string]string{
55 // TODO: make caseInsensitive test cases consistent with
57 "caseInsensitive": "",
59 "caseSensitive": "casesensitive",
62 func workspaceSymbolsGolden(matcher, query string) string {
63 dir := []string{"workspacesymbol", workspaceSymbolsDir[matcher]}
65 return path.Join(append(dir, "EmptyQuery")...)
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')
74 name = append(name, r)
77 return path.Join(append(dir, string(name))...)