.gitignore added
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools / gopls@v0.6.9 / internal / regtest / misc / shared_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 const sharedProgram = `
14 -- go.mod --
15 module mod
16
17 go 1.12
18 -- main.go --
19 package main
20
21 import "fmt"
22
23 func main() {
24         fmt.Println("Hello World.")
25 }`
26
27 func runShared(t *testing.T, testFunc func(env1 *Env, env2 *Env)) {
28         // Only run these tests in forwarded modes.
29         modes := DefaultModes() & (Forwarded | SeparateProcess)
30         WithOptions(Modes(modes)).Run(t, sharedProgram, func(t *testing.T, env1 *Env) {
31                 // Create a second test session connected to the same workspace and server
32                 // as the first.
33                 env2 := NewEnv(env1.Ctx, t, env1.Sandbox, env1.Server, env1.Editor.Config, true)
34                 testFunc(env1, env2)
35         })
36 }
37
38 func TestSimultaneousEdits(t *testing.T) {
39         runShared(t, func(env1 *Env, env2 *Env) {
40                 // In editor #1, break fmt.Println as before.
41                 env1.OpenFile("main.go")
42                 env1.RegexpReplace("main.go", "Printl(n)", "")
43                 // In editor #2 remove the closing brace.
44                 env2.OpenFile("main.go")
45                 env2.RegexpReplace("main.go", "\\)\n(})", "")
46
47                 // Now check that we got different diagnostics in each environment.
48                 env1.Await(env1.DiagnosticAtRegexp("main.go", "Printl"))
49                 env2.Await(env2.DiagnosticAtRegexp("main.go", "$"))
50         })
51 }
52
53 func TestShutdown(t *testing.T) {
54         runShared(t, func(env1 *Env, env2 *Env) {
55                 env1.CloseEditor()
56                 // Now make an edit in editor #2 to trigger diagnostics.
57                 env2.OpenFile("main.go")
58                 env2.RegexpReplace("main.go", "\\)\n(})", "")
59                 env2.Await(env2.DiagnosticAtRegexp("main.go", "$"))
60         })
61 }