Documentation
¶
Overview ¶
Package test provides utilities for testing Fastbelt language implementations.
Create a Fixture from your language's service container, then call Fixture.Parse or Fixture.ParseAll to build documents. Use Doc assertion methods and the generic Find/MustFind functions to inspect results.
Markers ¶
Content strings may embed position markers that are stripped before parsing. Positions are recorded relative to the cleaned text.
- Range marker: <|label:text|> — spans "text"; label identifies the range.
- Range shorthand: <|label|> — equivalent to <|label:label|>.
- Empty range: <|label:|> — zero-length span at the marker position.
- Index marker: <|label> — single position (no text content).
Range markers are tried before index markers when both share the same opening delimiter (the default). Marker delimiters are configurable via TestMarking.
Index ¶
- Variables
- func FindAll[T core.AstNode](d *Doc) []T
- func FindNamedNode[T core.AstNode](d *Doc, name string) (T, bool)
- func FindNode[T core.AstNode](d *Doc) (T, bool)
- func FindNodeAtLabel[T core.AstNode](d *Doc, label string) (T, bool)
- func FindNodeAtLocation[T core.AstNode](d *Doc, location core.TextLocation) (T, bool)
- func FindNodeAtOffset[T core.AstNode](d *Doc, offset int) (T, bool)
- func FindReference[T core.AstNode](d *Doc, label string) (*core.Reference[T], bool)
- func FindReferenceWithText[T core.AstNode](d *Doc, text string) (*core.Reference[T], bool)
- func MustFindNamedNode[T core.AstNode](d *Doc, name string) T
- func MustFindNode[T core.AstNode](d *Doc) T
- func MustFindNodeAtLabel[T core.AstNode](d *Doc, label string) T
- func MustFindNodeAtLocation[T core.AstNode](d *Doc, location core.TextLocation) T
- func MustFindNodeAtOffset[T core.AstNode](d *Doc, offset int) T
- func MustFindReference[T core.AstNode](d *Doc, label string) *core.Reference[T]
- func MustFindReferenceWithText[T core.AstNode](d *Doc, text string) *core.Reference[T]
- type DiagnosticExpectation
- func (d *DiagnosticExpectation) WithCode(code string) *DiagnosticExpectation
- func (d *DiagnosticExpectation) WithMessage(msg string) *DiagnosticExpectation
- func (d *DiagnosticExpectation) WithMessageContaining(substring string) *DiagnosticExpectation
- func (d *DiagnosticExpectation) WithSeverity(severity core.DiagnosticSeverity) *DiagnosticExpectation
- func (d *DiagnosticExpectation) WithSource(source string) *DiagnosticExpectation
- func (d *DiagnosticExpectation) WithTags(tags ...core.DiagnosticTag) *DiagnosticExpectation
- type Doc
- func (d *Doc) AssertDefinition(label string)
- func (d *Doc) AssertDocumentSymbol(label string, expectedName string, expectedKind lsp.SymbolKind) *Doc
- func (d *Doc) AssertFoldingRanges(labels ...string) *Doc
- func (d *Doc) AssertNoDiagnostics() *Doc
- func (d *Doc) AssertNoErrors() *Doc
- func (d *Doc) AssertNoParseErrors() *Doc
- func (d *Doc) AssertReferences(label string)
- func (d *Doc) AssertState(flag core.DocumentState) *Doc
- func (d *Doc) Ctx() context.Context
- func (d *Doc) Diagnostics() []*core.Diagnostic
- func (d *Doc) ExpectDiagnostic(label string) *DiagnosticExpectation
- func (d *Doc) FindSymbolAtLabel(label string) (*lsp.DocumentSymbol, bool)
- func (d *Doc) MarkerRange(label string) (core.TextRange, error)
- func (d *Doc) MustFindSymbolAtLabel(label string) *lsp.DocumentSymbol
- func (d *Doc) Root() core.AstNode
- func (d *Doc) RunRename(label string, newName string) *Doc
- type Fixture
- func (f *Fixture) Ctx() context.Context
- func (f *Fixture) Documents() []*Doc
- func (f *Fixture) Marking() *TestMarking
- func (f *Fixture) Parse(content string) *Doc
- func (f *Fixture) ParseAll(uriContentPairs ...string) []*Doc
- func (f *Fixture) ParseURI(content, uri string) *Doc
- func (f *Fixture) Services() *service.Container
- func (f *Fixture) T() testing.TB
- func (f *Fixture) WithMarking(m *TestMarking) *Fixture
- type IndexMarker
- type RangeMarker
- type TestMarking
Constants ¶
This section is empty.
Variables ¶
var DefaultMarking = &TestMarking{
StartRange: "<|",
EndRange: "|>",
StartIndex: "",
EndIndex: ">",
Delimiter: ":",
}
DefaultMarking is the marker configuration used by New. Also used if a nil *TestMarking is passed to Fixture.WithMarking.
Functions ¶
func FindNamedNode ¶
FindNamedNode returns the first node of type T whose Name() method returns the given name. T must implement core.NamedNode (or have a Name() string method) to find results.
func FindNodeAtLabel ¶
FindNodeAtLabel returns the most specific node of type T at the position of the named range marker (start offset) or index marker.
func FindNodeAtLocation ¶
FindNodeAtLocation returns the most specific (smallest span) node of type T whose text range contains the given line/column position.
func FindNodeAtOffset ¶
FindNodeAtOffset returns the most specific (smallest span) node of type T whose text span contains the given byte offset.
func FindReference ¶
FindReference returns the first reference of type T whose cross-reference text is located at the given label. If the label can be found multiple times, the function returns (nil, false)
func FindReferenceWithText ¶
FindReferenceWithText returns the first reference of type T whose cross-reference text matches the given string exactly.
func MustFindNamedNode ¶
MustFindNamedNode fails the test if no node of type T with the given name is found.
func MustFindNode ¶
MustFindNode fails the test if no node of type T is found in the document tree.
func MustFindNodeAtLabel ¶
MustFindNodeAtLabel fails the test if no node of type T is found at the given label.
func MustFindNodeAtLocation ¶
func MustFindNodeAtLocation[T core.AstNode](d *Doc, location core.TextLocation) T
MustFindNodeAtLocation fails the test if no node of type T contains the given location.
func MustFindNodeAtOffset ¶
MustFindNodeAtOffset fails the test if no node of type T contains the given offset.
func MustFindReference ¶
MustFindReference fails the test if no reference of type T is found at the given label.
Types ¶
type DiagnosticExpectation ¶
type DiagnosticExpectation struct {
Diagnostic *core.Diagnostic
// contains filtered or unexported fields
}
func (*DiagnosticExpectation) WithCode ¶
func (d *DiagnosticExpectation) WithCode(code string) *DiagnosticExpectation
func (*DiagnosticExpectation) WithMessage ¶
func (d *DiagnosticExpectation) WithMessage(msg string) *DiagnosticExpectation
func (*DiagnosticExpectation) WithMessageContaining ¶
func (d *DiagnosticExpectation) WithMessageContaining(substring string) *DiagnosticExpectation
func (*DiagnosticExpectation) WithSeverity ¶
func (d *DiagnosticExpectation) WithSeverity(severity core.DiagnosticSeverity) *DiagnosticExpectation
func (*DiagnosticExpectation) WithSource ¶
func (d *DiagnosticExpectation) WithSource(source string) *DiagnosticExpectation
func (*DiagnosticExpectation) WithTags ¶
func (d *DiagnosticExpectation) WithTags(tags ...core.DiagnosticTag) *DiagnosticExpectation
type Doc ¶
type Doc struct {
Document *core.Document
Ranges []RangeMarker
Indices []IndexMarker
// contains filtered or unexported fields
}
Doc wraps a built core.Document with assertion methods and marker positions. Access the underlying document via the exported Document field.
func (*Doc) AssertDefinition ¶
func (*Doc) AssertDocumentSymbol ¶
func (d *Doc) AssertDocumentSymbol(label string, expectedName string, expectedKind lsp.SymbolKind) *Doc
AssertDocumentSymbol verifies that a document symbol exists with the given name at the marker label. Returns the Doc for chaining.
func (*Doc) AssertFoldingRanges ¶
AssertFoldingRanges verifies that folding ranges exist for all specified marker labels. Returns the Doc for chaining.
func (*Doc) AssertNoDiagnostics ¶
AssertNoDiagnostics fails the test if any diagnostics exist at any severity.
func (*Doc) AssertNoErrors ¶
AssertNoErrors fails the test if any error-severity Diagnostics exist.
func (*Doc) AssertNoParseErrors ¶
AssertNoParseErrors fails the test if any LexerErrors or ParserErrors exist. Diagnostics are not checked.
func (*Doc) AssertReferences ¶
func (*Doc) AssertState ¶
func (d *Doc) AssertState(flag core.DocumentState) *Doc
AssertState fails the test unless the document state includes the given flag.
func (*Doc) Ctx ¶
Ctx returns the context for this document. Pass it to core.Reference.Ref.
func (*Doc) Diagnostics ¶
func (d *Doc) Diagnostics() []*core.Diagnostic
Diagnostics returns all diagnostics collected during validation.
func (*Doc) ExpectDiagnostic ¶
func (d *Doc) ExpectDiagnostic(label string) *DiagnosticExpectation
AssertDiagnostic fails the test unless at least one diagnostic has the given severity and a message containing msgSubstring.
func (*Doc) FindSymbolAtLabel ¶
func (d *Doc) FindSymbolAtLabel(label string) (*lsp.DocumentSymbol, bool)
FindSymbolAtLabel finds a document symbol at the given marker label. Returns the symbol and true if found, or nil and false if not found.
func (*Doc) MustFindSymbolAtLabel ¶
func (d *Doc) MustFindSymbolAtLabel(label string) *lsp.DocumentSymbol
MustFindSymbolAtLabel finds a document symbol at the given marker label. Fails the test if the symbol is not found.
type Fixture ¶
type Fixture struct {
// contains filtered or unexported fields
}
Fixture is the entry point for language tests. Create one per test with New.
func New ¶
New creates a Fixture backed by the given service container. It uses DefaultMarking and context.Background.
func NewWithContext ¶
NewWithContext creates a Fixture with an explicit context.
func (*Fixture) Marking ¶
func (f *Fixture) Marking() *TestMarking
func (*Fixture) Parse ¶
Parse builds a single in-memory document from content. Markers are extracted before parsing. The URI is "inmemory://test<ext>" where <ext> is the first entry in WorkspaceSrv.FileExtensions (e.g. ".statemachine"), or "inmemory://test" if none are configured.
func (*Fixture) ParseAll ¶
ParseAll builds multiple documents together, enabling cross-document reference resolution. Arguments are alternating URI/content pairs: uri1, content1, uri2, content2, ... All documents are registered in the DocumentManager before building. Results are returned in the same order as the pairs.
func (*Fixture) ParseURI ¶
ParseURI builds a single in-memory document with the given URI. Markers are extracted before parsing.
func (*Fixture) WithMarking ¶
func (f *Fixture) WithMarking(m *TestMarking) *Fixture
WithMarking returns a shallow copy of the Fixture using m as the marker configuration.
type IndexMarker ¶
IndexMarker records a labeled position extracted from test content. Offset is a byte offset into the clean text (markers removed).
type RangeMarker ¶
RangeMarker records a labeled span extracted from test content. Start and End are byte offsets into the clean text (markers removed).
type TestMarking ¶
type TestMarking struct {
StartRange string // Opening delimiter for range markers.
EndRange string // Closing delimiter for range markers.
StartIndex string // Opening delimiter for index markers, defaults to the current [TestMarking.StartRange] if empty.
EndIndex string // Closing delimiter for index markers.
Delimiter string // Separator between label and text in range markers.
}
TestMarking configures the delimiter syntax for position markers in test content. See DefaultMarking for the default configuration.