tests

package
v0.0.0-...-3999d51 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 15, 2020 License: BSD-3-Clause Imports: 26 Imported by: 0

Documentation

Overview

Package tests exports functionality to be used across a variety of gopls tests.

Index

Constants

View Source
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
)
View Source
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

View Source
var UpdateGolden = flag.Bool("golden", false, "Update golden files")

Functions

func CheckCompletionOrder

func CheckCompletionOrder(want, got []protocol.CompletionItem, strictScores bool) string

func Context

func Context(t testing.TB) context.Context

func CopyFolderToTempDir

func CopyFolderToTempDir(folder string) (string, error)

func DefaultOptions

func DefaultOptions() source.Options

func Diff

func Diff(want, got string) string

func DiffCodeLens

func DiffCodeLens(uri span.URI, want, got []protocol.CodeLens) string

func DiffCompletionItems

func DiffCompletionItems(want, got []protocol.CompletionItem) string

DiffCompletionItems prints the diff between expected and actual completion test results.

func DiffDiagnostics

func DiffDiagnostics(uri span.URI, want, got []*source.Diagnostic) string

DiffDiagnostics prints the diff between expected and actual diagnostics test results.

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 DiffSymbols

func DiffSymbols(t *testing.T, uri span.URI, want, got []protocol.DocumentSymbol) string

DiffSymbols prints the diff between expected and actual symbols test results.

func DiffWorkspaceSymbols

func DiffWorkspaceSymbols(want, got []protocol.SymbolInformation) string

DiffWorkspaceSymbols prints the diff between expected and actual workspace symbols test results.

func EnableAllAnalyzers

func EnableAllAnalyzers(snapshot source.Snapshot, opts *source.Options)

func FilterBuiltins

func FilterBuiltins(src span.Span, items []protocol.CompletionItem) []protocol.CompletionItem

func FilterWorkspaceSymbols

func FilterWorkspaceSymbols(got []protocol.SymbolInformation, dirs map[string]struct{}) []protocol.SymbolInformation

FilterWorkspaceSymbols filters to got contained in the given dirs.

func FormatFolderName

func FormatFolderName(folder string) string

func Run

func Run(t *testing.T, tests Tests, data *Data)

func SpanName

func SpanName(spn span.Span) string

func ToProtocolCompletionItem

func ToProtocolCompletionItem(item source.CompletionItem) protocol.CompletionItem

func ToProtocolCompletionItems

func ToProtocolCompletionItems(items []source.CompletionItem) []protocol.CompletionItem

Types

type CaseSensitiveCompletions

type CaseSensitiveCompletions map[span.Span][]Completion

type CodeLens

type CodeLens map[span.URI][]protocol.CodeLens

type Completion

type Completion struct {
	CompletionItems []token.Pos
}

type CompletionItems

type CompletionItems map[token.Pos]*source.CompletionItem

type CompletionSnippet

type CompletionSnippet struct {
	CompletionItem     token.Pos
	PlainSnippet       string
	PlaceholderSnippet string
}

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
	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
	SuggestedFixes           SuggestedFixes
	RefactorRewrite          RefactorRewriteActions
	Definitions              Definitions
	Implementations          Implementations
	Highlights               Highlights
	References               References
	Renames                  Renames
	PrepareRenames           PrepareRenames
	Symbols                  Symbols

	WorkspaceSymbols              WorkspaceSymbols
	FuzzyWorkspaceSymbols         WorkspaceSymbols
	CaseSensitiveWorkspaceSymbols WorkspaceSymbols
	Signatures                    Signatures
	Links                         Links

	Folder string

	ModfileFlagAvailable bool
	// contains filtered or unexported fields
}

func Load

func Load(t testing.TB, exporter packagestest.Exporter, dir string) []*Data

Load creates the folder structure required when testing with modules. The directory structure of a test needs to look like the example below:

- dir

  • primarymod
  • .go files
  • packages
  • go.mod (optional)
  • modules
  • repoa
  • mod1
  • .go files
  • packages
  • go.mod (optional)
  • mod2
  • repob
  • mod1

All the files that are primarily being tested should be in the primarymod folder, any auxillary packages should be declared in the modules folder. The modules folder requires each module to have the following format: repo/module Then inside each repo/module, there can be any number of packages and files that are needed to test the primarymod.

func (*Data) Golden

func (data *Data) Golden(tag string, target string, update func() ([]byte, error)) []byte

func (*Data) Mapper

func (data *Data) Mapper(uri span.URI) (*protocol.ColumnMapper, error)

type DeepCompletions

type DeepCompletions map[span.Span][]Completion

type Definition

type Definition struct {
	Name      string
	IsType    bool
	OnlyHover bool
	Src, Def  span.Span
}

type Definitions

type Definitions map[span.Span]Definition

type Diagnostics

type Diagnostics map[span.URI][]*source.Diagnostic

type FoldingRanges

type FoldingRanges []span.Span

type Formats

type Formats []span.Span

type FuzzyCompletions

type FuzzyCompletions map[span.Span][]Completion

type Golden

type Golden struct {
	Filename string
	Archive  *txtar.Archive
	Modified bool
}

type Highlights

type Highlights map[span.Span][]span.Span

type Implementations

type Implementations map[span.Span][]span.Span

type Imports

type Imports []span.Span
type Link struct {
	Src          span.Span
	Target       string
	NotePosition token.Position
}
type Links map[span.URI][]Link

type PrepareRenames

type PrepareRenames map[span.Span]*source.PrepareItem

type RankCompletions

type RankCompletions map[span.Span][]Completion

type RefactorRewriteActions

type RefactorRewriteActions map[span.Span]string

type References

type References map[span.Span][]span.Span

type Renames

type Renames map[span.Span]string

type Signatures

type Signatures map[span.Span]*protocol.SignatureHelp

type SuggestedFixes

type SuggestedFixes map[span.Span][]string

type SymbolInformation

type SymbolInformation map[span.Span]protocol.SymbolInformation

type Symbols

type Symbols map[span.URI][]protocol.DocumentSymbol

type SymbolsChildren

type SymbolsChildren map[string][]protocol.DocumentSymbol

type Tests

type Tests interface {
	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)
	SuggestedFix(*testing.T, span.Span, []string)
	Definition(*testing.T, span.Span, Definition)
	Implementation(*testing.T, span.Span, []span.Span)
	Highlight(*testing.T, span.Span, []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, string, []protocol.SymbolInformation, map[string]struct{})
	FuzzyWorkspaceSymbols(*testing.T, string, []protocol.SymbolInformation, map[string]struct{})
	CaseSensitiveWorkspaceSymbols(*testing.T, string, []protocol.SymbolInformation, map[string]struct{})
	SignatureHelp(*testing.T, span.Span, *protocol.SignatureHelp)
	Link(*testing.T, span.URI, []Link)
	RefactorRewrite(*testing.T, span.Span, string)
}

type UnimportedCompletions

type UnimportedCompletions map[span.Span][]Completion

type WorkspaceSymbols

type WorkspaceSymbols map[string][]protocol.SymbolInformation

type WorkspaceSymbolsTestType

type WorkspaceSymbolsTestType int

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL