Documentation ¶
Index ¶
- Constants
- Variables
- func Assert(condition bool, msg string)
- func CopyFile(path string, out io.Writer) error
- func CreateBoolIdent(v bool) *ast.Ident
- func CreateMemorizedFuncCall(ctx *Context, filename string, line int, pos token.Pos, n *ast.CallExpr, ...) *ast.CallExpr
- func CreatePosValuePairExpr(ctx *Context, ps []printExpr) []ast.Expr
- func CreateRawStringLit(s string) ast.Expr
- func CreateReflectBoolExpr(ctx *Context, rv ast.Expr) *ast.CallExpr
- func CreateReflectInterfaceExpr(ctx *Context, rv ast.Expr) *ast.CallExpr
- func CreateReflectTypeExprFromTypeExpr(ctx *Context, t ast.Expr) ast.Expr
- func CreateReflectTypeOfExpr(ctx *Context, v ast.Expr) *ast.CallExpr
- func CreateReflectValueOfExpr(ctx *Context, v ast.Expr) *ast.CallExpr
- func CreateUntypedCallExprFromBuiltinCallExpr(ctx *Context, n *ast.CallExpr) *ast.CallExpr
- func CreateUntypedExprFromBinaryExpr(ctx *Context, n *ast.BinaryExpr) ast.Expr
- func CreateUntypedExprFromUnaryExpr(ctx *Context, n *ast.UnaryExpr) ast.Expr
- func DeterminantExprOfIsTypeConversion(e ast.Expr) ast.Expr
- func DropGopwtEmpower(a *ast.File) (dropped bool)
- func ExtractPrintExprs(ctx *Context, typesInfo *types.Info, filename string, line int, ...) []printExpr
- func FindDeps(pkg *build.Package) ([]string, error)
- func FindImportPathByPath(path string) (string, error)
- func FindPathByImportPath(importPath string) (string, error)
- func FindVendor(fpath string, nest int) (string, bool)
- func FprintCode(out io.Writer, n ast.Node) error
- func GetAssertImport(a *ast.File) *ast.ImportSpec
- func HandleGlobalOrLocalImportPath(globalOrLocalImportPath string) (importpath, fpath string, err error)
- func InspectAssert(ctx *Context, root ast.Node, fn func(*ast.CallExpr))
- func IsAssert(x *ast.Ident, c *ast.CallExpr) bool
- func IsBuildableFileName(name string) bool
- func IsBuildableFileSet(s *token.FileSet) bool
- func IsBuiltinFunc(n *ast.CallExpr) bool
- func IsEqualExpr(expr ast.Expr) bool
- func IsGoFile(f os.FileInfo) bool
- func IsGoFileName(name string) bool
- func IsMapType(n ast.Node) bool
- func IsRawStringLit(n *ast.BasicLit) bool
- func IsReflectDeepEqual(expr ast.Expr) bool
- func IsTestGoFile(f os.FileInfo) bool
- func IsTestGoFileName(name string) bool
- func IsTestdata(fpath string) bool
- func IsTypeConversion(info *types.Info, e *ast.CallExpr) bool
- func Must(err error)
- func MustParse(file *ast.File, err error) *ast.File
- func NewPrintExpr(pos token.Pos, newExpr ast.Expr, originalExpr string) printExpr
- func NormalizeFile(file *ast.File, in *os.File, out io.Writer) error
- func ReplaceAllRawStringLitByStringLit(root ast.Node)
- func ReplaceBinaryExpr(parent ast.Node, oldExpr *ast.BinaryExpr, newExpr ast.Expr)
- func ReplaceUnaryExpr(parent ast.Node, oldExpr *ast.UnaryExpr, newExpr ast.Expr)
- func ResultPosOf(n ast.Expr) token.Pos
- func RetrieveImportpathFromVendorDir(path string) (string, bool)
- func RewriteAssert(ctx *Context, typesInfo *types.Info, position token.Position, n *ast.CallExpr)
- func RewriteFile(pkgCtx *PackageContext, file *GoFile, ctx *Context, typesInfo *types.Info, ...) error
- func SprintCode(n ast.Node) string
- func Translate(gopath string, importpath, fpath string) error
- type Context
- type File
- type GoFile
- type PackageContext
Constants ¶
const SeekStart = os.SEEK_SET
Variables ¶
var ( Testdata = "testdata" TermWidth = 0 WorkingDir = "" Verbose = false )
Functions ¶
func CreateBoolIdent ¶
func CreateMemorizedFuncCall ¶
func CreateMemorizedFuncCall(ctx *Context, filename string, line int, pos token.Pos, n *ast.CallExpr, returnType string) *ast.CallExpr
CreateMemorizedFuncCall creates memorized *ast.CallExpr. f(a, b) -> translatedassert.FRVInterface(translatedassert.MFCall(filename, line, pos, f, translatedassert.RVOf(a), translatedassert.RVOf(b)))
func CreatePosValuePairExpr ¶
func CreateRawStringLit ¶
CreateRawStringLit creates raw string literal(ast.Expr) from string. VALUE:"foo" ---> AST:`foo` VALUE:"foo`bar" ---> AST:`foo` + "`" + `bar` (because we can't escape ` in “)
func CreateReflectTypeExprFromTypeExpr ¶
CreateReflectTypeExprFromTypeExpr create ast of reflect.Type from ast of type.
func CreateUntypedExprFromBinaryExpr ¶
func CreateUntypedExprFromBinaryExpr(ctx *Context, n *ast.BinaryExpr) ast.Expr
CreateUntypedExprFromBinaryExpr creates untyped operator-func(translatedassert.Op*()) from BinaryExpr if given BinaryExpr is untyped, returns it.
func CreateUntypedExprFromUnaryExpr ¶ added in v1.1.0
CreateUntypedExprFromUnaryExpr creates untyped operator-func(translatedassert.UnaryOp*()) from UnaryExpr if given UnaryExpr is untyped, returns it.
func DropGopwtEmpower ¶
DropGopwtEmpower drops `gopwt.Empower()` and drops `import "github.com/ToQoz/gopwt"`.
func ExtractPrintExprs ¶
func FindImportPathByPath ¶
func FindPathByImportPath ¶
func GetAssertImport ¶
func GetAssertImport(a *ast.File) *ast.ImportSpec
GetAssertImport returns *ast.ImportSpec of "github.com/ToQoz/gopwt/assert" if it is not found, this returns nil
func IsAssert ¶
IsAssert returns ok if given CallExpr is github.com/ToQoz/gopwt/assert.OK or Require
func IsBuildableFileName ¶
func IsBuildableFileSet ¶
func IsBuiltinFunc ¶
func IsEqualExpr ¶
func IsGoFileName ¶
func IsRawStringLit ¶
func IsReflectDeepEqual ¶
func IsTestGoFile ¶
func IsTestGoFileName ¶
func IsTestdata ¶ added in v1.3.0
func NewPrintExpr ¶
func NormalizeFile ¶
NormalizeFile normalize file. e.g. multi-line CompositeLit -> single-line in gopwt/assert.{OK, Require}
func ReplaceAllRawStringLitByStringLit ¶
ReplaceAllRawStringLitByStringLit replaces all raw string literals in root by string literals.
func ReplaceBinaryExpr ¶
ReplaceBinaryExpr replace oldExpr by newExpr in parent
func ReplaceUnaryExpr ¶ added in v1.1.0
ReplaceUnaryExpr replace oldExpr by newExpr in parent
func ResultPosOf ¶
ResultPosOf returns result position of given expr. "a" -> 0 "obj.Fn" -> 3 "1 + 2" -> 2 "(1)" -> 1
func RewriteAssert ¶
RewriteAssert rewrites assert to translatedassert
func RewriteFile ¶
func RewriteFile(pkgCtx *PackageContext, file *GoFile, ctx *Context, typesInfo *types.Info, out io.Writer) error
RewriteFile rewrites assert to translatedassert in the given file
func SprintCode ¶
Types ¶
type File ¶
func ListTestdataFiles ¶
ListTestdata lists all <pkgDir>/testdata/**/* files
func ListVendorFiles ¶
ListVendor lists all vendored files
type PackageContext ¶
type PackageContext struct { Filepath string Importpath string SrcDir string Vendor string HasVendor bool TypeInfo *types.Info OriginalFset *token.FileSet NormalizedFset *token.FileSet GoFiles []*GoFile Wg *sync.WaitGroup Error error }
func NewPackageContext ¶
func NewPackageContext(fpath, importpath, srcDir string) *PackageContext
func (*PackageContext) CopyPackage ¶
func (pkgCtx *PackageContext) CopyPackage()
CopyPackage vendoring and ./testdata/... files
func (*PackageContext) ReadPackage ¶
func (pkgCtx *PackageContext) ReadPackage()
ReadPackage reads gofiles in package
func (*PackageContext) RewritePackage ¶
func (pkgCtx *PackageContext) RewritePackage()
Rewrite rewrites assert to translatedassert in the given package
func (*PackageContext) Translate ¶
func (pkgCtx *PackageContext) Translate() error
func (*PackageContext) TypecheckPackage ¶
func (pkgCtx *PackageContext) TypecheckPackage()