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 / 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 regtest
6
7 import (
8         "log"
9         "testing"
10 )
11
12 // This test passes (TestHoverOnError in definition_test.go) without
13 // the //line directive
14 func TestHoverFailure(t *testing.T) {
15         const mod = `
16 -- go.mod --
17 module mod.com
18 -- a.y --
19 DWIM(main)
20
21 -- main.go --
22 //line a.y:1
23 package main
24
25 func main() {
26         var err error
27         err.Error()
28 }`
29         withOptions(SkipLogs()).run(t, mod, func(t *testing.T, env *Env) {
30                 env.OpenFile("main.go")
31                 content, _ := env.Hover("main.go", env.RegexpSearch("main.go", "Error"))
32                 // without the //line comment content would be non-nil
33                 if content != nil {
34                         t.Fatalf("expected nil hover content for Error")
35                 }
36         })
37 }
38
39 // badPackageDup contains a duplicate definition of the 'a' const.
40 // this is from diagnostics_test.go,
41 const badPackageDup = `
42 -- go.mod --
43 module mod.com
44 -- a.go --
45 package consts
46
47 const a = 1
48 -- b.go --
49 package consts
50 //line gen.go:5
51 const a = 2
52 `
53
54 func TestFailingDiagnosticClearingOnEdit(t *testing.T) {
55         runner.Run(t, badPackageDup, func(t *testing.T, env *Env) {
56                 log.SetFlags(log.Lshortfile)
57                 env.OpenFile("b.go")
58                 env.Await(env.AnyDiagnosticAtCurrentVersion("a.go"))
59                 // no diagnostics for either b.go or 'gen.go', but there should be
60                 env.Await(NoDiagnostics("b.go"))
61
62                 // Fix the error by editing the const name in b.go to `b`.
63                 env.RegexpReplace("b.go", "(a) = 2", "b")
64                 env.Await(
65                         EmptyDiagnostics("a.go"),
66                         // expected, as there have never been any diagnostics for b.go
67                         NoDiagnostics("b.go"),
68                 )
69         })
70 }