| // Copyright 2020 The Go Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| |
| package regtest |
| |
| import ( |
| "testing" |
| |
| "golang.org/x/tools/internal/lsp/fake" |
| "golang.org/x/tools/internal/lsp/source" |
| ) |
| |
| func TestDisablingCodeLens(t *testing.T) { |
| const workspace = ` |
| -- go.mod -- |
| module codelens.test |
| -- lib.go -- |
| package lib |
| |
| type Number int |
| |
| const ( |
| Zero Number = iota |
| One |
| Two |
| ) |
| |
| //go:generate stringer -type=Number |
| ` |
| tests := []struct { |
| label string |
| enabled map[string]bool |
| wantCodeLens bool |
| }{ |
| { |
| label: "default", |
| wantCodeLens: true, |
| }, |
| { |
| label: "generate disabled", |
| enabled: map[string]bool{source.CommandGenerate: false}, |
| wantCodeLens: false, |
| }, |
| } |
| for _, test := range tests { |
| t.Run(test.label, func(t *testing.T) { |
| runner.Run(t, workspace, func(t *testing.T, env *Env) { |
| env.OpenFile("lib.go") |
| lens := env.CodeLens("lib.go") |
| if gotCodeLens := len(lens) > 0; gotCodeLens != test.wantCodeLens { |
| t.Errorf("got codeLens: %t, want %t", gotCodeLens, test.wantCodeLens) |
| } |
| }, WithEditorConfig(fake.EditorConfig{CodeLens: test.enabled})) |
| }) |
| } |
| } |