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

60 lines
1.2 KiB
Ruby
Raw Normal View History

2013-06-14 12:22:34 -04:00
module Mutant
class Mutator
class Node
# Mutator for case nodes
class Case < self
handle(:case)
2013-06-21 09:30:06 -04:00
children :condition
2013-06-14 12:22:34 -04:00
private
# Emit mutations
#
# @return [undefined]
#
# @api private
#
def dispatch
2013-06-21 09:30:06 -04:00
emit_condition_mutations
2013-06-23 15:56:46 -04:00
emit_when_mutations
emit_else_mutations
2013-06-14 12:22:34 -04:00
end
2013-06-23 15:56:46 -04:00
# Emit when mutations
2013-06-14 12:22:34 -04:00
#
# @return [undefined]
#
# @api private
#
2013-06-23 15:56:46 -04:00
def emit_when_mutations
indices = children.each_index.drop(1).take(children.length-2)
one = indices.length > 1
indices.each do |index|
mutate_child(index)
delete_child(index) if one
2013-06-14 12:22:34 -04:00
end
end
2013-06-23 15:56:46 -04:00
# Emit else mutations
2013-06-15 11:16:34 -04:00
#
# @return [undefined]
#
# @api private
#
2013-06-23 15:56:46 -04:00
def emit_else_mutations
else_branch = children.last
else_index = children.length - 1
if else_branch
mutate_child(else_index)
emit_child_update(else_index, nil)
2013-06-15 11:16:34 -04:00
end
end
2013-06-14 12:22:34 -04:00
end # Case
end # Node
end # Mutator
end # Mutant