golang.org/x/tools/gopls@v0.15.3/internal/analysis/fillstruct/fillstruct_test.go (about)

     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  	"go/token"
     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  )
    17  
    18  // analyzer allows us to test the fillstruct code action using the analysistest
    19  // harness. (fillstruct used to be a gopls analyzer.)
    20  var analyzer = &analysis.Analyzer{
    21  	Name:     "fillstruct",
    22  	Doc:      "test only",
    23  	Requires: []*analysis.Analyzer{inspect.Analyzer},
    24  	Run: func(pass *analysis.Pass) (any, error) {
    25  		inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
    26  		for _, d := range fillstruct.Diagnose(inspect, token.NoPos, token.NoPos, pass.Pkg, pass.TypesInfo) {
    27  			pass.Report(d)
    28  		}
    29  		return nil, nil
    30  	},
    31  	URL:              "https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/fillstruct",
    32  	RunDespiteErrors: true,
    33  }
    34  
    35  func Test(t *testing.T) {
    36  	testdata := analysistest.TestData()
    37  	analysistest.Run(t, testdata, analyzer, "a", "typeparams")
    38  }