.gitignore added
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools / gopls@v0.6.9 / internal / regtest / misc / references_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 misc
6
7 import (
8         "testing"
9
10         . "golang.org/x/tools/gopls/internal/regtest"
11 )
12
13 func TestStdlibReferences(t *testing.T) {
14         const files = `
15 -- go.mod --
16 module mod.com
17
18 go 1.12
19 -- main.go --
20 package main
21
22 import "fmt"
23
24 func main() {
25         fmt.Print()
26 }
27 `
28
29         Run(t, files, func(t *testing.T, env *Env) {
30                 env.OpenFile("main.go")
31                 file, pos := env.GoToDefinition("main.go", env.RegexpSearch("main.go", `fmt.(Print)`))
32                 refs, err := env.Editor.References(env.Ctx, file, pos)
33                 if err != nil {
34                         t.Fatal(err)
35                 }
36                 if len(refs) != 2 {
37                         t.Fatalf("got %v reference(s), want 2", len(refs))
38                 }
39                 // The first reference is guaranteed to be the definition.
40                 if got, want := refs[1].URI, env.Sandbox.Workdir.URI("main.go"); got != want {
41                         t.Errorf("found reference in %v, wanted %v", got, want)
42                 }
43         })
44 }