.gitignore added
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools / gopls@v0.6.9 / internal / regtest / misc / failures_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 // This test passes (TestHoverOnError in definition_test.go) without
14 // the //line directive
15 func TestHoverFailure(t *testing.T) {
16         const mod = `
17 -- go.mod --
18 module mod.com
19
20 go 1.12
21 -- a.y --
22 DWIM(main)
23
24 -- main.go --
25 //line a.y:1
26 package main
27
28 func main() {
29         var err error
30         err.Error()
31 }`
32         WithOptions(SkipLogs()).Run(t, mod, func(t *testing.T, env *Env) {
33                 env.OpenFile("main.go")
34                 content, _ := env.Hover("main.go", env.RegexpSearch("main.go", "Error"))
35                 // without the //line comment content would be non-nil
36                 if content != nil {
37                         t.Fatalf("expected nil hover content for Error")
38                 }
39         })
40 }
41
42 // badPackageDup contains a duplicate definition of the 'a' const.
43 // this is from diagnostics_test.go,
44 const badPackageDup = `
45 -- go.mod --
46 module mod.com
47
48 go 1.12
49 -- a.go --
50 package consts
51
52 const a = 1
53 -- b.go --
54 package consts
55 //line gen.go:5
56 const a = 2
57 `
58
59 func TestFailingDiagnosticClearingOnEdit(t *testing.T) {
60         Run(t, badPackageDup, func(t *testing.T, env *Env) {
61                 env.OpenFile("b.go")
62                 // no diagnostics for any files, but there should be
63                 env.Await(NoDiagnostics("a.go"), NoDiagnostics("b.go"))
64
65                 // Fix the error by editing the const name in b.go to `b`.
66                 env.RegexpReplace("b.go", "(a) = 2", "b")
67
68                 // The diagnostics that weren't sent above should now be cleared.
69         })
70 }