Documentation ¶
Overview ¶
Package tests exports functionality to be used across a variety of gopls tests.
Index ¶
- Constants
- Variables
- func CheckCompletionOrder(want, got []protocol.CompletionItem, strictScores bool) string
- func CheckSameMarkdown(t *testing.T, got, want string)
- func CompareDiagnostics(t *testing.T, uri span.URI, want, got []*source.Diagnostic)
- func Context(t testing.TB) context.Context
- func CopyFolderToTempDir(folder string) (string, error)
- func DefaultOptions(o *source.Options)
- func DiffCallHierarchyItems(gotCalls []protocol.CallHierarchyItem, ...) string
- func DiffCodeLens(uri span.URI, want, got []protocol.CodeLens) string
- func DiffCompletionItems(want, got []protocol.CompletionItem) string
- func DiffLinks(mapper *protocol.ColumnMapper, wantLinks []Link, ...) string
- func DiffSignatures(spn span.Span, want, got *protocol.SignatureHelp) string
- func DiffSnippets(want string, got *protocol.CompletionItem) string
- func EnableAllAnalyzers(view source.View, opts *source.Options)
- func EnableAllInlayHints(view source.View, opts *source.Options)
- func FilterBuiltins(src span.Span, items []protocol.CompletionItem) []protocol.CompletionItem
- func FindItem(list []protocol.CompletionItem, want completion.CompletionItem) *protocol.CompletionItem
- func Normalize(s string, normalizers []Normalizer) string
- func NormalizeAny(input string) string
- func NormalizePrefix(s string, normalizers []Normalizer) string
- func Run(t *testing.T, tests Tests, data *Data)
- func RunTests(t *testing.T, dataDir string, includeMultiModule bool, ...)
- func SpanName(spn span.Span) string
- func StripSubscripts(s string) string
- func ToProtocolCompletionItem(item completion.CompletionItem) protocol.CompletionItem
- func ToProtocolCompletionItems(items []completion.CompletionItem) []protocol.CompletionItem
- func WorkspaceSymbolsString(ctx context.Context, data *Data, queryURI span.URI, ...) (string, error)
- func WorkspaceSymbolsTestTypeToMatcher(typ WorkspaceSymbolsTestType) source.SymbolMatcher
- type AddImport
- type CallHierarchy
- type CallHierarchyResult
- type CaseSensitiveCompletions
- type CodeLens
- type Completion
- type CompletionItems
- type CompletionSnippet
- type CompletionSnippets
- type CompletionTestType
- type Completions
- type Data
- type DeepCompletions
- type Definition
- type Definitions
- type Diagnostics
- type FoldingRanges
- type Formats
- type FunctionExtractions
- type FuzzyCompletions
- type Golden
- type Highlights
- type Hovers
- type Implementations
- type Imports
- type InlayHints
- type Link
- type Links
- type MethodExtractions
- type Normalizer
- type PrepareRenames
- type RankCompletions
- type References
- type Renames
- type SemanticTokens
- type Signatures
- type SuggestedFix
- type SuggestedFixes
- type Symbols
- type Tests
- type UnimportedCompletions
- type WorkspaceSymbols
- type WorkspaceSymbolsTestType
Constants ¶
const ( // Default runs the standard completion tests. CompletionDefault = CompletionTestType(iota) // Unimported tests the autocompletion of unimported packages. CompletionUnimported // Deep tests deep completion. CompletionDeep // Fuzzy tests deep completion and fuzzy matching. CompletionFuzzy // CaseSensitive tests case sensitive completion. CompletionCaseSensitive // CompletionRank candidates in test must be valid and in the right relative order. CompletionRank )
const ( // Default runs the standard workspace symbols tests. WorkspaceSymbolsDefault = WorkspaceSymbolsTestType(iota) // Fuzzy tests workspace symbols with fuzzy matching. WorkspaceSymbolsFuzzy // CaseSensitive tests workspace symbols with case sensitive. WorkspaceSymbolsCaseSensitive )
Variables ¶
var UpdateGolden = flag.Bool("golden", false, "Update golden files")
Functions ¶
func CheckCompletionOrder ¶
func CheckCompletionOrder(want, got []protocol.CompletionItem, strictScores bool) string
func CheckSameMarkdown ¶
The markdown in the golden files matches the converter in comment.go, but for go1.19 and later the conversion is done using go/doc/comment. Compared to the newer version, the older version has extra escapes, and treats code blocks slightly differently.
func CompareDiagnostics ¶
CompareDiagnostics reports testing errors to t when the diagnostic set got does not match want. If the sole expectation has source "no_diagnostics", the test expects that no diagnostics were received for the given document.
func CopyFolderToTempDir ¶
func DefaultOptions ¶
func DiffCallHierarchyItems ¶
func DiffCallHierarchyItems(gotCalls []protocol.CallHierarchyItem, expectedCalls []protocol.CallHierarchyItem) string
DiffCallHierarchyItems returns the diff between expected and actual call locations for incoming/outgoing call hierarchies
func DiffCompletionItems ¶
func DiffCompletionItems(want, got []protocol.CompletionItem) string
DiffCompletionItems prints the diff between expected and actual completion test results.
func DiffLinks ¶
func DiffLinks(mapper *protocol.ColumnMapper, wantLinks []Link, gotLinks []protocol.DocumentLink) string
DiffLinks takes the links we got and checks if they are located within the source or a Note. If the link is within a Note, the link is removed. Returns an diff comment if there are differences and empty string if no diffs.
func DiffSignatures ¶
func DiffSignatures(spn span.Span, want, got *protocol.SignatureHelp) string
func DiffSnippets ¶
func DiffSnippets(want string, got *protocol.CompletionItem) string
func FilterBuiltins ¶
func FilterBuiltins(src span.Span, items []protocol.CompletionItem) []protocol.CompletionItem
func FindItem ¶
func FindItem(list []protocol.CompletionItem, want completion.CompletionItem) *protocol.CompletionItem
func Normalize ¶
func Normalize(s string, normalizers []Normalizer) string
Normalize replaces all paths present in s with just the fragment portion this is used to make golden files not depend on the temporary paths of the files
func NormalizeAny ¶
NormalizeAny replaces occurrences of interface{} in input with any.
In Go 1.18, standard library functions were changed to use the 'any' alias in place of interface{}, which affects their type string.
func NormalizePrefix ¶
func NormalizePrefix(s string, normalizers []Normalizer) string
NormalizePrefix normalizes a single path at the front of the input string.
func SpanName ¶
TODO(golang/go#54845): improve the formatting here to match standard line:column position formatting.
func StripSubscripts ¶
StripSubscripts removes type parameter id subscripts.
TODO(rfindley): remove this function once subscripts are removed from the type parameter type string.
func ToProtocolCompletionItem ¶
func ToProtocolCompletionItem(item completion.CompletionItem) protocol.CompletionItem
func ToProtocolCompletionItems ¶
func ToProtocolCompletionItems(items []completion.CompletionItem) []protocol.CompletionItem
func WorkspaceSymbolsString ¶
func WorkspaceSymbolsTestTypeToMatcher ¶
func WorkspaceSymbolsTestTypeToMatcher(typ WorkspaceSymbolsTestType) source.SymbolMatcher
Types ¶
type CallHierarchy ¶
type CallHierarchy = map[span.Span]*CallHierarchyResult
These type names apparently avoid the need to repeat the type in the field name and the make() expression.
type CallHierarchyResult ¶
type CallHierarchyResult struct {
IncomingCalls, OutgoingCalls []protocol.CallHierarchyItem
}
type CaseSensitiveCompletions ¶
type CaseSensitiveCompletions = map[span.Span][]Completion
type Completion ¶
type CompletionItems ¶
type CompletionItems = map[token.Pos]*completion.CompletionItem
type CompletionSnippet ¶
type CompletionSnippets ¶
type CompletionSnippets = map[span.Span][]CompletionSnippet
type CompletionTestType ¶
type CompletionTestType int
type Completions ¶
type Completions = map[span.Span][]Completion
type Data ¶
type Data struct { Config packages.Config Exported *packagestest.Exported CallHierarchy CallHierarchy CodeLens CodeLens Diagnostics Diagnostics CompletionItems CompletionItems Completions Completions CompletionSnippets CompletionSnippets UnimportedCompletions UnimportedCompletions DeepCompletions DeepCompletions FuzzyCompletions FuzzyCompletions CaseSensitiveCompletions CaseSensitiveCompletions RankCompletions RankCompletions FoldingRanges FoldingRanges Formats Formats Imports Imports SemanticTokens SemanticTokens SuggestedFixes SuggestedFixes FunctionExtractions FunctionExtractions MethodExtractions MethodExtractions Definitions Definitions Implementations Implementations Highlights Highlights References References Renames Renames InlayHints InlayHints PrepareRenames PrepareRenames Symbols Symbols WorkspaceSymbols WorkspaceSymbols Signatures Signatures Links Links AddImport AddImport Hovers Hovers ModfileFlagAvailable bool // contains filtered or unexported fields }
type DeepCompletions ¶
type DeepCompletions = map[span.Span][]Completion
type Definition ¶
type Definitions ¶
type Definitions = map[span.Span]Definition
type Diagnostics ¶
type Diagnostics = map[span.URI][]*source.Diagnostic
type FoldingRanges ¶
type FuzzyCompletions ¶
type FuzzyCompletions = map[span.Span][]Completion
type InlayHints ¶
type Normalizer ¶
type Normalizer struct {
// contains filtered or unexported fields
}
func CollectNormalizers ¶
func CollectNormalizers(exported *packagestest.Exported) []Normalizer
type PrepareRenames ¶
type PrepareRenames = map[span.Span]*source.PrepareItem
type RankCompletions ¶
type RankCompletions = map[span.Span][]Completion
type SemanticTokens ¶
type Signatures ¶
type Signatures = map[span.Span]*protocol.SignatureHelp
type SuggestedFix ¶
type SuggestedFix struct {
ActionKind, Title string
}
type SuggestedFixes ¶
type SuggestedFixes = map[span.Span][]SuggestedFix
type Tests ¶
type Tests interface { CallHierarchy(*testing.T, span.Span, *CallHierarchyResult) CodeLens(*testing.T, span.URI, []protocol.CodeLens) Diagnostics(*testing.T, span.URI, []*source.Diagnostic) Completion(*testing.T, span.Span, Completion, CompletionItems) CompletionSnippet(*testing.T, span.Span, CompletionSnippet, bool, CompletionItems) UnimportedCompletion(*testing.T, span.Span, Completion, CompletionItems) DeepCompletion(*testing.T, span.Span, Completion, CompletionItems) FuzzyCompletion(*testing.T, span.Span, Completion, CompletionItems) CaseSensitiveCompletion(*testing.T, span.Span, Completion, CompletionItems) RankCompletion(*testing.T, span.Span, Completion, CompletionItems) FoldingRanges(*testing.T, span.Span) Format(*testing.T, span.Span) Import(*testing.T, span.Span) SemanticTokens(*testing.T, span.Span) SuggestedFix(*testing.T, span.Span, []SuggestedFix, int) FunctionExtraction(*testing.T, span.Span, span.Span) MethodExtraction(*testing.T, span.Span, span.Span) Definition(*testing.T, span.Span, Definition) Implementation(*testing.T, span.Span, []span.Span) Highlight(*testing.T, span.Span, []span.Span) InlayHints(*testing.T, span.Span) References(*testing.T, span.Span, []span.Span) Rename(*testing.T, span.Span, string) PrepareRename(*testing.T, span.Span, *source.PrepareItem) Symbols(*testing.T, span.URI, []protocol.DocumentSymbol) WorkspaceSymbols(*testing.T, span.URI, string, WorkspaceSymbolsTestType) SignatureHelp(*testing.T, span.Span, *protocol.SignatureHelp) Link(*testing.T, span.URI, []Link) AddImport(*testing.T, span.URI, string) Hover(*testing.T, span.Span, string) }
TODO(adonovan): there are multiple implementations of this (undocumented) interface, each of which must implement similar semantics. For example: - *runner in ../cmd/test/check.go - *runner in ../source/source_test.go - *runner in ../lsp_test.go Can we avoid this duplication?
type UnimportedCompletions ¶
type UnimportedCompletions = map[span.Span][]Completion
type WorkspaceSymbols ¶
type WorkspaceSymbols = map[WorkspaceSymbolsTestType]map[span.URI][]string
type WorkspaceSymbolsTestType ¶
type WorkspaceSymbolsTestType int