free_mutant/lib/mutant/mutator/node/if.rb

72 lines
1.5 KiB
Ruby
Raw Normal View History

# encoding: utf-8
module Mutant
class Mutator
class Node
# Mutator for if nodes
class If < self
handle(:if)
2013-06-21 09:06:24 -04:00
children :condition, :if_branch, :else_branch
2013-06-10 04:15:59 -04:00
private
2013-06-10 04:15:59 -04:00
# Emit mutations
#
# @return [undefined]
#
# @api private
#
def dispatch
2013-06-10 04:15:59 -04:00
mutate_condition
mutate_if_branch
mutate_else_branch
emit_nil
end
2013-06-10 04:15:59 -04:00
# Emit conditon mutations
#
# @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
emit_self(n_not(condition), if_branch, else_branch)
2013-07-24 01:58:20 -04:00
emit_self(N_TRUE, if_branch, else_branch)
emit_self(N_FALSE, if_branch, else_branch)
end
2013-06-10 04:15:59 -04:00
# Emit if branch mutations
#
# @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-07-24 01:58:39 -04:00
emit_self(condition, if_branch, nil)
2013-06-12 13:04:40 -04:00
end
end
2013-06-10 04:15:59 -04:00
# Emit else branch mutations
#
# @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
end
end # If
end # Node
end # Mutator
end # Mutant