2012-12-06 15:30:28 -05:00
|
|
|
module Mutant
|
|
|
|
class Mutator
|
|
|
|
class Node
|
2013-06-04 04:25:13 -04:00
|
|
|
# Mutator for if nodes
|
2013-01-04 16:16:03 -05:00
|
|
|
class If < self
|
2012-12-06 15:30:28 -05:00
|
|
|
|
2013-06-04 04:25:13 -04:00
|
|
|
handle(:if)
|
2012-12-06 15:30:28 -05:00
|
|
|
|
2013-06-21 09:06:24 -04:00
|
|
|
children :condition, :if_branch, :else_branch
|
2013-06-10 04:15:59 -04:00
|
|
|
|
2012-12-06 15:30:28 -05:00
|
|
|
private
|
|
|
|
|
2013-06-10 04:15:59 -04:00
|
|
|
# Emit mutations
|
2012-12-06 15:30:28 -05:00
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def dispatch
|
2013-06-10 04:15:59 -04:00
|
|
|
mutate_condition
|
|
|
|
mutate_if_branch
|
|
|
|
mutate_else_branch
|
2012-12-06 15:30:28 -05:00
|
|
|
end
|
|
|
|
|
2013-06-10 04:15:59 -04:00
|
|
|
# Emit conditon mutations
|
2012-12-06 15:30:28 -05:00
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2013-06-10 04:15:59 -04:00
|
|
|
def mutate_condition
|
2013-06-21 09:06:24 -04:00
|
|
|
emit_condition_mutations
|
2013-06-10 04:15:59 -04:00
|
|
|
emit_self(s(:send, condition, :!), if_branch, else_branch)
|
|
|
|
emit_self(s(:true), if_branch, else_branch)
|
|
|
|
emit_self(s(:false), if_branch, else_branch)
|
2012-12-06 15:30:28 -05:00
|
|
|
end
|
|
|
|
|
2013-06-10 04:15:59 -04:00
|
|
|
# Emit if branch mutations
|
2013-03-24 02:12:36 -04:00
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2013-06-10 04:15:59 -04:00
|
|
|
def mutate_if_branch
|
2013-06-12 13:04:40 -04:00
|
|
|
emit_self(condition, else_branch, nil) if else_branch
|
|
|
|
if if_branch
|
2013-06-21 09:06:24 -04:00
|
|
|
emit_if_branch_mutations
|
2013-06-12 13:04:40 -04:00
|
|
|
emit_self(condition, if_branch, nil)
|
|
|
|
end
|
2013-03-24 02:12:36 -04:00
|
|
|
end
|
|
|
|
|
2013-06-10 04:15:59 -04:00
|
|
|
# Emit else branch mutations
|
2013-03-24 02:12:36 -04:00
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2013-06-10 04:15:59 -04:00
|
|
|
def mutate_else_branch
|
2013-06-12 13:04:40 -04:00
|
|
|
if else_branch
|
2013-06-21 09:06:24 -04:00
|
|
|
emit_else_branch_mutations
|
2013-06-12 13:04:40 -04:00
|
|
|
emit_self(condition, nil, else_branch)
|
|
|
|
end
|
2013-03-24 02:12:36 -04:00
|
|
|
end
|
|
|
|
|
2013-06-04 04:25:13 -04:00
|
|
|
end # If
|
|
|
|
end # Node
|
|
|
|
end # Mutator
|
|
|
|
end # Mutant
|