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 15:06:24 +02:00
children :condition, :if_branch, :else_branch
2013-06-10 10:15:59 +02:00
private
2013-06-10 10:15:59 +02:00
# Emit mutations
#
# @return [undefined]
#
# @api private
#
def dispatch
2013-06-10 10:15:59 +02:00
mutate_condition
mutate_if_branch
mutate_else_branch
emit_nil
end
2013-06-10 10:15:59 +02:00
# Emit conditon mutations
#
# @return [undefined]
#
# @api private
#
2013-06-10 10:15:59 +02:00
def mutate_condition
2013-06-21 15:06:24 +02:00
emit_condition_mutations
emit_self(n_not(condition), if_branch, else_branch) unless condition.type == :match_current_line
2013-07-23 22:58:20 -07:00
emit_self(N_TRUE, if_branch, else_branch)
emit_self(N_FALSE, if_branch, else_branch)
end
2013-06-10 10:15:59 +02:00
# Emit if branch mutations
#
# @return [undefined]
#
# @api private
#
2013-06-10 10:15:59 +02:00
def mutate_if_branch
2013-06-12 19:04:40 +02:00
emit_self(condition, else_branch, nil) if else_branch
if if_branch
2013-06-21 15:06:24 +02:00
emit_if_branch_mutations
2013-07-23 22:58:39 -07:00
emit_self(condition, if_branch, nil)
2013-06-12 19:04:40 +02:00
end
end
2013-06-10 10:15:59 +02:00
# Emit else branch mutations
#
# @return [undefined]
#
# @api private
#
2013-06-10 10:15:59 +02:00
def mutate_else_branch
2013-06-12 19:04:40 +02:00
if else_branch
2013-06-21 15:06:24 +02:00
emit_else_branch_mutations
2013-06-12 19:04:40 +02:00
emit_self(condition, nil, else_branch)
end
end
end # If
end # Node
end # Mutator
end # Mutant