Documentation ¶
Overview ¶
Package srctesting contains common helpers for unit testing source code analysis and transformation.
Index ¶
- func Check(t *testing.T, fset *token.FileSet, files ...*ast.File) (*types.Info, *types.Package)
- func Format(t *testing.T, fset *token.FileSet, node any) string
- func Parse(t *testing.T, fset *token.FileSet, src string) *ast.File
- func ParseDecl(t *testing.T, src string) ast.Decl
- func ParseFuncDecl(t *testing.T, src string) *ast.FuncDecl
- func ParseSpec(t *testing.T, src string) ast.Spec
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Check ¶
Check type correctness of the provided AST.
Assumes "test" package import path. Fails the test if type checking fails. Provided AST is expected not to have any imports.
func Format ¶
Format AST node into a string.
The node type must be *ast.File, *printer.CommentedNode, []ast.Decl, []ast.Stmt, or assignment-compatible to ast.Expr, ast.Decl, ast.Spec, or ast.Stmt.
func Parse ¶
Parse source from the string and return complete AST.
Assumes source file name `test.go`. Fails the test on parsing error.
func ParseDecl ¶
ParseDecl parses source with a single declaration and returns that declaration AST.
Fails the test if there isn't exactly one declaration in the source.
func ParseFuncDecl ¶
ParseFuncDecl parses source with a single function defined and returns the function AST.
Fails the test if there isn't exactly one function declared in the source.
Types ¶
This section is empty.