2012-12-06 15:30:28 -05:00
|
|
|
module Mutant
|
|
|
|
class Mutator
|
|
|
|
class Node
|
|
|
|
|
|
|
|
# Mutator for Rubinius::AST::ReceiverCase nodes
|
|
|
|
class ReceiverCase < self
|
|
|
|
|
|
|
|
handle(Rubinius::AST::ReceiverCase)
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# Emit mutations
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def dispatch
|
2012-12-06 16:30:57 -05:00
|
|
|
emit_attribute_mutations(:receiver)
|
2012-12-06 15:30:28 -05:00
|
|
|
emit_when_branch_presence_mutations
|
|
|
|
emit_else_branch_presence_mutation
|
|
|
|
emit_when_branch_mutations
|
|
|
|
end
|
|
|
|
|
|
|
|
# Emit else branch presence mutation
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def emit_else_branch_presence_mutation
|
|
|
|
emit_self(receiver, when_branches, nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Emit when branch body mutations
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def emit_when_branch_mutations
|
2013-01-04 16:16:03 -05:00
|
|
|
when_branches.each_with_index do |branch, index|
|
2012-12-06 15:30:28 -05:00
|
|
|
Mutator.each(branch) do |mutant|
|
|
|
|
branches = dup_when_branches
|
|
|
|
branches[index]=mutant
|
|
|
|
emit_self(receiver, branches, else_branch)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Emit when branch presence mutations
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def emit_when_branch_presence_mutations
|
|
|
|
return if one?
|
|
|
|
when_branches.each_index do |index|
|
|
|
|
dup_branches = dup_when_branches
|
|
|
|
dup_branches.delete_at(index)
|
|
|
|
emit_self(receiver, dup_branches, else_branch)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Check for case there is only one when branch
|
|
|
|
#
|
|
|
|
# @return [true]
|
|
|
|
# returns true when there is only one when branch
|
|
|
|
#
|
|
|
|
# @return [false]
|
|
|
|
# returns false otherwise
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def one?
|
|
|
|
when_branches.one?
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return duplicate of when branches
|
|
|
|
#
|
|
|
|
# @return [Array]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def dup_when_branches
|
|
|
|
when_branches.dup
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return when branches
|
|
|
|
#
|
|
|
|
# @return [Array]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def when_branches
|
|
|
|
node.whens
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return receiver
|
|
|
|
#
|
|
|
|
# @return [Rubinius::AST::Node]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def receiver
|
|
|
|
node.receiver
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return else branch
|
|
|
|
#
|
|
|
|
# @return [Rubinius::AST::Node]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def else_branch
|
|
|
|
node.else
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|