model

package
v2.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

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 New

func New() *AssertionPackage

New empty AssertionPackage.

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

func (d Document) HasGenerics() bool

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

func (f Function) FailMsg(args ...string) string

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

func (f Function) GenericCallName(suffixes ...string) string

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

func (f Function) GenericName(suffixes ...string) string

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

func (f Function) GenericSuffix() string

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

func (f Function) HasSuccessTest() bool

func (Function) HasTest

func (f Function) HasTest() bool

type FunctionWithContext

type FunctionWithContext struct {
	Function

	Package        string
	Receiver       string
	EnableFormat   bool
	EnableForward  bool
	EnableGenerics bool
	EnableExamples bool
}

type Functions added in v2.3.0

type Functions []Function

func (Functions) Scope added in v2.3.0

func (f Functions) Scope(scope ScopeKind, ctx *AssertionPackage) (iter.Seq[Function], error)

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

type ImportMap map[string]string

ImportMap represents the imports for the analyzed package.

func (ImportMap) HasImports

func (m ImportMap) HasImports() bool

type IndexEntry

type IndexEntry struct {
	Name        string
	Title       string
	Description string
	Link        string
	RefCount    int
	Weight      int
}

type KindDoc

type KindDoc uint8
const (
	KindPage KindDoc = iota
	KindIndex
	KindFolder
)

type Parameter

type Parameter struct {
	Name       string
	GoType     string
	Selector   string
	IsVariadic bool
	IsGeneric  bool
}

Parameter represents a function parameter or return value.

type Parameters

type Parameters []Parameter

type Renderable added in v2.3.0

type Renderable interface {
	Render() string
}

type ScopeKind added in v2.3.0

type ScopeKind string
const (
	ScopeKindWithGenerics    ScopeKind = "include-generics"
	ScopeKindWithoutGenerics ScopeKind = "exclude-generics"
	ScopeKindHelpers         ScopeKind = "only-helpers"
)

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) IsFailure added in v2.3.0

func (t Test) IsFailure() bool

func (Test) IsKindRequire added in v2.3.0

func (t Test) IsKindRequire() bool

func (Test) IsPanic added in v2.3.0

func (t Test) IsPanic() bool

func (Test) IsSuccess added in v2.3.0

func (t Test) IsSuccess() bool

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.

type TypeParam added in v2.2.0

type TypeParam struct {
	Name       string // type parameter name (e.g., "B")
	Constraint string // constraint type (e.g., "Boolean", "cmp.Ordered")
}

TypeParam represents a type parameter in a generic function.

Jump to

Keyboard shortcuts

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