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
|
2014-06-05 12:37:31 -04:00
|
|
|
emit_singletons
|
2014-04-06 17:59:12 -04:00
|
|
|
emit_condition_mutations if condition
|
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
|
2013-07-27 15:14:41 -04:00
|
|
|
indices = children.each_index.drop(1).take(children.length - 2)
|
2013-06-23 16:41:55 -04:00
|
|
|
one = indices.one?
|
2013-06-23 15:56:46 -04:00
|
|
|
indices.each do |index|
|
|
|
|
mutate_child(index)
|
2013-06-23 15:59:09 -04:00
|
|
|
delete_child(index) unless 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
|
2014-06-08 09:01:26 -04:00
|
|
|
return unless else_branch
|
|
|
|
mutate_child(else_index)
|
|
|
|
emit_child_update(else_index, nil)
|
2013-06-15 11:16:34 -04:00
|
|
|
end
|
|
|
|
|
2013-06-14 12:22:34 -04:00
|
|
|
end # Case
|
|
|
|
end # Node
|
|
|
|
end # Mutator
|
|
|
|
end # Mutant
|