forked from avito-tech/go-mutesting
-
Notifications
You must be signed in to change notification settings - Fork 1
/
assign_invert.go
46 lines (39 loc) · 928 Bytes
/
assign_invert.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
package arithmetic
import (
"go/ast"
"go/token"
"go/types"
"github.com/JekaMas/go-mutesting/mutator"
)
func init() {
mutator.Register("arithmetic/assign_invert", MutatorArithmeticAssignInvert)
}
var assignInvertMutations = map[token.Token]token.Token{
token.ADD_ASSIGN: token.SUB_ASSIGN,
token.SUB_ASSIGN: token.ADD_ASSIGN,
token.MUL_ASSIGN: token.QUO_ASSIGN,
token.QUO_ASSIGN: token.MUL_ASSIGN,
token.REM_ASSIGN: token.MUL_ASSIGN,
}
// MutatorArithmeticAssignInvert implements a mutator to invert change assign statements.
func MutatorArithmeticAssignInvert(_ *types.Package, _ *types.Info, node ast.Node) []mutator.Mutation {
n, ok := node.(*ast.AssignStmt)
if !ok {
return nil
}
original := n.Tok
mutated, ok := assignInvertMutations[n.Tok]
if !ok {
return nil
}
return []mutator.Mutation{
{
Change: func() {
n.Tok = mutated
},
Reset: func() {
n.Tok = original
},
},
}
}