srctesting

package
v1.18.1 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2022 License: BSD-2-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package srctesting contains common helpers for unit testing source code analysis and transformation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check

func Check(t *testing.T, fset *token.FileSet, files ...*ast.File) (*types.Info, *types.Package)

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

func Format(t *testing.T, fset *token.FileSet, node any) string

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

func Parse(t *testing.T, fset *token.FileSet, src string) *ast.File

Parse source from the string and return complete AST.

Assumes source file name `test.go`. Fails the test on parsing error.

func ParseFuncDecl

func ParseFuncDecl(t *testing.T, src string) *ast.FuncDecl

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.

Jump to

Keyboard shortcuts

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