Prettify case mutator
This commit is contained in:
parent
71b5365a81
commit
77fe909b6e
1 changed files with 16 additions and 17 deletions
|
@ -19,39 +19,38 @@ module Mutant
|
||||||
#
|
#
|
||||||
def dispatch
|
def dispatch
|
||||||
emit_condition_mutations
|
emit_condition_mutations
|
||||||
emit_branch_mutations
|
emit_when_mutations
|
||||||
|
emit_else_mutations
|
||||||
end
|
end
|
||||||
|
|
||||||
# Emit presence mutations
|
# Emit when mutations
|
||||||
#
|
#
|
||||||
# @return [undefined]
|
# @return [undefined]
|
||||||
#
|
#
|
||||||
# @api private
|
# @api private
|
||||||
#
|
#
|
||||||
def emit_branch_mutations
|
def emit_when_mutations
|
||||||
remaining_children_with_index.each do |child, index|
|
indices = children.each_index.drop(1).take(children.length-2)
|
||||||
next unless child
|
one = indices.length > 1
|
||||||
mutate_index(index)
|
indices.each do |index|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Perform mutations of child index
|
|
||||||
#
|
|
||||||
# @param [Fixnum] index
|
|
||||||
#
|
|
||||||
# @return [undefined]
|
|
||||||
#
|
|
||||||
# @api private
|
|
||||||
#
|
|
||||||
def mutate_index(index)
|
|
||||||
mutate_child(index)
|
mutate_child(index)
|
||||||
dup_children = children.dup
|
delete_child(index) if one
|
||||||
dup_children.delete_at(index)
|
end
|
||||||
return if dup_children.none? { |child| child.type == :when }
|
end
|
||||||
if dup_children.last.type == :when
|
|
||||||
dup_children << nil
|
# Emit else mutations
|
||||||
|
#
|
||||||
|
# @return [undefined]
|
||||||
|
#
|
||||||
|
# @api private
|
||||||
|
#
|
||||||
|
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)
|
||||||
end
|
end
|
||||||
emit_self(*dup_children)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end # Case
|
end # Case
|
||||||
|
|
Loading…
Add table
Reference in a new issue