goparser

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package goparse contains logic for parsing Go files. Specifically it parses source and test files into domain models for generating tests.

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyFile = errors.New("file is empty")

ErrEmptyFile is returned when attempting to parse an empty Go source file.

Functions

func QualifyTypes added in v1.10.0

func QualifyTypes(fn *models.Function, pkgName string, localTypes map[string]bool) (reason string)

QualifyTypes prepares fn for a test in the external <pkg>_test package.

It rewrites the parameter, result and receiver field types so that types declared in the package under test (localTypes) are referenced through pkgName, e.g. "[]*Bar" becomes "[]*pkg.Bar". The receiver's own type is left untouched because it also names the generated test; templates qualify it with the ReceiverType helper. Unexported receiver fields are dropped, since an external package cannot set them.

It returns a non-empty reason when fn cannot be tested from an external package: its receiver type, or a type in its signature, is unexported.

Types

type Parser

type Parser struct {
	// The importer to resolve packages from import paths.
	Importer types.Importer
}

Parser parses Go source files into domain models for test generation.

func (*Parser) Parse

func (p *Parser) Parse(srcPath string, files []models.Path) (*Result, error)

Parse parses a given Go file at srcPath, along any files that share the same package, into a domain model for generating tests.

type Result

type Result struct {
	// The package name and imports of a Go file.
	Header *models.Header
	// All the functions and methods in a Go file.
	Funcs []*models.Function
	// Names of the types declared in the file's package.
	TypeNames map[string]bool
}

Result represents a parsed Go file containing the header information and function signatures.

Jump to

Keyboard shortcuts

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