2013-07-28 16:03:06 -07:00
|
|
|
# encoding: utf-8
|
|
|
|
|
2013-06-14 18:22:34 +02:00
|
|
|
module Mutant
|
|
|
|
class Mutator
|
|
|
|
class Node
|
|
|
|
|
|
|
|
# Mutator for case nodes
|
|
|
|
class Case < self
|
|
|
|
|
|
|
|
handle(:case)
|
|
|
|
|
2013-06-21 15:30:06 +02:00
|
|
|
children :condition
|
2013-06-14 18:22:34 +02:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# Emit mutations
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def dispatch
|
2014-04-06 21:59:12 +00:00
|
|
|
emit_condition_mutations if condition
|
2013-06-23 21:56:46 +02:00
|
|
|
emit_when_mutations
|
|
|
|
emit_else_mutations
|
2013-09-07 23:10:25 -07:00
|
|
|
emit_nil
|
2013-06-14 18:22:34 +02:00
|
|
|
end
|
|
|
|
|
2013-06-23 21:56:46 +02:00
|
|
|
# Emit when mutations
|
2013-06-14 18:22:34 +02:00
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2013-06-23 21:56:46 +02:00
|
|
|
def emit_when_mutations
|
2013-07-27 21:14:41 +02:00
|
|
|
indices = children.each_index.drop(1).take(children.length - 2)
|
2013-06-23 22:41:55 +02:00
|
|
|
one = indices.one?
|
2013-06-23 21:56:46 +02:00
|
|
|
indices.each do |index|
|
|
|
|
mutate_child(index)
|
2013-06-23 21:59:09 +02:00
|
|
|
delete_child(index) unless one
|
2013-06-14 18:22:34 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-06-23 21:56:46 +02:00
|
|
|
# Emit else mutations
|
2013-06-15 17:16:34 +02:00
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2013-06-23 21:56:46 +02: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 17:16:34 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-06-14 18:22:34 +02:00
|
|
|
end # Case
|
|
|
|
end # Node
|
|
|
|
end # Mutator
|
|
|
|
end # Mutant
|