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-14 12:22:34 -04:00
|
|
|
emit_branch_mutations
|
|
|
|
end
|
|
|
|
|
|
|
|
# Emit presence mutations
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def emit_branch_mutations
|
2013-06-21 09:53:33 -04:00
|
|
|
remaining_children_with_index.each do |child, index|
|
2013-06-14 12:22:34 -04:00
|
|
|
next unless child
|
2013-06-15 11:16:34 -04:00
|
|
|
mutate_index(index)
|
2013-06-14 12:22:34 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-06-15 11:16:34 -04:00
|
|
|
# Perform mutations of child index
|
|
|
|
#
|
|
|
|
# @param [Fixnum] index
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def mutate_index(index)
|
|
|
|
mutate_child(index)
|
|
|
|
dup_children = children.dup
|
|
|
|
dup_children.delete_at(index)
|
|
|
|
if dup_children.last.type == :when
|
|
|
|
dup_children << nil
|
|
|
|
end
|
|
|
|
emit_self(*dup_children)
|
|
|
|
end
|
|
|
|
|
2013-06-14 12:22:34 -04:00
|
|
|
end # Case
|
|
|
|
end # Node
|
|
|
|
end # Mutator
|
|
|
|
end # Mutant
|