github.com/mshitrit/go-mutesting@v0.0.0-20210528084812-ff81dcaedfea/mutator/branch/mutateif.go (about) 1 package branch 2 3 import ( 4 "go/ast" 5 "go/types" 6 7 "github.com/zimmski/go-mutesting/astutil" 8 "github.com/zimmski/go-mutesting/mutator" 9 ) 10 11 func init() { 12 mutator.Register("branch/if", MutatorIf) 13 } 14 15 // MutatorIf implements a mutator for if and else if branches. 16 func MutatorIf(pkg *types.Package, info *types.Info, node ast.Node) []mutator.Mutation { 17 n, ok := node.(*ast.IfStmt) 18 if !ok { 19 return nil 20 } 21 22 old := n.Body.List 23 24 return []mutator.Mutation{ 25 { 26 Change: func() { 27 n.Body.List = []ast.Stmt{ 28 astutil.CreateNoopOfStatement(pkg, info, n.Body), 29 } 30 }, 31 Reset: func() { 32 n.Body.List = old 33 }, 34 }, 35 } 36 }