Debian Codegraph @

gopls/internal/test/integration/completion/fixedbugs_test.go

raw symbols SCIP
1 // Copyright 2024 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 completion
6
7 import (
8 "testing"
9
10 . "golang.org/x/tools/gopls/internal/test/integration"
11 )
12
13 func TestPackageCompletionCrash_Issue68169(t *testing.T) {
14 // This test reproduces the scenario of golang/go#68169, a crash in
15 // completion.Selection.Suffix.
16 //
17 // The file content here is extracted from the issue.
18 const files = `
19 -- go.mod --
20 module example.com
21
22 go 1.18
23 -- playdos/play.go --
24 package // comment (to preserve spaces)
25 `
26
27 Run(t, files, func(t *testing.T, env *Env) {
28 env.OpenFile("playdos/play.go")
29 // Previously, this call would crash gopls as it was incorrectly computing
30 // the surrounding completion suffix.
31 completions := env.Completion(env.RegexpSearch("playdos/play.go", "package ()"))
32 if len(completions.Items) == 0 {
33 t.Fatal("Completion() returned empty results")
34 }
35 // Sanity check: we should get package clause completion.
36 if got, want := completions.Items[0].Label, "package playdos"; got != want {
37 t.Errorf("Completion()[0].Label == %s, want %s", got, want)
38 }
39 })
40 }
41
42 func TestFixInitStatementCrash_Issue72026(t *testing.T) {
43 // This test checks that we don't crash when the if condition overflows the
44 // file (as is possible with a malformed struct type).
45
46 const files = `
47 -- go.mod --
48 module example.com
49
50 go 1.18
51 `
52
53 Run(t, files, func(t *testing.T, env *Env) {
54 env.CreateBuffer("p.go", "package p\nfunc _() {\n\tfor i := struct")
55 env.AfterChange()
56 })
57 }