Debian Codegraph @

gopls/internal/analysis/fillstruct/fillstruct_test.go

raw symbols SCIP
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 fillstruct_test
6
7 import (
8 "fmt"
9 "testing"
10
11 "golang.org/x/tools/go/analysis"
12 "golang.org/x/tools/go/analysis/analysistest"
13 "golang.org/x/tools/go/analysis/passes/inspect"
14 "golang.org/x/tools/go/ast/inspector"
15 "golang.org/x/tools/gopls/internal/analysis/fillstruct"
16 "golang.org/x/tools/internal/testenv"
17 )
18
19 // analyzer allows us to test the fillstruct code action using the analysistest
20 // harness. (fillstruct used to be a gopls analyzer.)
21 var analyzer = &analysis.Analyzer{
22 Name: "fillstruct",
23 Doc: "test only",
24 Requires: []*analysis.Analyzer{inspect.Analyzer},
25 Run: func(pass *analysis.Pass) (any, error) {
26 inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
27
28 for _, f := range pass.Files {
29 curFile, ok := inspect.Root().FindNode(f)
30 if !ok {
31 return nil, fmt.Errorf("can't find file %s", f.Name.Name)
32 }
33 for _, diag := range fillstruct.Diagnose(curFile, f.Pos(), f.End(), pass.Pkg, pass.TypesInfo) {
34 pass.Report(diag)
35 }
36 }
37 return nil, nil
38 },
39 URL: "https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/fillstruct",
40 RunDespiteErrors: true,
41 }
42
43 func Test(t *testing.T) {
44 testdata := analysistest.TestData()
45 analysistest.Run(t, testdata, analyzer, "a", "typeparams")
46 }
47
48 func TestIssue78553(t *testing.T) {
49 testenv.NeedsGo1Point(t, 27)
50 testdata := analysistest.TestData()
51 analysistest.Run(t, testdata, analyzer, "issue78553")
52 }