Documentation
¶
Index ¶
- type AssertionPackage
- type CommentTag
- type Document
- type Documentation
- type ExtraComment
- type ExtraPackages
- type Function
- type FunctionWithContext
- type Functions
- type Ident
- type ImportMap
- type IndexEntry
- type KindDoc
- type Parameter
- type Parameters
- type Renderable
- type ScopeKind
- type Test
- type TestData
- type TestExpectedOutcome
- type TestValue
- type TypeParam
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AssertionPackage ¶
type AssertionPackage struct {
Tool string
Header string
Package string
DocString string
Copyright string
Receiver string
Imports ImportMap
EnableFormat bool
EnableForward bool
EnableGenerics bool
EnableExamples bool
RunnableExamples bool
Functions Functions
Types []Ident
Consts []Ident
Vars []Ident
// extraneous information when scanning in collectDoc mode
ExtraComments []ExtraComment
Context *Document
// Overridable context for test generation
TestDataPath string
TestPackage bool
}
AssertionPackage describes the internal/assertions package.
func (*AssertionPackage) Clone ¶
func (a *AssertionPackage) Clone() *AssertionPackage
func (*AssertionPackage) HasHelpers ¶
func (a *AssertionPackage) HasHelpers() (ok bool)
func (*AssertionPackage) Names ¶ added in v2.3.0
func (a *AssertionPackage) Names() iter.Seq[string]
func (*AssertionPackage) WithTestPackage ¶ added in v2.3.0
func (a *AssertionPackage) WithTestPackage() *AssertionPackage
type CommentTag ¶
type CommentTag uint8
const ( CommentTagNone CommentTag = iota CommentTagDomain CommentTagMaintainer CommentTagMention CommentTagNote CommentTagDomainDescription )
func (CommentTag) String ¶ added in v2.3.0
func (t CommentTag) String() string
String representation of a comment tag, mostly useful for debugging purpose.
type Document ¶
type Document struct {
Title string
Domain string
Description string
Path string // document folder, relative to its parent if any
File string // document name, e.g. _index.md, string.md
GitHubURL string
PkgGoDevURL string
Kind KindDoc // page or index or folder
Documents []Document // for folders, their content [Document]
Index []IndexEntry // for indexes, their entry list
Package *AssertionPackage // subset of the package that pertains to this document
ExtraPackages ExtraPackages
RefCount int
Weight int
}
func (Document) HasGenerics ¶ added in v2.2.0
type Documentation ¶
type Documentation struct {
Package *AssertionPackage // the complete source package being documented
Documents []Document // Documents is a collection of markdown pages or folders
}
func NewDocumentation ¶
func NewDocumentation() *Documentation
NewDocumentation builds an empty Documentation.
func (*Documentation) Merge ¶
func (d *Documentation) Merge(doc Documentation)
type ExtraComment ¶
type ExtraComment struct {
Tag CommentTag
Key string
Text string
}
func (ExtraComment) IsTagMaintainer ¶ added in v2.3.0
func (c ExtraComment) IsTagMaintainer() bool
func (ExtraComment) IsTagMention ¶ added in v2.3.0
func (c ExtraComment) IsTagMention() bool
func (ExtraComment) IsTagNote ¶ added in v2.3.0
func (c ExtraComment) IsTagNote() bool
type ExtraPackages ¶
type ExtraPackages []*AssertionPackage
func (ExtraPackages) LookupFunction ¶
func (pkgs ExtraPackages) LookupFunction(name string) []FunctionWithContext
type Function ¶
type Function struct {
TestData
ID string
Name string
SourcePackage string
TargetPackage string
DocString string
UseMock string
Params Parameters
AllParams Parameters
Returns Parameters
TypeParams []TypeParam
IsGeneric bool
IsHelper bool
IsDeprecated bool
IsConstructor bool
Tests []Test
// extraneous information when scanning in collectDoc mode
Domain string
SourceLink *token.Position
ExtraComments []ExtraComment
Examples []Renderable // testable examples as a collection of [Renderable] examples
Context *Document
}
Function represents an assertion function extracted from the source package.
func (Function) FailMsg ¶ added in v2.3.0
FailMsg returns an error message to report in tests.
If the function should use the "mockFailNowT" mock, we should report that testing.FailNow should be called, not just marking the test as failed.
An optional suffix may be used to apply to the function name and express a formatted variant.
If to arguments are passed, the first one is interpreted as a prefix, followed by "." and the second as a suffix. Further passed args are ignored.
func (Function) GenericCallName ¶ added in v2.2.0
GenericCallName renders the function name with explicit type parameters. This is used when forwarding type parameters, as all type parameters may not be always inferred from the arguments.
func (Function) GenericName ¶ added in v2.2.0
GenericName renders the function name with one or more suffixes, accounting for any type parameter for generic functions.
func (Function) GenericSuffix ¶ added in v2.3.0
GenericSuffix provides a type parameter instantiation for methods which cannot infer type parameters from their arguments. At this moment, only one such case exists: OfTypeT().
func (Function) HasSuccessTest ¶
type FunctionWithContext ¶
type Ident ¶
type Ident struct {
ID string
Name string
SourcePackage string
TargetPackage string
DocString string
IsAlias bool
IsDeprecated bool
Function *Function // for function types (or vars)
// extraneous information when scanning in collectDoc mode
Domain string
SourceLink *token.Position
ExtraComments []ExtraComment
Examples []Renderable // testable examples as a collection of [Renderable] examples
}
Ident represents an exported identifier (type, constant, or variable) from the source package.
type ImportMap ¶
ImportMap represents the imports for the analyzed package.
func (ImportMap) HasImports ¶
type IndexEntry ¶
type Parameters ¶
type Parameters []Parameter
type Renderable ¶ added in v2.3.0
type Renderable interface {
Render() string
}
type Test ¶
type Test struct {
TestedValues []TestValue // Parsed test value expressions
TestedValue string // Original raw string, kept for auditability
ExpectedOutcome TestExpectedOutcome // Expected test outcome (success/failure/panic)
AssertionMessage string // Optional assertion message for panic tests
IsFirst bool
Pkg string
}
Test captures test values to use with generated tests.
Test values are parsed as Go expressions and stored with their AST representation.
func (Test) IsKindRequire ¶ added in v2.3.0
type TestData ¶ added in v2.3.0
type TestData struct {
TestCall string
TestMock string
TestErrorPrefix string
TestMockFailure string
TestPanicWrapper string
TestMsg string
}
TestData holds test variabilization parameters for templates.
type TestExpectedOutcome ¶
type TestExpectedOutcome uint8
const ( TestNone TestExpectedOutcome = iota TestSuccess TestFailure TestPanic )
type TestValue ¶
type TestValue struct {
Raw string // Original string from doc comment
Expr ast.Expr // Parsed Go expression (nil if parse failed)
Error error // Parse error if any
}
TestValue represents a single parsed test value expression.
It stores both the original string (for debugging/audit) and the parsed AST.