forked from zimmski/go-mutesting
/
remove.go
55 lines (47 loc) · 828 Bytes
/
remove.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package expression
import (
"go/ast"
"go/token"
"go/types"
"github.com/fbustamant3/go-mutesting/mutator"
)
func init() {
mutator.Register("expression/remove", MutatorRemoveTerm)
}
// MutatorRemoveTerm implements a mutator to remove expression terms.
func MutatorRemoveTerm(pkg *types.Package, info *types.Info, node ast.Node) []mutator.Mutation {
n, ok := node.(*ast.BinaryExpr)
if !ok {
return nil
}
if n.Op != token.LAND && n.Op != token.LOR {
return nil
}
var r *ast.Ident
switch n.Op {
case token.LAND:
r = ast.NewIdent("true")
case token.LOR:
r = ast.NewIdent("false")
}
x := n.X
y := n.Y
return []mutator.Mutation{
{
Change: func() {
n.X = r
},
Reset: func() {
n.X = x
},
},
{
Change: func() {
n.Y = r
},
Reset: func() {
n.Y = y
},
},
}
}