internal

package
v2.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2018 License: BSD-2-Clause Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const SeekStart = os.SEEK_SET

Variables

View Source
var (
	Testdata   = "testdata"
	TermWidth  = 0
	WorkingDir = ""
	Verbose    = false
)

Functions

func Assert

func Assert(condition bool, msg string)

func CopyFile

func CopyFile(path string, out io.Writer) error

func CreateBoolIdent

func CreateBoolIdent(v bool) *ast.Ident

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 CreatePosValuePairExpr(ctx *Context, ps []printExpr) []ast.Expr

func CreateRawStringLit

func CreateRawStringLit(s string) ast.Expr

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 CreateReflectBoolExpr

func CreateReflectBoolExpr(ctx *Context, rv ast.Expr) *ast.CallExpr

func CreateReflectInterfaceExpr

func CreateReflectInterfaceExpr(ctx *Context, rv ast.Expr) *ast.CallExpr

func CreateReflectTypeExprFromTypeExpr

func CreateReflectTypeExprFromTypeExpr(ctx *Context, t ast.Expr) ast.Expr

CreateReflectTypeExprFromTypeExpr create ast of reflect.Type from ast of type.

func CreateReflectTypeOfExpr

func CreateReflectTypeOfExpr(ctx *Context, v ast.Expr) *ast.CallExpr

func CreateReflectValueOfExpr

func CreateReflectValueOfExpr(ctx *Context, v ast.Expr) *ast.CallExpr

func CreateUntypedCallExprFromBuiltinCallExpr

func CreateUntypedCallExprFromBuiltinCallExpr(ctx *Context, n *ast.CallExpr) *ast.CallExpr

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

func CreateUntypedExprFromUnaryExpr(ctx *Context, n *ast.UnaryExpr) ast.Expr

CreateUntypedExprFromUnaryExpr creates untyped operator-func(translatedassert.UnaryOp*()) from UnaryExpr if given UnaryExpr is untyped, returns it.

func DeterminantExprOfIsTypeConversion

func DeterminantExprOfIsTypeConversion(e ast.Expr) ast.Expr

func DropGopwtEmpower

func DropGopwtEmpower(a *ast.File) (dropped bool)

DropGopwtEmpower drops `gopwt.Empower()` and drops `import "github.com/ToQoz/gopwt"`.

func ExtractPrintExprs

func ExtractPrintExprs(ctx *Context, typesInfo *types.Info, filename string, line int, offset token.Pos, parent ast.Expr, n ast.Expr) []printExpr

func FindDeps

func FindDeps(pkg *build.Package) ([]string, error)

func FindImportPathByPath

func FindImportPathByPath(path string) (string, error)

func FindPathByImportPath

func FindPathByImportPath(importPath string) (string, error)

func FindVendor

func FindVendor(fpath string, nest int) (string, bool)

func FprintCode

func FprintCode(out io.Writer, n ast.Node) error

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 HandleGlobalOrLocalImportPath

func HandleGlobalOrLocalImportPath(globalOrLocalImportPath string) (importpath, fpath string, err error)

func InspectAssert

func InspectAssert(ctx *Context, root ast.Node, fn func(*ast.CallExpr))

func IsAssert

func IsAssert(x *ast.Ident, c *ast.CallExpr) bool

IsAssert returns ok if given CallExpr is github.com/ToQoz/gopwt/assert.OK or Require

func IsBuildableFileName

func IsBuildableFileName(name string) bool

func IsBuildableFileSet

func IsBuildableFileSet(s *token.FileSet) bool

func IsBuiltinFunc

func IsBuiltinFunc(n *ast.CallExpr) bool

func IsEqualExpr

func IsEqualExpr(expr ast.Expr) bool

func IsGoFile

func IsGoFile(f os.FileInfo) bool

func IsGoFileName

func IsGoFileName(name string) bool

func IsMapType

func IsMapType(n ast.Node) bool

func IsRawStringLit

func IsRawStringLit(n *ast.BasicLit) bool

func IsReflectDeepEqual

func IsReflectDeepEqual(expr ast.Expr) bool

func IsTestGoFile

func IsTestGoFile(f os.FileInfo) bool

func IsTestGoFileName

func IsTestGoFileName(name string) bool

func IsTestdata added in v1.3.0

func IsTestdata(fpath string) bool

func IsTypeConversion

func IsTypeConversion(info *types.Info, e *ast.CallExpr) bool

func Must

func Must(err error)

func MustParse

func MustParse(file *ast.File, err error) *ast.File

func NewPrintExpr

func NewPrintExpr(pos token.Pos, newExpr ast.Expr, originalExpr string) printExpr

func NormalizeFile

func NormalizeFile(file *ast.File, in *os.File, out io.Writer) error

NormalizeFile normalize file. e.g. multi-line CompositeLit -> single-line in gopwt/assert.{OK, Require}

func ReplaceAllRawStringLitByStringLit

func ReplaceAllRawStringLitByStringLit(root ast.Node)

ReplaceAllRawStringLitByStringLit replaces all raw string literals in root by string literals.

func ReplaceBinaryExpr

func ReplaceBinaryExpr(parent ast.Node, oldExpr *ast.BinaryExpr, newExpr ast.Expr)

ReplaceBinaryExpr replace oldExpr by newExpr in parent

func ReplaceUnaryExpr added in v1.1.0

func ReplaceUnaryExpr(parent ast.Node, oldExpr *ast.UnaryExpr, newExpr ast.Expr)

ReplaceUnaryExpr replace oldExpr by newExpr in parent

func ResultPosOf

func ResultPosOf(n ast.Expr) token.Pos

ResultPosOf returns result position of given expr. "a" -> 0 "obj.Fn" -> 3 "1 + 2" -> 2 "(1)" -> 1

func RetrieveImportpathFromVendorDir

func RetrieveImportpathFromVendorDir(path string) (string, bool)

func RewriteAssert

func RewriteAssert(ctx *Context, typesInfo *types.Info, position token.Position, n *ast.CallExpr)

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

func SprintCode(n ast.Node) string

func Translate

func Translate(gopath string, importpath, fpath string) error

Types

type Context

type Context struct {
	TranslatedassertImport *ast.Ident
	AssertImport           *ast.Ident
}

type File

type File struct {
	SrcPath string
	Path    string
	Mode    os.FileMode
}

func ListTestdataFiles

func ListTestdataFiles(pkgDir string, importPath string, tempGoSrcDir string) []File

ListTestdata lists all <pkgDir>/testdata/**/* files

func ListVendorFiles

func ListVendorFiles(vendor, pkgDir, importPath, tempGoSrcDir string) []File

ListVendor lists all vendored files

type GoFile

type GoFile struct {
	Path       string
	Original   *ast.File
	Normalized *ast.File
	Mode       os.FileMode
	Data       io.Reader
}

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()

Jump to

Keyboard shortcuts

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